mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-07-11 20:32:48 +00:00
Can open new conversations
This commit is contained in:
src
controllers
entities
helpers
@ -3,6 +3,7 @@ import { ConversationsHelper } from "../helpers/ConversationsHelper";
|
||||
import { Conversation, BaseConversation } from "../entities/Conversation";
|
||||
import { UserHelper } from "../helpers/UserHelper";
|
||||
import { removeHTMLNodes } from "../utils/StringUtils";
|
||||
import { ConversationMessage } from "../entities/ConversationMessage";
|
||||
|
||||
/**
|
||||
* Conversations controller
|
||||
@ -120,6 +121,33 @@ export class ConversationsController {
|
||||
h.success("Conversation information successfully updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh current user conversations
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async RefreshList(h: RequestHandler) {
|
||||
|
||||
const list = {};
|
||||
|
||||
// Check for new conversations
|
||||
if(h.hasPostParameter("newConversations")) {
|
||||
for(const convID of h.postNumbersSet("newConversations")) {
|
||||
if(!ConversationsHelper.DoesUsersBelongsTo(h.getUserId(), convID))
|
||||
h.error(401, "You are not allowed to fetch the messages of this conversation ("+convID+")!");
|
||||
|
||||
list["conversation-" + convID] = (await ConversationsHelper.GetLastMessages(convID, 10))
|
||||
.map(e => this.ConversationMessageToAPI(e));
|
||||
|
||||
// TODO : mark the user has seen the messages
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Check for refresh on some conversations
|
||||
|
||||
h.send(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and return safely a conversation ID specified in a $_POST Request
|
||||
*
|
||||
@ -152,4 +180,19 @@ export class ConversationsController {
|
||||
members: [...c.members]
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a conversation message into an API object
|
||||
*
|
||||
* @param c Information about the conversation
|
||||
*/
|
||||
private static ConversationMessageToAPI(c: ConversationMessage) : any {
|
||||
return {
|
||||
ID: c.id,
|
||||
ID_user: c.userID,
|
||||
time_insert: c.timeSent,
|
||||
message: c.message,
|
||||
image_path: c.hasImage ? c.imageURL : null
|
||||
};
|
||||
}
|
||||
}
|
@ -57,6 +57,9 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/conversations/updateSettings", cb: (h) => ConversationsController.UpdateSettings(h)},
|
||||
|
||||
{path: "/conversations/refresh", cb: (h) => ConversationsController.RefreshList(h)},
|
||||
|
||||
|
||||
// Search controller
|
||||
{path: "/search/user", cb: (h) => SearchController.SearchUser(h)},
|
||||
{path: "/user/search", cb: (h) => SearchController.SearchUser(h)}, // Legacy
|
||||
|
Reference in New Issue
Block a user