Skip to content

Commit

Permalink
Fix GetMessagesByIds
Browse files Browse the repository at this point in the history
  • Loading branch information
deff7 committed Sep 17, 2024
1 parent 9f8bea8 commit 89324db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/block/editor/chatobject/chatobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func (s *storeObject) GetMessagesByIds(ctx context.Context, messageIds []string)
messages := make([]*model.ChatMessage, 0, len(messageIds))
for _, messageId := range messageIds {
obj, err := coll.FindId(txn.Context(), messageId)
if errors.Is(err, anystore.ErrDocNotFound) {
continue
}
if err != nil {
return nil, errors.Join(txn.Commit(), fmt.Errorf("find id: %w", err))
}
Expand Down
21 changes: 21 additions & 0 deletions core/block/editor/chatobject/chatobject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ func TestGetMessages(t *testing.T) {
}
}

func TestGetMessagesByIds(t *testing.T) {
ctx := context.Background()
sessionCtx := session.NewContext()

fx := newFixture(t)

inputMessage := givenMessage()
messageId, err := fx.AddMessage(ctx, sessionCtx, inputMessage)
require.NoError(t, err)

messages, err := fx.GetMessagesByIds(ctx, []string{messageId, "wrongId"})
require.NoError(t, err)
require.Len(t, messages, 1)

want := givenMessage()
want.Id = messageId
want.Creator = testCreator
got := messages[0]
assertMessagesEqual(t, want, got)
}

func TestEditMessage(t *testing.T) {
t.Run("edit own message", func(t *testing.T) {
ctx := context.Background()
Expand Down

0 comments on commit 89324db

Please sign in to comment.