From 900ed3cf980f1c64b863c07ce267773d53a7225b Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 24 Mar 2020 18:59:06 +0100 Subject: [PATCH] Can send notification to all groups moderators --- src/controllers/GroupsController.ts | 6 +++++- src/helpers/NotificationsHelper.ts | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index 99dfd15..f05a884 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -328,7 +328,11 @@ export class GroupsController { // Respond to the invitation await GroupsHelper.RespondInvitation(groupID, h.getUserId(), accept); - // TODO : Create a notification + // Create a notification + await NotificationsUtils.CreateGroupMembershipNotification( + h.getUserId(), 0, groupID, + accept ? NotifEventType.ACCEPTED_GROUP_MEMBERSHIP_INVITATION : NotifEventType.REJECTED_GROUP_MEMBERSHIP_INVITATION + ) h.success("Response to the invitation was successfully saved!"); } diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index de7313d..3058d6b 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -5,6 +5,7 @@ import { PostsHelper } from "./PostsHelper"; import { PostPageKind, PostVisibilityLevel } from "../entities/Post"; import { FriendsHelper } from "./FriendsHelper"; import { GroupsHelper } from "./GroupsHelper"; +import { GroupMembershipLevels } from "../entities/GroupMember"; /** * Notifications helper @@ -133,7 +134,7 @@ export class NotificationsHelper { else { // Push the notification to all the moderators of the group - throw new Error("//TODO Push notification to all members of the group"); + await this.PushGroupModerators(n, n.onElemID); } } @@ -160,6 +161,22 @@ export class NotificationsHelper { await this.PushPublic(n, list); } + /** + * Push a notification to all the moderators & administrators of a group + * + * @param n The notification to push + * @param groupID Target group ID + */ + private static async PushGroupModerators(n: Notif, groupID: number) { + let list = await GroupsHelper.GetListMembers(groupID); + + // Remove all the users who are not moderators or administrators + list = list.filter((v) => v.level <= GroupMembershipLevels.MODERATOR); + const ids = list.map((v) => v.userID); + + await this.PushPublic(n, ids); + } + /** * Push a notification to multiple users *