From 8efcec6283d43efe40bd8081ca1f7ec6e29d90d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Kub=C3=ADk?= Date: Sat, 19 Nov 2022 21:52:26 +0100 Subject: [PATCH] feat(presence): send presence events for own users unreliably --- src/service/sending/mod.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/service/sending/mod.rs b/src/service/sending/mod.rs index afa12fc7..3de704a8 100644 --- a/src/service/sending/mod.rs +++ b/src/service/sending/mod.rs @@ -24,7 +24,7 @@ use ruma::{ federation::{ self, transactions::edu::{ - DeviceListUpdateContent, Edu, ReceiptContent, ReceiptData, ReceiptMap, + DeviceListUpdateContent, Edu, ReceiptContent, ReceiptData, ReceiptMap, PresenceUpdate, PresenceContent, }, }, OutgoingRequest, @@ -283,6 +283,31 @@ impl Service { .filter(|user_id| user_id.server_name() == services().globals.server_name()), ); + // Look for presence updates in this room + let presence_updates: Vec = services() + .rooms + .edus + .presence + .presence_since(&room_id, since)? + .filter(|(user_id, _)| user_id.server_name() == services().globals.server_name()) + .map(|(user_id, presence_event)| PresenceUpdate { + user_id, + presence: presence_event.content.presence, + status_msg: presence_event.content.status_msg, + last_active_ago: presence_event.content.last_active_ago.unwrap_or(uint!(0)), + currently_active: presence_event.content.currently_active.unwrap_or(false), + }) + .collect(); + + let presence_content = PresenceContent { + push: presence_updates, + }; + + events.push( + serde_json::to_vec(&Edu::Presence(presence_content)) + .expect("presence json can be serialized"), + ); + // Look for read receipts in this room for r in services() .rooms