2021-06-17 18:02:33 +02:00
|
|
|
package typeutils
|
|
|
|
|
|
|
|
import (
|
2021-08-25 15:34:33 +02:00
|
|
|
"context"
|
2021-06-17 18:02:33 +02:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
|
|
|
)
|
|
|
|
|
2021-08-25 15:34:33 +02:00
|
|
|
func (c *converter) interactionsWithStatusForAccount(ctx context.Context, s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*statusInteractions, error) {
|
2021-06-17 18:02:33 +02:00
|
|
|
si := &statusInteractions{}
|
|
|
|
|
|
|
|
if requestingAccount != nil {
|
2021-08-25 15:34:33 +02:00
|
|
|
faved, err := c.db.IsStatusFavedBy(ctx, s, requestingAccount.ID)
|
2021-06-17 18:02:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error checking if requesting account has faved status: %s", err)
|
|
|
|
}
|
|
|
|
si.Faved = faved
|
|
|
|
|
2021-08-25 15:34:33 +02:00
|
|
|
reblogged, err := c.db.IsStatusRebloggedBy(ctx, s, requestingAccount.ID)
|
2021-06-17 18:02:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error checking if requesting account has reblogged status: %s", err)
|
|
|
|
}
|
|
|
|
si.Reblogged = reblogged
|
|
|
|
|
2021-08-25 15:34:33 +02:00
|
|
|
muted, err := c.db.IsStatusMutedBy(ctx, s, requestingAccount.ID)
|
2021-06-17 18:02:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error checking if requesting account has muted status: %s", err)
|
|
|
|
}
|
|
|
|
si.Muted = muted
|
|
|
|
|
2021-08-25 15:34:33 +02:00
|
|
|
bookmarked, err := c.db.IsStatusBookmarkedBy(ctx, s, requestingAccount.ID)
|
2021-06-17 18:02:33 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error checking if requesting account has bookmarked status: %s", err)
|
|
|
|
}
|
|
|
|
si.Bookmarked = bookmarked
|
|
|
|
}
|
|
|
|
return si, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// StatusInteractions denotes interactions with a status on behalf of an account.
|
|
|
|
type statusInteractions struct {
|
|
|
|
Faved bool
|
|
|
|
Muted bool
|
|
|
|
Bookmarked bool
|
|
|
|
Reblogged bool
|
|
|
|
}
|