Add typing indicators to sync v5.

Co-authored-by: Jade Ellis <jade@ellis.link>
This commit is contained in:
Tyler Mayoff
2025-07-07 20:15:58 -04:00
committed by Jason Volk
parent f7877d122b
commit 9ea8fbc482
3 changed files with 62 additions and 9 deletions

View File

@@ -189,17 +189,15 @@ impl Service {
}
/// Returns a new typing EDU.
pub async fn typings_all(
pub async fn typing_users_for_user(
&self,
room_id: &RoomId,
sender_user: &UserId,
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {
) -> Result<Vec<OwnedUserId>> {
let room_typing_indicators = self.typing.read().await.get(room_id).cloned();
let Some(typing_indicators) = room_typing_indicators else {
return Ok(SyncEphemeralRoomEvent {
content: ruma::events::typing::TypingEventContent { user_ids: Vec::new() },
});
return Ok(Vec::new());
};
let user_ids: Vec<_> = typing_indicators
@@ -216,8 +214,20 @@ impl Service {
.collect()
.await;
Ok(user_ids)
}
pub async fn typings_event_for_user(
&self,
room_id: &RoomId,
sender_user: &UserId,
) -> Result<SyncEphemeralRoomEvent<ruma::events::typing::TypingEventContent>> {
Ok(SyncEphemeralRoomEvent {
content: ruma::events::typing::TypingEventContent { user_ids },
content: ruma::events::typing::TypingEventContent {
user_ids: self
.typing_users_for_user(room_id, sender_user)
.await?,
},
})
}