Group Android notifications by space and clear them on read.
All checks were successful
Build / increment-version (push) Successful in 5s
Build / build-android (push) Successful in 4m52s

Use stable per-room notification IDs with Directs/Spaces/Home channels and space group summaries so the shade nests deeper than a flat Messages list, and dismiss those tray entries when a room is marked read.
This commit is contained in:
2026-07-24 14:36:06 +10:00
parent 60edb063dd
commit 45bc475340
5 changed files with 671 additions and 59 deletions

View File

@@ -10,6 +10,10 @@ type UnifiedPushStatus = {
distributors: string[] | string;
};
type ClearRoomNotificationsResult = {
cleared: boolean;
};
type UnifiedPushEndpointEvent = {
endpoint: string;
previousEndpoint: string;
@@ -48,6 +52,18 @@ interface MatrixBackgroundSyncPlugin {
setAppForeground(options: { foreground: boolean }): Promise<void>;
/** Returns fetch state and current UnifiedPush registration details. */
getStatus(): Promise<UnifiedPushStatus>;
/** Cancel native tray notifications posted for a Matrix room. */
clearRoomNotifications(options: { roomId: string }): Promise<ClearRoomNotificationsResult>;
/**
* Persist room → space/group metadata so background notifications can nest
* under Direct messages / Space name / Home.
*/
setNotificationGroups(options: {
rooms: Record<
string,
{ groupId: string; groupName: string; roomName: string; kind: string }
>;
}): Promise<{ success: boolean }>;
addListener(
eventName: 'unifiedPushNewEndpoint',
listenerFunc: (event: UnifiedPushEndpointEvent) => void
@@ -516,3 +532,35 @@ export const getBackgroundSyncStatus = async (): Promise<UnifiedPushStatus | und
return undefined;
}
};
/**
* Clears native (MatrixSyncService) tray notifications for a room after it is read.
* No-op when background sync / native Android is unavailable.
*/
export const clearNativeRoomNotifications = async (roomId: string): Promise<void> => {
if (!isBackgroundSyncSupported() || !roomId) return;
try {
await MatrixBackgroundSync.clearRoomNotifications({ roomId });
} catch (err) {
console.warn('[BackgroundSync] clearRoomNotifications failed:', err);
}
};
/**
* Syncs space/DM grouping metadata to the native layer for background notifications.
*/
export const syncNotificationGroupMap = async (
rooms: Record<
string,
{ groupId: string; groupName: string; roomName: string; kind: string }
>
): Promise<void> => {
if (!isBackgroundSyncSupported()) return;
try {
await MatrixBackgroundSync.setNotificationGroups({ rooms });
} catch (err) {
console.warn('[BackgroundSync] setNotificationGroups failed:', err);
}
};