From c9f25a46ae660c44cbda10253390232fef15096c Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 30 Nov 2019 15:22:10 +0100 Subject: [PATCH] Can mark conversation messages as seen --- src/controllers/ConversationsController.ts | 3 ++- src/helpers/ConversationsHelper.ts | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 8412bb6..41379e9 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -139,7 +139,8 @@ export class ConversationsController { list["conversation-" + convID] = (await ConversationsHelper.GetLastMessages(convID, 10)) .map(e => this.ConversationMessageToAPI(e)); - // TODO : mark the user has seen the messages + // Mark the user has seen the messages + await ConversationsHelper.MarkUserSeen(convID, h.getUserId()); } } diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index 266b056..1d19cde 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -258,6 +258,25 @@ export class ConversationsHelper { })).map(m => this.DBToConversationMessage(convID, m)); } + /** + * Mark the user has seen the last messages of the conversation + * + * @param convID Target conversation ID + * @param userID Target user ID + */ + public static async MarkUserSeen(convID: number, userID: number) { + await DatabaseHelper.UpdateRows({ + table: USERS_TABLE, + where: { + conv_id: convID, + user_id: userID + }, + set: { + saw_last_message: 1 + } + }); + } + /** * Get the list of members of a conversation *