A platform for community discussion. Free, open, simple.
Smart Notifications
Overview
Alert users when their frequent live contacts join rooms. Uses co-presence
data from the analytics system (see analytics.md) to determine relationship
strength.
Prerequisites
- Session tracking (analytics Phase 1) —
live_sessionstable. - Co-presence tracking (analytics Phase 2) —
live_co_presencestable.
"Your frequent contact joined a room"
Trigger: A user joins a room.
Logic (in RoomsController#join, after recording the session):
- Query the joining user's top contacts from
live_co_presences(cached — see below). - For each top contact who is currently online (Discourse presence) but NOT
in any live room:
- Check if the room the user just joined is one the contact frequents
(from
live_sessionsaggregation, also cached). - If both conditions met (strong relationship + familiar room), send a notification.
- Check if the room the user just joined is one the contact frequents
(from
Notification content:
"Alice joined Watercooler — you two have chatted 12 times this month"
Delivery: Discourse MessageBus push to the contact's browser → rendered as a toast notification with a "Join" action button.
Caching strategy
Computing top contacts and frequent rooms on every join would be expensive.
- Top contacts per user: Cache in Redis as a sorted set
live:contacts:{user_id}with score = aggregatedtotal_secondsover the last 30 days. Refresh every hour via a scheduled job, or invalidate whenUpdateCoPresenceruns. - Frequent rooms per user: Cache as
live:frequent_rooms:{user_id}. Refresh daily or on session close. - Notification cooldown: Don't notify the same user about the same contact
more than once per hour. Track in Redis:
live:notified:{user_id}:{contact_id}with 1h TTL.
Thresholds
Not every co-presence should trigger notifications. Minimum thresholds:
- Minimum co-presence time: 30 minutes total within the lookback window (avoids noise from one-time encounters).
- Minimum sessions: 3 within the lookback window (avoids a single long session skewing results).
- Recency lookback window: 30 days (only co-presence rows with
date >= today - 30 daysare considered — stale relationships naturally drop out). - Room familiarity: Contact has visited the room at least twice in the last 30 days (don't notify about unfamiliar rooms).
All thresholds configurable via site settings.
Site settings
live_smart_notifications_enabled:
default: true
live_co_presence_min_seconds:
default: 1800
description: "Minimum co-presence time (seconds) before a relationship is considered for notifications"
live_co_presence_min_sessions:
default: 3
live_smart_notification_cooldown_minutes:
default: 60
min: 10
max: 1440
User preferences
Users can control notification behavior from their Discourse notification preferences (or a Live-specific section):
- Enable/disable smart room notifications (default: enabled).
- Quiet hours — respect Discourse's existing Do Not Disturb setting.
No per-contact granularity in the first version — either on or off globally.
Implementation plan
- Implement notification logic in room join flow.
- Add Redis caching for contacts and frequent rooms.
- Add notification cooldown.
- Add user preference toggle.
- Frontend toast with "Join" action button.
Privacy considerations
- Smart notifications respect Discourse's existing block/ignore system — if user A has blocked user B, no notifications are sent in either direction.
- Co-presence data is symmetric — if Alice can see Bob as a top contact, Bob can see Alice. There is no way to silently track someone.