start work on notifications
This commit is contained in:
@ -18,7 +18,11 @@
|
||||
|
||||
package message
|
||||
|
||||
import "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||
)
|
||||
|
||||
func (p *processor) notifyStatus(status *gtsmodel.Status) error {
|
||||
return nil
|
||||
@ -29,5 +33,17 @@ func (p *processor) notifyFollow(follow *gtsmodel.Follow) error {
|
||||
}
|
||||
|
||||
func (p *processor) notifyFave(fave *gtsmodel.StatusFave) error {
|
||||
return nil
|
||||
|
||||
notif := >smodel.Notification{
|
||||
NotificationType: gtsmodel.NotificationFave,
|
||||
TargetAccountID: fave.TargetAccountID,
|
||||
OriginAccountID: fave.AccountID,
|
||||
StatusID: fave.StatusID,
|
||||
}
|
||||
|
||||
if err := p.db.Put(notif); err != nil {
|
||||
return fmt.Errorf("notifyFave: error putting fave in database: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -74,6 +74,16 @@ func (p *processor) processFromFederator(federatorMsg gtsmodel.FromFederator) er
|
||||
if err := p.db.UpdateByID(incomingAccount.ID, incomingAccount); err != nil {
|
||||
return fmt.Errorf("error updating dereferenced account in the db: %s", err)
|
||||
}
|
||||
case gtsmodel.ActivityStreamsLike:
|
||||
// CREATE A FAVE
|
||||
incomingFave, ok := federatorMsg.GTSModel.(*gtsmodel.StatusFave)
|
||||
if !ok {
|
||||
return errors.New("like was not parseable as *gtsmodel.StatusFave")
|
||||
}
|
||||
|
||||
if err := p.notifyFave(incomingFave); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case gtsmodel.ActivityStreamsUpdate:
|
||||
// UPDATE
|
||||
|
||||
24
internal/message/notificationsprocess.go
Normal file
24
internal/message/notificationsprocess.go
Normal file
@ -0,0 +1,24 @@
|
||||
package message
|
||||
|
||||
import (
|
||||
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/oauth"
|
||||
)
|
||||
|
||||
func (p *processor) NotificationsGet(authed *oauth.Auth, limit int, maxID string) ([]*apimodel.Notification, ErrorWithCode) {
|
||||
notifs, err := p.db.GetNotificationsForAccount(authed.Account.ID, limit, maxID)
|
||||
if err != nil {
|
||||
return nil, NewErrorInternalError(err)
|
||||
}
|
||||
|
||||
mastoNotifs := []*apimodel.Notification{}
|
||||
for _, n := range notifs {
|
||||
mastoNotif, err := p.tc.NotificationToMasto(n)
|
||||
if err != nil {
|
||||
return nil, NewErrorInternalError(err)
|
||||
}
|
||||
mastoNotifs = append(mastoNotifs, mastoNotif)
|
||||
}
|
||||
|
||||
return mastoNotifs, nil
|
||||
}
|
||||
@ -106,6 +106,9 @@ type Processor interface {
|
||||
// MediaUpdate handles the PUT of a media attachment with the given ID and form
|
||||
MediaUpdate(authed *oauth.Auth, attachmentID string, form *apimodel.AttachmentUpdateRequest) (*apimodel.Attachment, ErrorWithCode)
|
||||
|
||||
// NotificationsGet
|
||||
NotificationsGet(authed *oauth.Auth, limit int, maxID string) ([]*apimodel.Notification, ErrorWithCode)
|
||||
|
||||
// StatusCreate processes the given form to create a new status, returning the api model representation of that status if it's OK.
|
||||
StatusCreate(authed *oauth.Auth, form *apimodel.AdvancedStatusCreateForm) (*apimodel.Status, error)
|
||||
// StatusDelete processes the delete of a given status, returning the deleted status if the delete goes through.
|
||||
|
||||
Reference in New Issue
Block a user