Skip to content

Commit bfce725

Browse files
committed
feat: enhance pending session notifications with user lookup and logging
1 parent 04466a1 commit bfce725

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

sql_models/seed.sql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,13 @@ CREATE OR REPLACE FUNCTION notify_new_pending_session() RETURNS trigger AS $$
277277
DECLARE
278278
recipient_user UUID;
279279
BEGIN
280-
SELECT user_id INTO recipient_user
281-
FROM devices
282-
WHERE id = NEW.recipient_device_id;
280+
SELECT u.id INTO recipient_user
281+
FROM users u
282+
JOIN devices d ON d.user_id = u.id
283+
WHERE d.id = NEW.recipient_device_id;
284+
285+
RAISE NOTICE 'Trigger fired: sender_device=%, recipient_device=%, found_user=%',
286+
NEW.sender_device_id, NEW.recipient_device_id, recipient_user;
283287

284288
IF recipient_user IS NOT NULL THEN
285289
PERFORM pg_notify(
@@ -293,12 +297,16 @@ BEGIN
293297
'created_at', NEW.created_at
294298
)::text
295299
);
300+
RAISE NOTICE 'Notification sent to user_id=%', recipient_user;
301+
ELSE
302+
RAISE NOTICE 'No recipient_user found for device_id=%', NEW.recipient_device_id;
296303
END IF;
297304

298305
RETURN NEW;
299306
END;
300307
$$ LANGUAGE plpgsql;
301308

309+
302310
DROP TRIGGER IF EXISTS pending_sessions_notify_trigger ON pending_sessions;
303311
CREATE TRIGGER pending_sessions_notify_trigger
304312
AFTER INSERT ON pending_sessions

src/realtime/listener.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub async fn start_pg_listeners(pool: PgPool, tx: broadcast::Sender<RealtimeEven
99
listener.listen_all(vec![
1010
"messages_channel",
1111
"sessions_channel",
12+
"pending_sessions_channel",
1213
"devices_channel",
1314
]).await.unwrap();
1415

0 commit comments

Comments
 (0)