mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-12-27 22:18:52 +00:00
Add groups posts support
This commit is contained in:
parent
7ab3682df8
commit
27a0c7d1c8
@ -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
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user