mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-10-30 17:14:43 +00:00 
			
		
		
		
	Can invite a user to join a group
This commit is contained in:
		| @@ -289,6 +289,25 @@ export class GroupsController { | ||||
| 		h.send(members.map((m) => this.GroupMemberToAPI(m))); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Invite a user to join the network | ||||
| 	 *  | ||||
| 	 * @param h Request handler | ||||
| 	 */ | ||||
| 	public static async InviteUser(h: RequestHandler) { | ||||
| 		const groupID = await h.postGroupIDWithAccess("group_id", GroupsAccessLevel.MODERATOR_ACCESS); | ||||
| 		const userID = await h.postUserId("userID"); | ||||
|  | ||||
| 		if(!await GroupsHelper.GetMembershipLevel(groupID, userID)) | ||||
| 			h.error(401, "The user is not a visitor of the group!"); | ||||
| 		 | ||||
| 		await GroupsHelper.SendInvitation(groupID, userID); | ||||
|  | ||||
| 		// TODO : Create a notification | ||||
|  | ||||
| 		h.success("The user has been successfully invited to join the group!"); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Turn a GroupInfo object into a valid API object | ||||
| 	 *  | ||||
|   | ||||
| @@ -106,4 +106,6 @@ export const Routes : Route[] = [ | ||||
| 	{path: "/groups/delete_logo", cb: (h) => GroupsController.DeleteLogo(h)}, | ||||
|  | ||||
| 	{path: "/groups/get_members", cb: (h) => GroupsController.GetMembers(h)}, | ||||
|  | ||||
| 	{path: "/groups/invite", cb: (h) => GroupsController.InviteUser(h)}, | ||||
| ] | ||||
| @@ -158,6 +158,23 @@ export class GroupsHelper { | ||||
| 		return result.visibility; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Invite a user to join a group | ||||
| 	 *  | ||||
| 	 * @param groupID The ID of the target group | ||||
| 	 * @param userID The ID of the target user | ||||
| 	 */ | ||||
| 	public static async SendInvitation(groupID: number, userID: number) { | ||||
| 		await this.InsertMember(new GroupMember({ | ||||
| 			id: -1, | ||||
| 			userID: userID, | ||||
| 			groupID: groupID, | ||||
| 			timeCreate: time(), | ||||
| 			following: true, | ||||
| 			level: GroupMembershipLevels.INVITED | ||||
| 		})); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Insert a new group member | ||||
| 	 *  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user