mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 08:35:17 +00:00
Can create a private conversation
This commit is contained in:
@ -121,6 +121,38 @@ export class ConversationsController {
|
||||
h.success("Conversation information successfully updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Find, optionally create and return the ID of a privat conversation
|
||||
*
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async FindPrivate(h: RequestHandler) {
|
||||
const otherUser = await h.postUserId("otherUser");
|
||||
const allowCreate = h.postBool("allowCreate", false);
|
||||
|
||||
// Query the database
|
||||
const list = await ConversationsHelper.FindPrivate(h.getUserId(), otherUser);
|
||||
|
||||
if(list.length == 0) {
|
||||
|
||||
if(!allowCreate)
|
||||
h.error(404, "Not any private conversation was found. The server was not allowed to create a new one...");
|
||||
|
||||
// Create the conversation
|
||||
const convID = await ConversationsHelper.Create({
|
||||
ownerID: h.getUserId(),
|
||||
name: "",
|
||||
following: true,
|
||||
members: new Set([h.getUserId(), otherUser])
|
||||
});
|
||||
|
||||
list.push(convID);
|
||||
}
|
||||
|
||||
|
||||
h.send({"conversationsID": list});
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh current user conversations
|
||||
*
|
||||
|
@ -57,6 +57,8 @@ export const Routes : Route[] = [
|
||||
|
||||
{path: "/conversations/updateSettings", cb: (h) => ConversationsController.UpdateSettings(h)},
|
||||
|
||||
{path: "/conversations/getPrivate", cb: (h) => ConversationsController.FindPrivate(h)},
|
||||
|
||||
{path: "/conversations/refresh", cb: (h) => ConversationsController.RefreshList(h)},
|
||||
|
||||
{path: "/conversations/refresh_single", cb: (h) => ConversationsController.RefreshSingleConversation(h)},
|
||||
|
Reference in New Issue
Block a user