diff --git a/src/helpers/NotificationsHelper.ts b/src/helpers/NotificationsHelper.ts index 0c2004f..e831a95 100644 --- a/src/helpers/NotificationsHelper.ts +++ b/src/helpers/NotificationsHelper.ts @@ -3,6 +3,7 @@ import { Notif, NotifElemType, NotifEventVisibility } from "../entities/Notifica import { time } from "../utils/DateUtils"; import { PostsHelper } from "./PostsHelper"; import { PostPageKind, PostVisibilityLevel } from "../entities/Post"; +import { FriendsHelper } from "./FriendsHelper"; /** * Notifications helper @@ -47,6 +48,7 @@ export class NotificationsHelper { // Check the scope of the notification + // Private post (on user pages) if(post.visibilityLevel == PostVisibilityLevel.VISIBILITY_USER) { // Check if the user does not own the post @@ -64,10 +66,57 @@ export class NotificationsHelper { await this.PushPrivate(n) } + // Posts on users page + else if(n.fromContainerType == NotifElemType.USER_PAGE) { + + // Process friends list of the user creating the notification + const friendsList = await FriendsHelper.GetList(n.fromUserID); + const targetUsers = []; + + for(const friend of friendsList) { + if(friend.friendID != n.fromContainerID && + post.userPageID != n.fromUserID && // Skip friendship check if user + // creating the notification + // & target page are the same + !await FriendsHelper.AreFriend(friend.friendID, post.userPageID)) + continue; + + // Check if the user is following his friend + if(!await FriendsHelper.IsFollowing(friend.friendID, n.fromUserID)) + continue; + + targetUsers.push(friend.friendID) + } + + await this.PushPublic(n, targetUsers); + + } + // TODO : continue } } + /** + * Push a notification to multiple users + * + * @param n The notification to push + * @param users The list of target users + */ + private static async PushPublic(n: Notif, users: Array) { + n.eventVisibility = NotifEventVisibility.EVENT_PUBLIC + + for(const userID of users) { + + n.destUserID = userID; + + if(await this.SimilarExists(n)) + continue + + await this.Create(n); + + } + } + /** * Push a private notification *