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

First public notification

This commit is contained in:
Pierre HUBERT 2020-03-24 08:31:29 +01:00
parent a40812f751
commit 7ab3682df8

View File

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