gotosocial/internal/typeutils/util.go
tobi 4920229a3b
Database updates (#144)
* start moving some database stuff around

* continue moving db stuff around

* more fiddling

* more updates

* and some more

* and yet more

* i broke SOMETHING but what, it's a mystery

* tidy up

* vendor ttlcache

* use ttlcache

* fix up some tests

* rename some stuff

* little reminder

* some more updates
2021-08-20 12:26:56 +02:00

47 lines
1.3 KiB
Go

package typeutils
import (
"fmt"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
func (c *converter) interactionsWithStatusForAccount(s *gtsmodel.Status, requestingAccount *gtsmodel.Account) (*statusInteractions, error) {
si := &statusInteractions{}
if requestingAccount != nil {
faved, err := c.db.IsStatusFavedBy(s, requestingAccount.ID)
if err != nil {
return nil, fmt.Errorf("error checking if requesting account has faved status: %s", err)
}
si.Faved = faved
reblogged, err := c.db.IsStatusRebloggedBy(s, requestingAccount.ID)
if err != nil {
return nil, fmt.Errorf("error checking if requesting account has reblogged status: %s", err)
}
si.Reblogged = reblogged
muted, err := c.db.IsStatusMutedBy(s, requestingAccount.ID)
if err != nil {
return nil, fmt.Errorf("error checking if requesting account has muted status: %s", err)
}
si.Muted = muted
bookmarked, err := c.db.IsStatusBookmarkedBy(s, requestingAccount.ID)
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
}