From 47e9d46b4d3b5cba3df68fc1f7830838d1d54b7e Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 30 Nov 2019 14:25:06 +0100 Subject: [PATCH] Can change conversation name --- src/controllers/ConversationsController.ts | 16 +++++++++++++++- src/helpers/ConversationsHelper.ts | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 7912103..f96eaef 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -90,7 +90,21 @@ export class ConversationsController { ); } - // TODO : update moderation settings + // Change moderator settings + if(handler.hasPostParameter("members") || handler.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 !"); + + + // Update conversation name (if required) + if(handler.hasPostParameter("name")) { + const name = handler.postString("name"); + await ConversationsHelper.SetName(convID, name == "false" ? "" : removeHTMLNodes(name)); + } + + } handler.success("Conversation information successfully updated!"); } diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index 5a2c5a7..1dd670c 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -146,6 +146,25 @@ export class ConversationsHelper { }) == 1; } + /** + * Change the name of a conversation + * + * @param convID Target conversation + * @param name New name for the conversation (empty name + * to remove it) + */ + public static async SetName(convID: number, name: string) { + await DatabaseHelper.UpdateRows({ + table: LIST_TABLE, + where: { + id: convID + }, + set: { + name: name + } + }); + } + /** * Update following state of the conversation *