From cdf59e29b84ee0423bc498749f73ab4ca915cb6b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 30 Nov 2019 16:44:27 +0100 Subject: [PATCH] Can get the messages of a single conversation. --- src/controllers/ConversationsController.ts | 23 ++++++++++++++++++++++ src/controllers/Routes.ts | 2 ++ 2 files changed, 25 insertions(+) diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index cf1723f..af2112a 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -179,6 +179,29 @@ export class ConversationsController { h.send(list); } + /** + * Refresh the messages of a single conversation + * + * @param h Request handler + */ + public static async RefreshSingleConversation(h: RequestHandler) { + const convID = await this.GetPostConversationId("conversationID", h); + const lastMessageID = h.postInt("last_message_id"); + + const messages = lastMessageID == 0 ? + + // Get lastest messages (the user has no message yet) + await ConversationsHelper.GetLastMessages(convID, 10) : + + // Get new messages + await ConversationsHelper.GetNewMessages(convID, lastMessageID); + + // Specify the user has seen the last message + await ConversationsHelper.MarkUserSeen(convID, h.getUserId()); + + h.send(h.send(messages.map(e => this.ConversationMessageToAPI(e))); + } + /** * Get and return safely a conversation ID specified in a $_POST Request * diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index a5af6f8..47f2200 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -58,6 +58,8 @@ export const Routes : Route[] = [ {path: "/conversations/updateSettings", cb: (h) => ConversationsController.UpdateSettings(h)}, {path: "/conversations/refresh", cb: (h) => ConversationsController.RefreshList(h)}, + + {path: "/conversations/refresh_single", cb: (h) => ConversationsController.RefreshSingleConversation(h)}, // Search controller