mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
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
This commit is contained in:
@ -1,46 +1,45 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode) {
|
||||
func (p *processor) Context(requestingAccount *gtsmodel.Account, targetStatusID string) (*apimodel.Context, gtserror.WithCode) {
|
||||
targetStatus, err := p.db.GetStatusByID(targetStatusID)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error fetching status %s: %s", targetStatusID, err))
|
||||
}
|
||||
if targetStatus.Account == nil {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("no status owner for status %s", targetStatusID))
|
||||
}
|
||||
|
||||
visible, err := p.filter.StatusVisible(targetStatus, requestingAccount)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorNotFound(fmt.Errorf("error seeing if status %s is visible: %s", targetStatus.ID, err))
|
||||
}
|
||||
if !visible {
|
||||
return nil, gtserror.NewErrorNotFound(errors.New("status is not visible"))
|
||||
}
|
||||
|
||||
context := &apimodel.Context{
|
||||
Ancestors: []apimodel.Status{},
|
||||
Descendants: []apimodel.Status{},
|
||||
}
|
||||
|
||||
targetStatus := >smodel.Status{}
|
||||
if err := p.db.GetByID(targetStatusID, targetStatus); err != nil {
|
||||
if _, ok := err.(db.ErrNoEntries); ok {
|
||||
return nil, gtserror.NewErrorNotFound(err)
|
||||
}
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
visible, err := p.filter.StatusVisible(targetStatus, account)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorNotFound(err)
|
||||
}
|
||||
if !visible {
|
||||
return nil, gtserror.NewErrorForbidden(fmt.Errorf("account with id %s does not have permission to view status %s", account.ID, targetStatusID))
|
||||
}
|
||||
|
||||
parents, err := p.db.StatusParents(targetStatus, false)
|
||||
parents, err := p.db.GetStatusParents(targetStatus, false)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
for _, status := range parents {
|
||||
if v, err := p.filter.StatusVisible(status, account); err == nil && v {
|
||||
mastoStatus, err := p.tc.StatusToMasto(status, account)
|
||||
if v, err := p.filter.StatusVisible(status, requestingAccount); err == nil && v {
|
||||
mastoStatus, err := p.tc.StatusToMasto(status, requestingAccount)
|
||||
if err == nil {
|
||||
context.Ancestors = append(context.Ancestors, *mastoStatus)
|
||||
}
|
||||
@ -51,14 +50,14 @@ func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*
|
||||
return context.Ancestors[i].ID < context.Ancestors[j].ID
|
||||
})
|
||||
|
||||
children, err := p.db.StatusChildren(targetStatus, false, "")
|
||||
children, err := p.db.GetStatusChildren(targetStatus, false, "")
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
for _, status := range children {
|
||||
if v, err := p.filter.StatusVisible(status, account); err == nil && v {
|
||||
mastoStatus, err := p.tc.StatusToMasto(status, account)
|
||||
if v, err := p.filter.StatusVisible(status, requestingAccount); err == nil && v {
|
||||
mastoStatus, err := p.tc.StatusToMasto(status, requestingAccount)
|
||||
if err == nil {
|
||||
context.Descendants = append(context.Descendants, *mastoStatus)
|
||||
}
|
||||
|
Reference in New Issue
Block a user