diff options
author | 2024-10-04 19:22:52 +0200 | |
---|---|---|
committer | 2024-10-04 19:22:52 +0200 | |
commit | 8bd8c6fb455d90c1ad0fe84430b7ea59bd1075f3 (patch) | |
tree | 60568db8f016e82ebad8acaa6b68938b31740331 /internal/typeutils/internaltofrontend.go | |
parent | [performance] remove the pragma optimize analysis limit on connection close (... (diff) | |
download | gotosocial-8bd8c6fb455d90c1ad0fe84430b7ea59bd1075f3.tar.xz |
[bugfix] Include own account in conversation when no other accounts involved (#3387)
Diffstat (limited to 'internal/typeutils/internaltofrontend.go')
-rw-r--r-- | internal/typeutils/internaltofrontend.go | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go index 4e76837cd..76d8ec81b 100644 --- a/internal/typeutils/internaltofrontend.go +++ b/internal/typeutils/internaltofrontend.go @@ -1832,46 +1832,23 @@ func (c *Converter) NotificationToAPINotification( func (c *Converter) ConversationToAPIConversation( ctx context.Context, conversation *gtsmodel.Conversation, - requestingAccount *gtsmodel.Account, + requester *gtsmodel.Account, filters []*gtsmodel.Filter, mutes *usermute.CompiledUserMuteList, ) (*apimodel.Conversation, error) { apiConversation := &apimodel.Conversation{ - ID: conversation.ID, - Unread: !*conversation.Read, - Accounts: []apimodel.Account{}, - } - for _, account := range conversation.OtherAccounts { - var apiAccount *apimodel.Account - blocked, err := c.state.DB.IsEitherBlocked(ctx, requestingAccount.ID, account.ID) - if err != nil { - return nil, gtserror.Newf( - "DB error checking blocks between accounts %s and %s: %w", - requestingAccount.ID, - account.ID, - err, - ) - } - if blocked || account.IsSuspended() { - apiAccount, err = c.AccountToAPIAccountBlocked(ctx, account) - } else { - apiAccount, err = c.AccountToAPIAccountPublic(ctx, account) - } - if err != nil { - return nil, gtserror.Newf( - "error converting account %s to API representation: %w", - account.ID, - err, - ) - } - apiConversation.Accounts = append(apiConversation.Accounts, *apiAccount) + ID: conversation.ID, + Unread: !*conversation.Read, } + + // Populate most recent status in convo; + // can be nil if this status is filtered. if conversation.LastStatus != nil { var err error apiConversation.LastStatus, err = c.StatusToAPIStatus( ctx, conversation.LastStatus, - requestingAccount, + requester, statusfilter.FilterContextNotifications, filters, mutes, @@ -1885,6 +1862,60 @@ func (c *Converter) ConversationToAPIConversation( } } + // If no other accounts are involved in this convo, + // just include the requesting account and return. + // + // See: https://github.com/superseriousbusiness/gotosocial/issues/3385#issuecomment-2394033477 + otherAcctsLen := len(conversation.OtherAccounts) + if otherAcctsLen == 0 { + apiAcct, err := c.AccountToAPIAccountPublic(ctx, requester) + if err != nil { + err := gtserror.Newf( + "error converting account %s to API representation: %w", + requester.ID, err, + ) + return nil, err + } + + apiConversation.Accounts = []apimodel.Account{*apiAcct} + return apiConversation, nil + } + + // Other accounts are involved in the + // convo. Convert each to API model. + apiConversation.Accounts = make([]apimodel.Account, otherAcctsLen) + for i, account := range conversation.OtherAccounts { + blocked, err := c.state.DB.IsEitherBlocked(ctx, + requester.ID, account.ID, + ) + if err != nil { + err := gtserror.Newf( + "db error checking blocks between accounts %s and %s: %w", + requester.ID, account.ID, err, + ) + return nil, err + } + + // API account model varies depending + // on status of conversation participant. + var apiAcct *apimodel.Account + if blocked || account.IsSuspended() { + apiAcct, err = c.AccountToAPIAccountBlocked(ctx, account) + } else { + apiAcct, err = c.AccountToAPIAccountPublic(ctx, account) + } + + if err != nil { + err := gtserror.Newf( + "error converting account %s to API representation: %w", + account.ID, err, + ) + return nil, err + } + + apiConversation.Accounts[i] = *apiAcct + } + return apiConversation, nil } |