diff --git a/src/helpers/GroupsHelper.ts b/src/helpers/GroupsHelper.ts index f22fa07..8faa61f 100644 --- a/src/helpers/GroupsHelper.ts +++ b/src/helpers/GroupsHelper.ts @@ -501,6 +501,24 @@ export class GroupsHelper { return members.map((row) => this.DbToGroupMember(row)); } + /** + * Get the list of followers of a group + * + * @param groupID Target Group ID + */ + public static async GetListFollowers(groupID: number) : Promise> { + const members = await DatabaseHelper.Query({ + table: GROUPS_MEMBERS_TABLE, + where: { + groups_id: groupID, + following: 1 + }, + fields: ["user_id"] + }); + + return members.map((row) => row.user_id); + } + /** * Count the number of members of a group * diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index e831a95..fbe2230 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -4,6 +4,7 @@ import { time } from "../utils/DateUtils"; import { PostsHelper } from "./PostsHelper"; import { PostPageKind, PostVisibilityLevel } from "../entities/Post"; import { FriendsHelper } from "./FriendsHelper"; +import { GroupsHelper } from "./GroupsHelper"; /** * Notifications helper @@ -92,8 +93,34 @@ export class NotificationsHelper { } - // TODO : continue + // For posts on grou pages + else if(n.fromContainerType == NotifElemType.GROUP_PAGE) { + await this.PushGroupMembers(n, n.fromContainerID) + } + + // Mark the scenario as unsupported + else { + console.error(n) + throw new Error("Post notification scenario not supported!") + } } + + // TODO : continue + } + + /** + * Push a notification to all the members of a group + * + * @param n The notification to push + * @param groupID Target group ID + */ + private static async PushGroupMembers(n: Notif, groupID: number) { + let list = await GroupsHelper.GetListFollowers(groupID); + + // Remove the user at the source of the notification + list = list.filter((v) => v != n.fromUserID); + + await this.PushPublic(n, list); } /**