Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy to EC2
on:
push:
branches:
- notif-bugs
- notif-update
- prod
paths:
- 'backend/**'
Expand Down
32 changes: 31 additions & 1 deletion backend/src/controllers/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -503,6 +503,36 @@ async selectActivity(req: Request, res: Response): Promise<void> {
// 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,
Expand Down
18 changes: 18 additions & 0 deletions backend/src/services/fcm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down