From 5d604bc57682e96dc14fe89312b8764df3425b2f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 25 Apr 2020 18:34:31 +0200 Subject: [PATCH] Can update "can_everyone_add_members" conversation setting --- src/controllers/ConversationsController.ts | 9 ++++++++- src/helpers/ConversationsHelper.ts | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 07b41bd..5bed968 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -95,7 +95,7 @@ export class ConversationsController { } // Change moderator settings - if(h.hasPostParameter("members") || h.hasPostParameter("name")) { + if(h.hasPostParameter("members") || h.hasPostParameter("name") || h.hasPostParameter("canEveryoneAddMembers")) { // Check if user is the moderator of the conversation if(!await ConversationsHelper.IsUserModerator(h.getUserId(), convID)) @@ -119,6 +119,11 @@ export class ConversationsController { await ConversationsHelper.SetMembers(convID, members); } + // Update "canEveryoneAddMembers" parameter + if(h.hasPostParameter("canEveryoneAddMembers")) { + await ConversationsHelper.SetCanEveryoneAddMembers(convID, h.postBool("canEveryoneAddMembers")); + } + } h.success("Conversation information successfully updated!"); @@ -160,6 +165,8 @@ export class ConversationsController { * Refresh current user conversations * * @param h Request handler + * @deprecated Only ComunicWeb was using this method until + * the introduction of WebSockets... */ public static async RefreshList(h: RequestHandler) { diff --git a/src/helpers/ConversationsHelper.ts b/src/helpers/ConversationsHelper.ts index 623fc09..2e511b7 100644 --- a/src/helpers/ConversationsHelper.ts +++ b/src/helpers/ConversationsHelper.ts @@ -208,6 +208,27 @@ export class ConversationsHelper { } } + /** + * Specify whether any member of this conversation can invite other users + * to join it + * + * @param convID Target conversation ID + * @param allow If set to true, all the members of the conversation + * will be allowed to add members to this conversation (this parameters + * is not related with the deletion of members) + */ + public static async SetCanEveryoneAddMembers(convID: number, allow: boolean) { + await DatabaseHelper.UpdateRows({ + table: LIST_TABLE, + where: { + "id": convID + }, + set: { + "can_everyone_add_members": allow ? 1 : 0 + } + }) + } + /** * Update following state of the conversation *