mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	First public notification
This commit is contained in:
		@@ -3,6 +3,7 @@ import { Notif, NotifElemType, NotifEventVisibility } from "../entities/Notifica
 | 
				
			|||||||
import { time } from "../utils/DateUtils";
 | 
					import { time } from "../utils/DateUtils";
 | 
				
			||||||
import { PostsHelper } from "./PostsHelper";
 | 
					import { PostsHelper } from "./PostsHelper";
 | 
				
			||||||
import { PostPageKind, PostVisibilityLevel } from "../entities/Post";
 | 
					import { PostPageKind, PostVisibilityLevel } from "../entities/Post";
 | 
				
			||||||
 | 
					import { FriendsHelper } from "./FriendsHelper";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * Notifications helper
 | 
					 * Notifications helper
 | 
				
			||||||
@@ -47,6 +48,7 @@ export class NotificationsHelper {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Check the scope of the notification
 | 
								// Check the scope of the notification
 | 
				
			||||||
 | 
								// Private post (on user pages)
 | 
				
			||||||
			if(post.visibilityLevel == PostVisibilityLevel.VISIBILITY_USER) {
 | 
								if(post.visibilityLevel == PostVisibilityLevel.VISIBILITY_USER) {
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				// Check if the user does not own the post
 | 
									// Check if the user does not own the post
 | 
				
			||||||
@@ -64,10 +66,57 @@ export class NotificationsHelper {
 | 
				
			|||||||
				await this.PushPrivate(n)
 | 
									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
 | 
								// 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
 | 
						 * Push a private notification
 | 
				
			||||||
	 * 
 | 
						 * 
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user