diff --git a/packages/api/services/conversation.service.ts b/packages/api/services/conversation.service.ts index a35a5ff..4bd17b6 100644 --- a/packages/api/services/conversation.service.ts +++ b/packages/api/services/conversation.service.ts @@ -7,10 +7,19 @@ export default class ConversationService { return await collections.conversations?.insertOne(newConversation); } + /** + * + * @param userId + * @returns all conversations for user + * sorted by lastActivityDate descending + */ static async getAllConversationsForUser(userId: string) { const query = { 'members._id': new ObjectId(userId) }; - const res = await collections.conversations?.find(query).toArray(); + const res = await collections.conversations + ?.find(query) + .sort({ lastActivityDate: -1 }) + .toArray(); // exists if (res?.length) {