mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 16:45:16 +00:00
Can update the list of members of a conversation.
This commit is contained in:
@ -76,37 +76,48 @@ export class ConversationsController {
|
||||
/**
|
||||
* Update conversation settings
|
||||
*
|
||||
* @param handler Request handler
|
||||
* @param h Request handler
|
||||
*/
|
||||
public static async UpdateSettings(handler: RequestHandler) : Promise<void> {
|
||||
const convID = await this.GetPostConversationId("conversationID", handler);
|
||||
public static async UpdateSettings(h: RequestHandler) : Promise<void> {
|
||||
const convID = await this.GetPostConversationId("conversationID", h);
|
||||
|
||||
// Update following state, if required
|
||||
if(handler.hasPostParameter("following")) {
|
||||
if(h.hasPostParameter("following")) {
|
||||
await ConversationsHelper.SetFollowing(
|
||||
handler.getUserId(),
|
||||
h.getUserId(),
|
||||
convID,
|
||||
handler.postBool("following")
|
||||
h.postBool("following")
|
||||
);
|
||||
}
|
||||
|
||||
// Change moderator settings
|
||||
if(handler.hasPostParameter("members") || handler.hasPostParameter("name")) {
|
||||
if(h.hasPostParameter("members") || h.hasPostParameter("name")) {
|
||||
|
||||
// Check if user is the moderator of the conversation
|
||||
if(!await ConversationsHelper.IsUserModerator(handler.getUserId(), convID))
|
||||
handler.error(401, "You are not allowed to perform changes on this conversation !");
|
||||
if(!await ConversationsHelper.IsUserModerator(h.getUserId(), convID))
|
||||
h.error(401, "You are not allowed to perform changes on this conversation !");
|
||||
|
||||
|
||||
// Update conversation name (if required)
|
||||
if(handler.hasPostParameter("name")) {
|
||||
const name = handler.postString("name");
|
||||
if(h.hasPostParameter("name")) {
|
||||
const name = h.postString("name");
|
||||
await ConversationsHelper.SetName(convID, name == "false" ? "" : removeHTMLNodes(name));
|
||||
}
|
||||
|
||||
// Update the list of members of the conversation (if required)
|
||||
if(h.hasPostParameter("members")) {
|
||||
const members = h.postNumbersSet("members");
|
||||
|
||||
// Make sure current user is on the list
|
||||
if(!members.has(h.getUserId()))
|
||||
members.add(h.getUserId());
|
||||
|
||||
await ConversationsHelper.SetMembers(convID, members);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
handler.success("Conversation information successfully updated!");
|
||||
h.success("Conversation information successfully updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user