mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Can refresh conversation messages
This commit is contained in:
@ -132,7 +132,7 @@ export class ConversationsController {
|
||||
|
||||
// Check for new conversations
|
||||
if(h.hasPostParameter("newConversations")) {
|
||||
for(const convID of h.postNumbersSet("newConversations")) {
|
||||
for(const convID of h.postNumbersSet("newConversations", 0)) {
|
||||
if(!ConversationsHelper.DoesUsersBelongsTo(h.getUserId(), convID))
|
||||
h.error(401, "You are not allowed to fetch the messages of this conversation ("+convID+")!");
|
||||
|
||||
@ -144,7 +144,37 @@ export class ConversationsController {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Check for refresh on some conversations
|
||||
// Check for refresh on some conversations
|
||||
if(h.hasPostParameter("toRefresh")) {
|
||||
const toRefresh = h.postJSON("toRefresh");
|
||||
|
||||
for (const key in toRefresh) {
|
||||
if (toRefresh.hasOwnProperty(key)) {
|
||||
const element = toRefresh[key];
|
||||
|
||||
// Extract conversation ID
|
||||
if(!key.startsWith("conversation-"))
|
||||
h.error(400, "Entries of 'toRefresh' should start with 'conversation-' !");
|
||||
const convID = Number.parseInt(key.replace("conversation-", ""));
|
||||
|
||||
// Extract last message ID
|
||||
if(!element.hasOwnProperty("last_message_id"))
|
||||
h.error(400, "Missing last_message_id for conversation " + convID + "!");
|
||||
const lastMessageID = Number.parseInt(element.last_message_id);
|
||||
|
||||
// Check user rights
|
||||
if(!ConversationsHelper.DoesUsersBelongsTo(h.getUserId(), convID))
|
||||
h.error(401, "You are not allowed to fetch the messages of this conversation ("+convID+")!");
|
||||
|
||||
// Get the messages
|
||||
list["conversation-" + convID] = (await ConversationsHelper.GetNewMessages(convID, lastMessageID))
|
||||
.map(e => this.ConversationMessageToAPI(e));
|
||||
|
||||
// Mark the user has seen the messages
|
||||
await ConversationsHelper.MarkUserSeen(convID, h.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h.send(list);
|
||||
}
|
||||
|
Reference in New Issue
Block a user