mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-18 09:17:30 -06:00
[feature] add support for polls + receiving federated status edits (#2330)
This commit is contained in:
parent
7204ccedc3
commit
e9e5dc5a40
84 changed files with 3992 additions and 570 deletions
|
|
@ -20,10 +20,10 @@ package bundb
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/db"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||
|
|
@ -54,31 +54,9 @@ func (m *mentionDB) GetMention(ctx context.Context, id string) (*gtsmodel.Mentio
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Set the mention originating status.
|
||||
mention.Status, err = m.state.DB.GetStatusByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
mention.StatusID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error populating mention status: %w", err)
|
||||
}
|
||||
|
||||
// Set the mention origin account model.
|
||||
mention.OriginAccount, err = m.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
mention.OriginAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error populating mention origin account: %w", err)
|
||||
}
|
||||
|
||||
// Set the mention target account model.
|
||||
mention.TargetAccount, err = m.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
mention.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error populating mention target account: %w", err)
|
||||
// Further populate the mention fields where applicable.
|
||||
if err := m.PopulateMention(ctx, mention); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mention, nil
|
||||
|
|
@ -102,6 +80,45 @@ func (m *mentionDB) GetMentions(ctx context.Context, ids []string) ([]*gtsmodel.
|
|||
return mentions, nil
|
||||
}
|
||||
|
||||
func (m *mentionDB) PopulateMention(ctx context.Context, mention *gtsmodel.Mention) (err error) {
|
||||
var errs gtserror.MultiError
|
||||
|
||||
if mention.Status == nil {
|
||||
// Set the mention originating status.
|
||||
mention.Status, err = m.state.DB.GetStatusByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
mention.StatusID,
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error populating mention status: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if mention.OriginAccount == nil {
|
||||
// Set the mention origin account model.
|
||||
mention.OriginAccount, err = m.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
mention.OriginAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error populating mention origin account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if mention.TargetAccount == nil {
|
||||
// Set the mention target account model.
|
||||
mention.TargetAccount, err = m.state.DB.GetAccountByID(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
mention.TargetAccountID,
|
||||
)
|
||||
if err != nil {
|
||||
return gtserror.Newf("error populating mention target account: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return errs.Combine()
|
||||
}
|
||||
|
||||
func (m *mentionDB) PutMention(ctx context.Context, mention *gtsmodel.Mention) error {
|
||||
return m.state.Caches.GTS.Mention().Store(mention, func() error {
|
||||
_, err := m.db.NewInsert().Model(mention).Exec(ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue