diff --git a/src/controllers/GroupsController.ts b/src/controllers/GroupsController.ts index 1b4c765..c19b236 100644 --- a/src/controllers/GroupsController.ts +++ b/src/controllers/GroupsController.ts @@ -537,6 +537,21 @@ export class GroupsController { h.success("Your membership has been successfully deleted!"); } + + /** + * Update the following status of a user + * + * @param h Request handler + */ + public static async SetFollowing(h: RequestHandler) { + const groupID = await h.postGroupIDWithAccess("groupID", GroupsAccessLevel.MEMBER_ACCESS); + const following = h.postBool("follow"); + + await GroupsHelper.SetFollowing(groupID, h.getUserId(), following); + + h.success("Follow status has been successfully updated!"); + } + /** * Turn a GroupInfo object into a valid API object * diff --git a/src/controllers/Routes.ts b/src/controllers/Routes.ts index dd7bd21..e028adc 100644 --- a/src/controllers/Routes.ts +++ b/src/controllers/Routes.ts @@ -126,4 +126,6 @@ export const Routes : Route[] = [ {path: "/groups/cancel_invitation", cb: (h) => GroupsController.CancelInvitation(h)}, {path: "/groups/remove_membership", cb: (h) => GroupsController.RemoveMembership(h)}, + + {path: "/groups/set_following", cb: (h) => GroupsController.SetFollowing(h)}, ] \ No newline at end of file diff --git a/src/helpers/GroupsHelper.ts b/src/helpers/GroupsHelper.ts index 253cfc4..20ad189 100644 --- a/src/helpers/GroupsHelper.ts +++ b/src/helpers/GroupsHelper.ts @@ -254,6 +254,26 @@ export class GroupsHelper { }); } + /** + * Update following status of a user + * + * @param groupID Target group ID + * @param userID Target user ID + * @param follow true to follow / false else + */ + public static async SetFollowing(groupID: number, userID: number, follow: boolean) { + await DatabaseHelper.UpdateRows({ + table: GROUPS_MEMBERS_TABLE, + where: { + groups_id: groupID, + user_id: userID + }, + set: { + following: follow ? 1 : 0 + } + }); + } + /** * Delete completely a user membership *