1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 13:29:22 +00:00

Can get the messages of a single conversation.

This commit is contained in:
Pierre HUBERT 2019-11-30 16:44:27 +01:00
parent 2d29db4900
commit cdf59e29b8
2 changed files with 25 additions and 0 deletions

View File

@ -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
*

View File

@ -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