mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-31 17:44:03 +00:00 
			
		
		
		
	Can create groups membership notifications (moderator > user)
This commit is contained in:
		| @@ -8,6 +8,8 @@ import { GroupSettings } from "../entities/GroupSettings"; | ||||
| import { removeHTMLNodes, checkURL } from "../utils/StringUtils"; | ||||
| import { findKey } from "../utils/ArrayUtils"; | ||||
| import { checkVirtualDirectoryAvailability, VirtualDirType } from "../utils/VirtualDirsUtils"; | ||||
| import { NotificationsUtils } from "../utils/NotificationsUtils"; | ||||
| import { NotifEventType } from "../entities/Notification"; | ||||
|  | ||||
| /** | ||||
|  * Groups API controller | ||||
| @@ -303,7 +305,9 @@ export class GroupsController { | ||||
| 		 | ||||
| 		await GroupsHelper.SendInvitation(groupID, userID); | ||||
|  | ||||
| 		// TODO : Create a notification | ||||
| 		// Create a notification | ||||
| 		await NotificationsUtils.CreateGroupMembershipNotification( | ||||
| 			userID, h.getUserId(), groupID, NotifEventType.SENT_GROUP_MEMBERSHIP_INVITATION) | ||||
|  | ||||
| 		h.success("The user has been successfully invited to join the group!"); | ||||
| 	} | ||||
|   | ||||
| @@ -51,7 +51,7 @@ export interface NotifBuilder { | ||||
| 	id ?: number, | ||||
| 	timeCreate ?: number, | ||||
| 	seen ?: boolean, | ||||
| 	fromUserID: number, | ||||
| 	fromUserID ?: number, | ||||
| 	destUserID ?: number, | ||||
| 	onElemID ?: number, | ||||
| 	onElemType: NotifElemType, | ||||
| @@ -65,7 +65,7 @@ export class Notif implements NotifBuilder { | ||||
| 	id ?: number; | ||||
| 	timeCreate ?: number; | ||||
| 	seen ?: boolean; | ||||
| 	fromUserID: number; | ||||
| 	fromUserID ?: number; | ||||
| 	destUserID ?: number; | ||||
| 	onElemID ?: number; | ||||
| 	onElemType: NotifElemType; | ||||
|   | ||||
| @@ -113,7 +113,30 @@ export class NotificationsHelper { | ||||
| 		} | ||||
|  | ||||
|  | ||||
| 		// TODO : continue | ||||
| 		// Groups membership notifications | ||||
| 		else if (n.onElemType == NotifElemType.GROUP_MEMBERSHIP) { | ||||
|  | ||||
| 			// Complete the notification | ||||
| 			n.fromContainerType = NotifElemType.EMPTY; | ||||
| 			n.fromContainerID = 0; | ||||
|  | ||||
| 			// Check whether the notification has to be pushed to a single user | ||||
| 			// or to all the moderators of the group | ||||
| 			if(n.hasDestUserID) { | ||||
|  | ||||
| 				//Push the notification in private way (if it has a destination, | ||||
| 				//generally the target user of the membership request) | ||||
| 				await this.PushPrivate(n); | ||||
|  | ||||
| 			} | ||||
|  | ||||
| 			else { | ||||
|  | ||||
| 				// Push the notification to all the moderators of the group | ||||
| 				throw new Error("//TODO Push notification to all members of the group"); | ||||
|  | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		// Unsupported notification type | ||||
| 		else { | ||||
|   | ||||
| @@ -70,4 +70,38 @@ export class NotificationsUtils { | ||||
| 			fromUserID: userOne, | ||||
| 		})); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Create & push a group membership notification | ||||
| 	 *  | ||||
| 	 * @param userID The ID of the target user for the membership | ||||
| 	 * @param moderatorID The ID of the moderator creating the notification (0 if it is the user) | ||||
| 	 * @param groupID The ID of the target group | ||||
| 	 * @param kind The kind of notification to create | ||||
| 	 */ | ||||
| 	public static async CreateGroupMembershipNotification(userID: number, moderatorID: number, groupID: number, kind: NotifEventType) { | ||||
| 		// TODO : Delete all previous notifications | ||||
|  | ||||
| 		const n = new Notif({ | ||||
| 			onElemID: groupID, | ||||
| 			onElemType: NotifElemType.GROUP_MEMBERSHIP, | ||||
| 			type: kind | ||||
| 		}); | ||||
|  | ||||
|  | ||||
| 		// The notification must be sent to all the moderators of the group | ||||
| 		if(moderatorID < 1) { | ||||
| 			n.fromUserID = userID; | ||||
| 			n.destUserID = -1; | ||||
| 		} | ||||
|  | ||||
| 		// We specify both the source and the destination of the notification | ||||
| 		// not to broadcast the notification to all the group members | ||||
| 		else { | ||||
| 			n.fromUserID = moderatorID; | ||||
| 			n.destUserID = userID; | ||||
| 		} | ||||
|  | ||||
| 		await NotificationsHelper.Push(n); | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user