This commit is contained in:
2026-06-10 07:55:16 +08:00
parent 821eca9f0c
commit aaac7e9d98
31 changed files with 548 additions and 149 deletions
+14 -2
View File
@@ -84,7 +84,8 @@ func (s *conversationService) Create(ctx context.Context, userID uuid.UUID, in C
}
// Get returns a conversation and its most recent messages, enforcing ownership.
func (s *conversationService) Get(ctx context.Context, userID, id uuid.UUID) (*Conversation, []Message, error) {
// limit caps the number of returned messages (defaults to 50 when non-positive).
func (s *conversationService) Get(ctx context.Context, userID, id uuid.UUID, limit int) (*Conversation, []Message, error) {
c, err := s.repo.GetConversation(ctx, id)
if err != nil {
return nil, nil, err
@@ -92,10 +93,21 @@ func (s *conversationService) Get(ctx context.Context, userID, id uuid.UUID) (*C
if c.UserID != userID {
return nil, nil, errs.New(errs.CodeForbidden, "not conversation owner")
}
msgs, err := s.repo.ListMessagesByConversation(ctx, id, nil, 50)
if limit <= 0 {
limit = 50
}
msgs, err := s.repo.ListMessagesByConversation(ctx, id, nil, limit)
if err != nil {
return nil, nil, err
}
// Populate each message's attachments for the user-facing read path.
for i := range msgs {
atts, err := s.repo.ListAttachmentsForMessage(ctx, msgs[i].ID)
if err != nil {
return nil, nil, err
}
msgs[i].Attachments = atts
}
return c, msgs, nil
}