Chat Notifications Implementation Proposal #446
AndreaDiazCorreia
started this conversation in
Ideas
Replies: 1 comment
-
|
I agree with the ideas, they seem good to me. Regarding the questions, I think it would be good to start by just putting the notification: "You have a new message", and then it can be improved to show the sender and the content. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Push and background notifications currently only work for Mostro-originated events (order updates, timeout detection, cancellations). Chat messages between users (P2P) and between users and admins (disputes) do not generate any notifications — not in background, not in foreground (outside the chat screen), and not via FCM when the app is killed.
Current Architecture
How notifications work today
Three message types and their encryption
ptagtradeKey.publicmostroUnWrap(tradeKey)[{action, id, payload}]sharedKey.publicp2pUnwrap(sharedKey)tradeKey.publicmostroUnWrap(tradeKey){dm: {action: "send-dm", payload: {text_message}}}What fails and why
P2P Chat
SubscriptionType.chatfilters withsharedKey.publicare transferred to background servicep=sharedKey.publicmatches the subscription filter_decryptAndProcessEvent()matches sessions bytradeKey.public == event.recipient— never matchessharedKey.publicMostroMessageJSON array format, not plain texttradeKeyregistered, doesn't know aboutsharedKeyChatRoomNotifierwhen that screen is openAdmin/Dispute Chat
SubscriptionType.ordersfilter (sametradeKey.public)p=tradeKey.publicmatches the orders subscriptionmostroUnWrap(tradeKey)works (same path as Mostro events)MostroMessagewith standard actions, but receives{dm: {...}}formattradeKey— admin events matchDisputeChatNotifierwhen dispute screen is openKey Finding: Shared Keys Are Available in Background
The background notification service loads sessions via
_loadSessionsFromDatabase(), which:KeyManagerfrom secure storagetradeKeyfrommasterKey+keyIndexpeer.publicKeyfrom stored session datasession.peerautomatically computessharedKey = ECDH(tradeKey.private, peer.publicKey)Therefore,
sharedKeycan be recomputed in the background isolate. This is not a blocker.Proposed Implementation
Layer 1: Background Notifications (app minimized)
Modify
_decryptAndProcessEvent()inbackground_notification_service.dartto handle all three message types:Notification display:
Files to modify
lib/features/notifications/services/background_notification_service.dart— add sharedKey matching + p2pUnwrap path + DM format detectionlib/features/notifications/utils/notification_data_extractor.dart— add chat message extraction (P2P and admin DM)lib/features/notifications/utils/notification_message_mapper.dart— add/verify chat notification templateslib/l10n/intl_*.arb— add localization keys if neededLayer 2: In-App Notifications (foreground, outside chat screen)
When the user is in the app but not viewing the specific chat screen, show a toast/badge notification.
Approach: In the
SubscriptionManagerevent processing, when a chat event arrives:ChatRoomNotifierfor that order is activeNotificationsNotifierThis avoids duplicate processing and leverages the existing temporary notification system (
showTemporary()).Files to modify
lib/features/subscriptions/subscription_manager.dart— add chat event notification logiclib/features/notifications/notifiers/notifications_notifier.dart— may need new methods for chat notificationsLayer 3: Push/FCM (app killed or suspended)
P2P Chat: Sender-triggered notification
When User A sends a chat message to User B:
POST /api/notify {trade_pubkey: peer.publicKey}(NEW)This works because:
session.peer.publicKey(the counterparty's trade pubkey)tradeKey → FCM tokenmappingWhy this is better than registering sharedKey:
Admin/Dispute Chat: Already works
Admin events already use
tradeKey.publicas theptag. Since the push server monitors relays for registered trade pubkeys, these events should already trigger FCM wake-ups. The only gap is Layer 1 (background notification processing), which is addressed above.Push server changes needed
New endpoint:
Response:
200 OK(notification queued) or404(pubkey not registered)This endpoint simply sends a silent FCM notification to the device registered for that trade pubkey. No content, no metadata beyond what the server already has.
Files to modify
lib/services/push_notification_service.dart— addnotifyPeer(String tradePubkey)methodlib/features/chat/notifiers/chat_room_notifier.dart— callnotifyPeer()after publishing messagelib/features/disputes/notifiers/dispute_chat_notifier.dart— callnotifyPeer()after publishing message (if admin push isn't already handled by relay monitoring)/api/notifyendpointImplementation Order
Layer 1 (Background) — Highest impact. Users already have the app minimized during trades. Subscriptions and events already work; only the notification processing pipeline needs changes.
Layer 2 (In-app) — Medium impact. Improves UX when navigating away from chat during an active trade.
Layer 3 (Push/FCM) — Requires server-side changes. Important for when the app is completely killed, but Layer 1 covers the common "app minimized" case.
Privacy Considerations
tradeKey → device tokenmapping (already existing)/api/notifyendpoint doesn't reveal sender identity to the push serverOpen Questions
/api/notifyendpoint have rate limiting to prevent abuse?/api/notify?Beta Was this translation helpful? Give feedback.
All reactions