From 452b7aa186ae567ddb1dd3b08007a2723e08a959 Mon Sep 17 00:00:00 2001 From: Anu Date: Sat, 1 Nov 2025 16:27:17 -0700 Subject: [PATCH] notif update test --- .github/workflows/deploy.yml | 2 +- backend/src/controllers/group.controller.ts | 32 +++++++++++++++++- backend/src/services/fcm.service.ts | 18 ++++++++++ .../ui/notifications/NotificationManager.kt | 33 ++++++++++++++----- 4 files changed, 75 insertions(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 52001c6..4ff0ac3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Deploy to EC2 on: push: branches: - - notif-bugs + - notif-update - prod paths: - 'backend/**' diff --git a/backend/src/controllers/group.controller.ts b/backend/src/controllers/group.controller.ts index 273861a..089329b 100644 --- a/backend/src/controllers/group.controller.ts +++ b/backend/src/controllers/group.controller.ts @@ -9,7 +9,7 @@ import { GetGroupResponse, UpdateGroupRequest, CreateGroupRequest, GetAllGroupsR import { getWebSocketService } from '../services/websocket.service'; import { locationService } from '../services/location.service'; import { GeoLocation, getLocationResponse, LocationInfo } from '../types/location.types'; -import { sendGroupJoinFCM, sendGroupLeaveFCM } from '../services/fcm.service'; +import { sendGroupJoinFCM, sendGroupLeaveFCM, sendActivitySelectedFCM } from '../services/fcm.service'; export class GroupController { async createGroup( @@ -503,6 +503,36 @@ async selectActivity(req: Request, res: Response): Promise { // Update the group with the selected activity const updatedGroup = await groupModel.updateSelectedActivity(joinCode, activity); + // Send notifications to group members + const wsService = getWebSocketService(); + if (wsService && updatedGroup) { + const leaderId = updatedGroup.groupLeaderId?.id || ''; + const leaderName = updatedGroup.groupLeaderId?.name || 'Group leader'; + const activityName = activity.name || 'an activity'; + + // Send WebSocket notification + wsService.notifyGroupUpdate( + joinCode, + `${leaderName} selected "${activityName}" for the group`, + { + type: 'activity_selected', + activity: activity, + leaderId: leaderId, + leaderName: leaderName + } + ); + + // Send FCM notification (will be suppressed in foreground on client side) + const activityDataStr = JSON.stringify(activity); + void sendActivitySelectedFCM( + joinCode, + activityName, + updatedGroup.groupName, + leaderId, + activityDataStr + ); + } + res.status(200).json({ message: 'Activity selected successfully', data: updatedGroup, diff --git a/backend/src/services/fcm.service.ts b/backend/src/services/fcm.service.ts index 61c8442..084bce7 100644 --- a/backend/src/services/fcm.service.ts +++ b/backend/src/services/fcm.service.ts @@ -98,4 +98,22 @@ export async function sendGroupLeaveFCM(joinCode: string, userName: string, grou actingUserId, // new field for filtering on frontend }, }); +} + +export async function sendActivitySelectedFCM(joinCode: string, activityName: string, groupName: string, leaderId: string, activityData?: string) { + const title = 'Activity Selected'; + const body = `Group leader selected "${activityName}" for the group "${groupName}"`; + return sendToTopic(joinCode, { + title, + body, + data: { + type: 'activity_selected', + joinCode, + activityName, + groupName, + timestamp: new Date().toISOString(), + actingUserId: leaderId, // new field for filtering on frontend + activityData: activityData || '', // Optional activity data as JSON string + }, + }); } \ No newline at end of file diff --git a/frontend/app/src/main/java/com/cpen321/squadup/ui/notifications/NotificationManager.kt b/frontend/app/src/main/java/com/cpen321/squadup/ui/notifications/NotificationManager.kt index 7f6390d..7c3b1e2 100644 --- a/frontend/app/src/main/java/com/cpen321/squadup/ui/notifications/NotificationManager.kt +++ b/frontend/app/src/main/java/com/cpen321/squadup/ui/notifications/NotificationManager.kt @@ -60,14 +60,31 @@ class NotificationManager @Inject constructor() { showNotification(notification) } "group_update" -> { - val notification = AppNotification( - id = System.currentTimeMillis().toString(), - title = "Group Update", - message = messageText, - type = type, - timestamp = timestamp - ) - showNotification(notification) + // Check if this is an activity_selected update + val dataObj = json.optJSONObject("data") + val updateType = dataObj?.optString("type", "") + + if (updateType == "activity_selected") { + val activityObj = dataObj.optJSONObject("activity") + val activityName = activityObj?.optString("name", "an activity") ?: "an activity" + val notification = AppNotification( + id = System.currentTimeMillis().toString(), + title = "Activity Selected", + message = "Group leader selected \"$activityName\"", + type = "activity_selected", + timestamp = timestamp + ) + showNotification(notification) + } else { + val notification = AppNotification( + id = System.currentTimeMillis().toString(), + title = "Group Update", + message = messageText, + type = type, + timestamp = timestamp + ) + showNotification(notification) + } } "notification" -> { val notification = AppNotification(