mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 03:12:25 -05:00 
			
		
		
		
	Timeline manager (#40)
* start messing about with timeline manager * i have no idea what i'm doing * i continue to not know what i'm doing * it's coming along * bit more progress * update timeline with new posts as they come in * lint and fmt * Select accounts where empty string * restructure a bunch, get unfaves working * moving stuff around * federate status deletes properly * mention regex better but not 100% there * fix regex * some more hacking away at the timeline code phew * fix up some little things * i can't even * more timeline stuff * move to ulid * fiddley * some lil fixes for kibou compatibility * timelines working pretty alright! * tidy + lint
This commit is contained in:
		
					parent
					
						
							
								6ac6f8d614
							
						
					
				
			
			
				commit
				
					
						b4288f3c47
					
				
			
		
					 96 changed files with 3458 additions and 1679 deletions
				
			
		|  | @ -19,531 +19,43 @@ | |||
| package processing | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"time" | ||||
| 
 | ||||
| 	"github.com/google/uuid" | ||||
| 	apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/db" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/gtserror" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/oauth" | ||||
| 	"github.com/superseriousbusiness/gotosocial/internal/util" | ||||
| ) | ||||
| 
 | ||||
| func (p *processor) StatusCreate(auth *oauth.Auth, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, error) { | ||||
| 	uris := util.GenerateURIsForAccount(auth.Account.Username, p.config.Protocol, p.config.Host) | ||||
| 	thisStatusID := uuid.NewString() | ||||
| 	thisStatusURI := fmt.Sprintf("%s/%s", uris.StatusesURI, thisStatusID) | ||||
| 	thisStatusURL := fmt.Sprintf("%s/%s", uris.StatusesURL, thisStatusID) | ||||
| 	newStatus := >smodel.Status{ | ||||
| 		ID:                       thisStatusID, | ||||
| 		URI:                      thisStatusURI, | ||||
| 		URL:                      thisStatusURL, | ||||
| 		Content:                  util.HTMLFormat(form.Status), | ||||
| 		CreatedAt:                time.Now(), | ||||
| 		UpdatedAt:                time.Now(), | ||||
| 		Local:                    true, | ||||
| 		AccountID:                auth.Account.ID, | ||||
| 		ContentWarning:           form.SpoilerText, | ||||
| 		ActivityStreamsType:      gtsmodel.ActivityStreamsNote, | ||||
| 		Sensitive:                form.Sensitive, | ||||
| 		Language:                 form.Language, | ||||
| 		CreatedWithApplicationID: auth.Application.ID, | ||||
| 		Text:                     form.Status, | ||||
| 	} | ||||
| 
 | ||||
| 	// check if replyToID is ok | ||||
| 	if err := p.processReplyToID(form, auth.Account.ID, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	// check if mediaIDs are ok | ||||
| 	if err := p.processMediaIDs(form, auth.Account.ID, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	// check if visibility settings are ok | ||||
| 	if err := p.processVisibility(form, auth.Account.Privacy, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	// handle language settings | ||||
| 	if err := p.processLanguage(form, auth.Account.Language, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	// handle mentions | ||||
| 	if err := p.processMentions(form, auth.Account.ID, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	if err := p.processTags(form, auth.Account.ID, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	if err := p.processEmojis(form, auth.Account.ID, newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	// put the new status in the database, generating an ID for it in the process | ||||
| 	if err := p.db.Put(newStatus); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	// change the status ID of the media attachments to the new status | ||||
| 	for _, a := range newStatus.GTSMediaAttachments { | ||||
| 		a.StatusID = newStatus.ID | ||||
| 		a.UpdatedAt = time.Now() | ||||
| 		if err := p.db.UpdateByID(a.ID, a); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// put the new status in the appropriate channel for async processing | ||||
| 	p.fromClientAPI <- gtsmodel.FromClientAPI{ | ||||
| 		APObjectType:   newStatus.ActivityStreamsType, | ||||
| 		APActivityType: gtsmodel.ActivityStreamsCreate, | ||||
| 		GTSModel:       newStatus, | ||||
| 	} | ||||
| 
 | ||||
| 	// return the frontend representation of the new status to the submitter | ||||
| 	return p.tc.StatusToMasto(newStatus, auth.Account, auth.Account, nil, newStatus.GTSReplyToAccount, nil) | ||||
| func (p *processor) StatusCreate(authed *oauth.Auth, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, error) { | ||||
| 	return p.statusProcessor.Create(authed.Account, authed.Application, form) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusDelete(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, error) { | ||||
| 	l := p.log.WithField("func", "StatusDelete") | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	if targetStatus.AccountID != authed.Account.ID { | ||||
| 		return nil, errors.New("status doesn't belong to requesting account") | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	var boostOfStatus *gtsmodel.Status | ||||
| 	if targetStatus.BoostOfID != "" { | ||||
| 		boostOfStatus = >smodel.Status{} | ||||
| 		if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { | ||||
| 			return nil, fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	mastoStatus, err := p.tc.StatusToMasto(targetStatus, authed.Account, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	if err := p.db.DeleteByID(targetStatus.ID, targetStatus); err != nil { | ||||
| 		return nil, fmt.Errorf("error deleting status from the database: %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoStatus, nil | ||||
| 	return p.statusProcessor.Delete(authed.Account, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusFave(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, error) { | ||||
| 	l := p.log.WithField("func", "StatusFave") | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Tracef("going to search for target account %s", targetStatus.AccountID) | ||||
| 	targetAccount := >smodel.Account{} | ||||
| 	if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	var boostOfStatus *gtsmodel.Status | ||||
| 	if targetStatus.BoostOfID != "" { | ||||
| 		boostOfStatus = >smodel.Status{} | ||||
| 		if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { | ||||
| 			return nil, fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to see if status is visible") | ||||
| 	visible, err := p.db.StatusVisible(targetStatus, targetAccount, authed.Account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	if !visible { | ||||
| 		return nil, errors.New("status is not visible") | ||||
| 	} | ||||
| 
 | ||||
| 	// is the status faveable? | ||||
| 	if targetStatus.VisibilityAdvanced != nil { | ||||
| 		if !targetStatus.VisibilityAdvanced.Likeable { | ||||
| 			return nil, errors.New("status is not faveable") | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// first check if the status is already faved, if so we don't need to do anything | ||||
| 	newFave := true | ||||
| 	gtsFave := >smodel.Status{} | ||||
| 	if err := p.db.GetWhere([]db.Where{{Key: "status_id", Value: targetStatus.ID}, {Key: "account_id", Value: authed.Account.ID}}, gtsFave); err == nil { | ||||
| 		// we already have a fave for this status | ||||
| 		newFave = false | ||||
| 	} | ||||
| 
 | ||||
| 	if newFave { | ||||
| 		thisFaveID := uuid.NewString() | ||||
| 
 | ||||
| 		// we need to create a new fave in the database | ||||
| 		gtsFave := >smodel.StatusFave{ | ||||
| 			ID:               thisFaveID, | ||||
| 			AccountID:        authed.Account.ID, | ||||
| 			TargetAccountID:  targetAccount.ID, | ||||
| 			StatusID:         targetStatus.ID, | ||||
| 			URI:              util.GenerateURIForLike(authed.Account.Username, p.config.Protocol, p.config.Host, thisFaveID), | ||||
| 			GTSStatus:        targetStatus, | ||||
| 			GTSTargetAccount: targetAccount, | ||||
| 			GTSFavingAccount: authed.Account, | ||||
| 		} | ||||
| 
 | ||||
| 		if err := p.db.Put(gtsFave); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 
 | ||||
| 		// send the new fave through the processor channel for federation etc | ||||
| 		p.fromClientAPI <- gtsmodel.FromClientAPI{ | ||||
| 			APObjectType:   gtsmodel.ActivityStreamsLike, | ||||
| 			APActivityType: gtsmodel.ActivityStreamsCreate, | ||||
| 			GTSModel:       gtsFave, | ||||
| 			OriginAccount:  authed.Account, | ||||
| 			TargetAccount:  targetAccount, | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// return the mastodon representation of the target status | ||||
| 	mastoStatus, err := p.tc.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoStatus, nil | ||||
| 	return p.statusProcessor.Fave(authed.Account, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusBoost(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, ErrorWithCode) { | ||||
| 	l := p.log.WithField("func", "StatusBoost") | ||||
| 
 | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Tracef("going to search for target account %s", targetStatus.AccountID) | ||||
| 	targetAccount := >smodel.Account{} | ||||
| 	if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to see if status is visible") | ||||
| 	visible, err := p.db.StatusVisible(targetStatus, targetAccount, authed.Account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	if !visible { | ||||
| 		return nil, NewErrorNotFound(errors.New("status is not visible")) | ||||
| 	} | ||||
| 
 | ||||
| 	if targetStatus.VisibilityAdvanced != nil { | ||||
| 		if !targetStatus.VisibilityAdvanced.Boostable { | ||||
| 			return nil, NewErrorForbidden(errors.New("status is not boostable")) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// it's visible! it's boostable! so let's boost the FUCK out of it | ||||
| 	boostWrapperStatus, err := p.tc.StatusToBoost(targetStatus, authed.Account) | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorInternalError(err) | ||||
| 	} | ||||
| 
 | ||||
| 	boostWrapperStatus.CreatedWithApplicationID = authed.Application.ID | ||||
| 	boostWrapperStatus.GTSBoostedAccount = targetAccount | ||||
| 
 | ||||
| 	// put the boost in the database | ||||
| 	if err := p.db.Put(boostWrapperStatus); err != nil { | ||||
| 		return nil, NewErrorInternalError(err) | ||||
| 	} | ||||
| 
 | ||||
| 	// send it to the processor for async processing | ||||
| 	p.fromClientAPI <- gtsmodel.FromClientAPI{ | ||||
| 		APObjectType:   gtsmodel.ActivityStreamsAnnounce, | ||||
| 		APActivityType: gtsmodel.ActivityStreamsCreate, | ||||
| 		GTSModel:       boostWrapperStatus, | ||||
| 		OriginAccount:  authed.Account, | ||||
| 		TargetAccount:  targetAccount, | ||||
| 	} | ||||
| 
 | ||||
| 	// return the frontend representation of the new status to the submitter | ||||
| 	mastoStatus, err := p.tc.StatusToMasto(boostWrapperStatus, authed.Account, authed.Account, targetAccount, nil, targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorInternalError(fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoStatus, nil | ||||
| func (p *processor) StatusBoost(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, gtserror.WithCode) { | ||||
| 	return p.statusProcessor.Boost(authed.Account, authed.Application, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusBoostedBy(authed *oauth.Auth, targetStatusID string) ([]*apimodel.Account, ErrorWithCode) { | ||||
| 	l := p.log.WithField("func", "StatusBoostedBy") | ||||
| 
 | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching status %s: %s", targetStatusID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Tracef("going to search for target account %s", targetStatus.AccountID) | ||||
| 	targetAccount := >smodel.Account{} | ||||
| 	if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching target account %s: %s", targetStatus.AccountID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error fetching related accounts for status %s: %s", targetStatusID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to see if status is visible") | ||||
| 	visible, err := p.db.StatusVisible(targetStatus, targetAccount, authed.Account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error seeing if status %s is visible: %s", targetStatus.ID, err)) | ||||
| 	} | ||||
| 
 | ||||
| 	if !visible { | ||||
| 		return nil, NewErrorNotFound(errors.New("StatusBoostedBy: status is not visible")) | ||||
| 	} | ||||
| 
 | ||||
| 	// get ALL accounts that faved a status -- doesn't take account of blocks and mutes and stuff | ||||
| 	favingAccounts, err := p.db.WhoBoostedStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error seeing who boosted status: %s", err)) | ||||
| 	} | ||||
| 
 | ||||
| 	// filter the list so the user doesn't see accounts they blocked or which blocked them | ||||
| 	filteredAccounts := []*gtsmodel.Account{} | ||||
| 	for _, acc := range favingAccounts { | ||||
| 		blocked, err := p.db.Blocked(authed.Account.ID, acc.ID) | ||||
| 		if err != nil { | ||||
| 			return nil, NewErrorNotFound(fmt.Errorf("StatusBoostedBy: error checking blocks: %s", err)) | ||||
| 		} | ||||
| 		if !blocked { | ||||
| 			filteredAccounts = append(filteredAccounts, acc) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// TODO: filter other things here? suspended? muted? silenced? | ||||
| 
 | ||||
| 	// now we can return the masto representation of those accounts | ||||
| 	mastoAccounts := []*apimodel.Account{} | ||||
| 	for _, acc := range filteredAccounts { | ||||
| 		mastoAccount, err := p.tc.AccountToMastoPublic(acc) | ||||
| 		if err != nil { | ||||
| 			return nil, NewErrorNotFound(fmt.Errorf("StatusFavedBy: error converting account to api model: %s", err)) | ||||
| 		} | ||||
| 		mastoAccounts = append(mastoAccounts, mastoAccount) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoAccounts, nil | ||||
| func (p *processor) StatusBoostedBy(authed *oauth.Auth, targetStatusID string) ([]*apimodel.Account, gtserror.WithCode) { | ||||
| 	return p.statusProcessor.BoostedBy(authed.Account, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusFavedBy(authed *oauth.Auth, targetStatusID string) ([]*apimodel.Account, error) { | ||||
| 	l := p.log.WithField("func", "StatusFavedBy") | ||||
| 
 | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Tracef("going to search for target account %s", targetStatus.AccountID) | ||||
| 	targetAccount := >smodel.Account{} | ||||
| 	if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to see if status is visible") | ||||
| 	visible, err := p.db.StatusVisible(targetStatus, targetAccount, authed.Account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	if !visible { | ||||
| 		return nil, errors.New("status is not visible") | ||||
| 	} | ||||
| 
 | ||||
| 	// get ALL accounts that faved a status -- doesn't take account of blocks and mutes and stuff | ||||
| 	favingAccounts, err := p.db.WhoFavedStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error seeing who faved status: %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	// filter the list so the user doesn't see accounts they blocked or which blocked them | ||||
| 	filteredAccounts := []*gtsmodel.Account{} | ||||
| 	for _, acc := range favingAccounts { | ||||
| 		blocked, err := p.db.Blocked(authed.Account.ID, acc.ID) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("error checking blocks: %s", err) | ||||
| 		} | ||||
| 		if !blocked { | ||||
| 			filteredAccounts = append(filteredAccounts, acc) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// TODO: filter other things here? suspended? muted? silenced? | ||||
| 
 | ||||
| 	// now we can return the masto representation of those accounts | ||||
| 	mastoAccounts := []*apimodel.Account{} | ||||
| 	for _, acc := range filteredAccounts { | ||||
| 		mastoAccount, err := p.tc.AccountToMastoPublic(acc) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("error converting account to api model: %s", err) | ||||
| 		} | ||||
| 		mastoAccounts = append(mastoAccounts, mastoAccount) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoAccounts, nil | ||||
| 	return p.statusProcessor.FavedBy(authed.Account, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusGet(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, error) { | ||||
| 	l := p.log.WithField("func", "StatusGet") | ||||
| 
 | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Tracef("going to search for target account %s", targetStatus.AccountID) | ||||
| 	targetAccount := >smodel.Account{} | ||||
| 	if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to see if status is visible") | ||||
| 	visible, err := p.db.StatusVisible(targetStatus, targetAccount, authed.Account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	if !visible { | ||||
| 		return nil, errors.New("status is not visible") | ||||
| 	} | ||||
| 
 | ||||
| 	var boostOfStatus *gtsmodel.Status | ||||
| 	if targetStatus.BoostOfID != "" { | ||||
| 		boostOfStatus = >smodel.Status{} | ||||
| 		if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { | ||||
| 			return nil, fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	mastoStatus, err := p.tc.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoStatus, nil | ||||
| 
 | ||||
| 	return p.statusProcessor.Get(authed.Account, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusUnfave(authed *oauth.Auth, targetStatusID string) (*apimodel.Status, error) { | ||||
| 	l := p.log.WithField("func", "StatusUnfave") | ||||
| 	l.Tracef("going to search for target status %s", targetStatusID) | ||||
| 	targetStatus := >smodel.Status{} | ||||
| 	if err := p.db.GetByID(targetStatusID, targetStatus); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Tracef("going to search for target account %s", targetStatus.AccountID) | ||||
| 	targetAccount := >smodel.Account{} | ||||
| 	if err := p.db.GetByID(targetStatus.AccountID, targetAccount); err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching target account %s: %s", targetStatus.AccountID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to get relevant accounts") | ||||
| 	relevantAccounts, err := p.db.PullRelevantAccountsFromStatus(targetStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error fetching related accounts for status %s: %s", targetStatusID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	l.Trace("going to see if status is visible") | ||||
| 	visible, err := p.db.StatusVisible(targetStatus, targetAccount, authed.Account, relevantAccounts) // requestingAccount might well be nil here, but StatusVisible knows how to take care of that | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	if !visible { | ||||
| 		return nil, errors.New("status is not visible") | ||||
| 	} | ||||
| 
 | ||||
| 	// is the status faveable? | ||||
| 	if targetStatus.VisibilityAdvanced != nil { | ||||
| 		if !targetStatus.VisibilityAdvanced.Likeable { | ||||
| 			return nil, errors.New("status is not faveable") | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// it's visible! it's faveable! so let's unfave the FUCK out of it | ||||
| 	_, err = p.db.UnfaveStatus(targetStatus, authed.Account.ID) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error unfaveing status: %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	var boostOfStatus *gtsmodel.Status | ||||
| 	if targetStatus.BoostOfID != "" { | ||||
| 		boostOfStatus = >smodel.Status{} | ||||
| 		if err := p.db.GetByID(targetStatus.BoostOfID, boostOfStatus); err != nil { | ||||
| 			return nil, fmt.Errorf("error fetching boosted status %s: %s", targetStatus.BoostOfID, err) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	mastoStatus, err := p.tc.StatusToMasto(targetStatus, targetAccount, authed.Account, relevantAccounts.BoostedAccount, relevantAccounts.ReplyToAccount, boostOfStatus) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("error converting status %s to frontend representation: %s", targetStatus.ID, err) | ||||
| 	} | ||||
| 
 | ||||
| 	return mastoStatus, nil | ||||
| 	return p.statusProcessor.Unfave(authed.Account, targetStatusID) | ||||
| } | ||||
| 
 | ||||
| func (p *processor) StatusGetContext(authed *oauth.Auth, targetStatusID string) (*apimodel.Context, ErrorWithCode) { | ||||
| 	return &apimodel.Context{}, nil | ||||
| func (p *processor) StatusGetContext(authed *oauth.Auth, targetStatusID string) (*apimodel.Context, gtserror.WithCode) { | ||||
| 	return p.statusProcessor.Context(authed.Account, targetStatusID) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue