diff --git a/src/internal/rest/group.go b/src/internal/rest/group.go index 5cfd369..321d2a8 100644 --- a/src/internal/rest/group.go +++ b/src/internal/rest/group.go @@ -23,9 +23,9 @@ func InitRestGroup(app *fiber.App, service domainGroup.IGroupService) Group { app.Post("/group/participants/remove", rest.DeleteParticipants) app.Post("/group/participants/promote", rest.PromoteParticipants) app.Post("/group/participants/demote", rest.DemoteParticipants) - app.Get("/group/participants/requested", rest.RequestedParticipants) - app.Post("/group/participants/requested/approve", rest.ApproveRequestedParticipants) - app.Post("/group/participants/requested/reject", rest.RejectRequestedParticipants) + app.Get("/group/participant-requests", rest.ListParticipantRequests) + app.Post("/group/participant-requests/approve", rest.ApproveParticipantRequests) + app.Post("/group/participant-requests/reject", rest.RejectParticipantRequests) return rest } @@ -97,7 +97,7 @@ func (controller *Group) DemoteParticipants(c *fiber.Ctx) error { return controller.manageParticipants(c, whatsmeow.ParticipantChangeDemote, "Success demote participants") } -func (controller *Group) RequestedParticipants(c *fiber.Ctx) error { +func (controller *Group) ListParticipantRequests(c *fiber.Ctx) error { var request domainGroup.GetGroupRequestParticipantsRequest err := c.QueryParser(&request) utils.PanicIfNeeded(err) @@ -115,11 +115,11 @@ func (controller *Group) RequestedParticipants(c *fiber.Ctx) error { }) } -func (controller *Group) ApproveRequestedParticipants(c *fiber.Ctx) error { +func (controller *Group) ApproveParticipantRequests(c *fiber.Ctx) error { return controller.handleRequestedParticipants(c, whatsmeow.ParticipantChangeApprove, "Success approve requested participants") } -func (controller *Group) RejectRequestedParticipants(c *fiber.Ctx) error { +func (controller *Group) RejectParticipantRequests(c *fiber.Ctx) error { return controller.handleRequestedParticipants(c, whatsmeow.ParticipantChangeReject, "Success reject requested participants") } diff --git a/src/views/components/GroupList.js b/src/views/components/GroupList.js index 615a211..3fe44c2 100644 --- a/src/views/components/GroupList.js +++ b/src/views/components/GroupList.js @@ -90,7 +90,7 @@ export default { this.requestedMembers = []; try { - const response = await window.http.get(`/group/participants/requested?group_id=${group_id}`); + const response = await window.http.get(`/group/participant-requests?group_id=${group_id}`); this.requestedMembers = response.data.results || []; this.loadingRequestedMembers = false; $('#modalRequestedMembers').modal('show'); @@ -111,56 +111,32 @@ export default { // open modal again this.openModal(); }, - async handleApproveRequest(member) { + async handleProcessRequest(member, action) { if (!this.selectedGroupId || !member) return; - - try { - this.processingMember = member.jid; - - const payload = { - group_id: this.selectedGroupId, - participants: [this.formatJID(member.jid)] - }; - - await window.http.post('/group/participants/requested/approve', payload); - - // Remove the approved member from the list - this.requestedMembers = this.requestedMembers.filter(m => m.jid !== member.jid); - - showSuccessInfo("Member request approved"); - this.processingMember = null; - - } catch (error) { - this.processingMember = null; - let errorMessage = "Failed to approve member request"; - if (error.response) { - errorMessage = error.response.data.message || errorMessage; - } - showErrorInfo(errorMessage); - } - }, - async handleRejectRequest(member) { - if (!this.selectedGroupId || !member) return; - + + const actionText = action === 'approve' ? 'approve' : 'reject'; + const confirmMsg = `Are you sure you want to ${actionText} this member request?`; + const ok = confirm(confirmMsg); + if (!ok) return; + try { this.processingMember = member.jid; - + const payload = { group_id: this.selectedGroupId, participants: [this.formatJID(member.jid)] }; - - await window.http.post('/group/participants/requested/reject', payload); - - // Remove the rejected member from the list + + await window.http.post(`/group/participant-requests/${action}`, payload); + + // Remove the processed member from the list this.requestedMembers = this.requestedMembers.filter(m => m.jid !== member.jid); - - showSuccessInfo("Member request rejected"); + + showSuccessInfo(`Member request ${actionText}d`); this.processingMember = null; - } catch (error) { this.processingMember = null; - let errorMessage = "Failed to reject member request"; + let errorMessage = `Failed to ${actionText} member request`; if (error.response) { errorMessage = error.response.data.message || errorMessage; } @@ -243,14 +219,14 @@ export default {