Propagate read receipt events
This commit is contained in:
@@ -29,6 +29,19 @@ pub struct WsRoomEvent<E> {
|
||||
pub data: Box<E>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct WsReceiptEntry {
|
||||
event: OwnedEventId,
|
||||
user: OwnedUserId,
|
||||
ts: Option<MilliSecondsSinceUnixEpoch>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct WsReceiptEvent {
|
||||
pub room_id: OwnedRoomId,
|
||||
pub receipts: Vec<WsReceiptEntry>,
|
||||
}
|
||||
|
||||
/// Messages sent to the client
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
@@ -41,6 +54,9 @@ pub enum WsMessage {
|
||||
|
||||
/// Room reaction event
|
||||
RoomRedactionEvent(WsRoomEvent<RoomRedactionEventContent>),
|
||||
|
||||
/// Fully read message event
|
||||
ReceiptEvent(WsReceiptEvent),
|
||||
}
|
||||
|
||||
impl WsMessage {
|
||||
@@ -73,6 +89,25 @@ impl WsMessage {
|
||||
data: Box::new(evt.data.content.clone()),
|
||||
}))
|
||||
}
|
||||
BroadcastMessage::ReceiptEvent(evt) if &evt.user == user => {
|
||||
let mut receipts = vec![];
|
||||
for (event_id, r) in &evt.data.content.0 {
|
||||
for user_receipts in r.values() {
|
||||
for (user, receipt) in user_receipts {
|
||||
receipts.push(WsReceiptEntry {
|
||||
event: event_id.clone(),
|
||||
user: user.clone(),
|
||||
ts: receipt.ts,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(Self::ReceiptEvent(WsReceiptEvent {
|
||||
room_id: evt.room.room_id().to_owned(),
|
||||
receipts,
|
||||
}))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user