1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-21 21:09:22 +00:00

Add groups posts support

This commit is contained in:
Pierre HUBERT 2020-03-24 08:45:20 +01:00
parent 7ab3682df8
commit 27a0c7d1c8
2 changed files with 46 additions and 1 deletions

View File

@ -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<Array<number>> {
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
*

View File

@ -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);
}
/**