Skip to content

Commit

Permalink
Now updating user's info in the stream.AttributedTo link
Browse files Browse the repository at this point in the history
  • Loading branch information
benpate committed Jan 21, 2025
1 parent 61cbafd commit 6c090e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions queries/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package queries
import (
"context"

"github.com/EmissarySocial/emissary/model"
"github.com/benpate/data"
"github.com/benpate/derp"
"github.com/benpate/exp"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
Expand Down Expand Up @@ -38,3 +40,16 @@ func MaxRank(ctx context.Context, collection data.Collection, parentID primitive
// Otherwise, return the count returned by mongo.
return result[0].MaxRank + 1, nil
}

func SetAttributedTo(ctx context.Context, collection data.Collection, personLink model.PersonLink) error {

criteria := exp.Equal("attributedTo.userId", personLink.UserID)

update := bson.M{
"$set": bson.M{
"attributedTo": personLink,
},
}

return RawUpdate(ctx, collection, criteria, update)
}
5 changes: 5 additions & 0 deletions service/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,11 @@ func (service *Stream) SetLocationChild(template *model.Template, stream *model.
* Custom Actions
******************************************/

func (service *Stream) SetAttributedTo(user *model.User) {
err := queries.SetAttributedTo(context.Background(), service.collection, user.PersonLink())
derp.Report(derp.Wrap(err, "service.Stream.SetAttributedTo", "Error setting attributedTo"))
}

func (service *Stream) DeleteByParent(parentID primitive.ObjectID, note string) error {
return service.DeleteMany(exp.Equal("parentId", parentID), note)
}
Expand Down
3 changes: 3 additions & 0 deletions service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func (service *User) Save(user *model.User, note string) error {
}
}

// Denormalize User information into the Streams they own.
go service.streamService.SetAttributedTo(user)

// Send Webhooks (if configured)
if isNew {
service.webhookService.Send(user, model.WebhookEventUserCreate)
Expand Down

0 comments on commit 6c090e1

Please sign in to comment.