show child statuses in context

This commit is contained in:
tsmethurst 2021-06-17 17:23:13 +02:00
parent 6a053ecfd8
commit d1eff9503e
3 changed files with 59 additions and 33 deletions

View File

@ -1,8 +1,10 @@
package pg package pg
import ( import (
"container/list"
"errors"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"sync"
) )
func (ps *postgresService) StatusParents(status *gtsmodel.Status) ([]*gtsmodel.Status, error) { func (ps *postgresService) StatusParents(status *gtsmodel.Status) ([]*gtsmodel.Status, error) {
@ -26,25 +28,48 @@ func (ps *postgresService) statusParent(status *gtsmodel.Status, foundStatuses *
} }
func (ps *postgresService) StatusChildren(status *gtsmodel.Status) ([]*gtsmodel.Status, error) { func (ps *postgresService) StatusChildren(status *gtsmodel.Status) ([]*gtsmodel.Status, error) {
foundStatuses := &list.List{}
foundStatuses.PushFront(status)
ps.statusChildren(status, foundStatuses)
children := []*gtsmodel.Status{} children := []*gtsmodel.Status{}
// ps.statusChildren(status, &children) for e := foundStatuses.Front(); e != nil; e = e.Next() {
entry, ok := e.Value.(*gtsmodel.Status)
if !ok {
panic(errors.New("entry in foundStatuses was not a *gtsmodel.Status"))
}
// only append children, not the overall parent status
if entry.ID != status.ID {
children = append(children, entry)
}
}
return children, nil return children, nil
} }
func (ps *postgresService) statusChildren(status *gtsmodel.Status, foundStatuses *sync.Map) { func (ps *postgresService) statusChildren(status *gtsmodel.Status, foundStatuses *list.List) {
// immediateChildren := []*gtsmodel.Status{} immediateChildren := []*gtsmodel.Status{}
// foundStatuses.Store()
// err := ps.conn.Model(&immediateChildren).Where("in_reply_to_id = ?", status.ID).Select() err := ps.conn.Model(&immediateChildren).Where("in_reply_to_id = ?", status.ID).Select()
// if err != nil { if err != nil {
// return return
// } }
// for _, child := range immediateChildren { for _, child := range immediateChildren {
// f[""][0] = child insertLoop:
// } for e := foundStatuses.Front(); e != nil; e = e.Next() {
entry, ok := e.Value.(*gtsmodel.Status)
if !ok {
panic(errors.New("entry in foundStatuses was not a *gtsmodel.Status"))
}
return if child.InReplyToAccountID != "" && entry.ID == child.InReplyToID {
foundStatuses.InsertAfter(child, e)
break insertLoop
}
}
ps.statusChildren(child, foundStatuses)
}
} }

View File

@ -47,6 +47,10 @@ func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*
} }
} }
sort.Slice(context.Ancestors, func(i int, j int) bool {
return context.Ancestors[i].ID < context.Ancestors[j].ID
})
children, err := p.db.StatusChildren(targetStatus) children, err := p.db.StatusChildren(targetStatus)
if err != nil { if err != nil {
return nil, gtserror.NewErrorInternalError(err) return nil, gtserror.NewErrorInternalError(err)
@ -56,18 +60,10 @@ func (p *processor) Context(account *gtsmodel.Account, targetStatusID string) (*
if v, err := p.filter.StatusVisible(status, account); err == nil && v { if v, err := p.filter.StatusVisible(status, account); err == nil && v {
mastoStatus, err := p.tc.StatusToMasto(status, account) mastoStatus, err := p.tc.StatusToMasto(status, account)
if err == nil { if err == nil {
context.Ancestors = append(context.Ancestors, *mastoStatus) context.Descendants = append(context.Descendants, *mastoStatus)
} }
} }
} }
sort.Slice(context.Ancestors, func(i int, j int) bool {
return context.Ancestors[i].ID < context.Ancestors[j].ID
})
sort.Slice(context.Descendants, func(i int, j int) bool {
return context.Descendants[i].ID < context.Descendants[j].ID
})
return context, nil return context, nil
} }

View File

@ -7,18 +7,18 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
) )
func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, requestingAccount *gtsmodel.Account) (bool, error) { func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, timelineOwnerAccount *gtsmodel.Account) (bool, error) {
l := f.log.WithFields(logrus.Fields{ l := f.log.WithFields(logrus.Fields{
"func": "StatusHometimelineable", "func": "StatusHometimelineable",
"statusID": targetStatus.ID, "statusID": targetStatus.ID,
}) })
// status owner should always be able to see their status in their timeline so we can return early if this is the case // status owner should always be able to see their own status in their timeline so we can return early if this is the case
if requestingAccount != nil && targetStatus.AccountID == requestingAccount.ID { if timelineOwnerAccount != nil && targetStatus.AccountID == timelineOwnerAccount.ID {
return true, nil return true, nil
} }
v, err := f.StatusVisible(targetStatus, requestingAccount) v, err := f.StatusVisible(targetStatus, timelineOwnerAccount)
if err != nil { if err != nil {
return false, fmt.Errorf("StatusHometimelineable: error checking visibility of status with id %s: %s", targetStatus.ID, err) return false, fmt.Errorf("StatusHometimelineable: error checking visibility of status with id %s: %s", targetStatus.ID, err)
} }
@ -48,10 +48,15 @@ func (f *filter) StatusHometimelineable(targetStatus *gtsmodel.Status, requestin
targetStatus.GTSReplyToAccount = ra targetStatus.GTSReplyToAccount = ra
} }
// make sure the requesting account follows the replied-to account // if it's a reply to the timelineOwnerAccount, we don't need to check if the timelineOwnerAccount follows itself, just return true, they can see it
follows, err := f.db.Follows(requestingAccount, targetStatus.GTSReplyToAccount) if targetStatus.AccountID == timelineOwnerAccount.ID {
return true, nil
}
// the replied-to account != timelineOwnerAccount, so make sure the timelineOwnerAccount follows the replied-to account
follows, err := f.db.Follows(timelineOwnerAccount, targetStatus.GTSReplyToAccount)
if err != nil { if err != nil {
return false, fmt.Errorf("StatusHometimelineable: error checking follow from account %s to account %s: %s", requestingAccount.ID, targetStatus.InReplyToAccountID, err) return false, fmt.Errorf("StatusHometimelineable: error checking follow from account %s to account %s: %s", timelineOwnerAccount.ID, targetStatus.InReplyToAccountID, err)
} }
if !follows { if !follows {