mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
Merge branch 'private-read-receipt' into 'main'
Draft: implement MSC2285 (private read receipts) Closes #113 See merge request matrix/grapevine!188
This commit is contained in:
commit
f90b45374a
1 changed files with 34 additions and 24 deletions
|
|
@ -38,15 +38,10 @@ pub(crate) async fn set_read_marker_route(
|
|||
)?;
|
||||
}
|
||||
|
||||
if body.private_read_receipt.is_some() || body.read_receipt.is_some() {
|
||||
services()
|
||||
.rooms
|
||||
.user
|
||||
.reset_notification_counts(sender_user, &body.room_id)?;
|
||||
}
|
||||
let mut content = BTreeMap::new();
|
||||
|
||||
if let Some(event) = &body.private_read_receipt {
|
||||
let count = services().rooms.timeline.get_pdu_count(event)?.ok_or(
|
||||
if let Some(event_id) = &body.private_read_receipt {
|
||||
let count = services().rooms.timeline.get_pdu_count(event_id)?.ok_or(
|
||||
Error::BadRequest(ErrorKind::InvalidParam, "Event does not exist."),
|
||||
)?;
|
||||
let count = match count {
|
||||
|
|
@ -63,34 +58,49 @@ pub(crate) async fn set_read_marker_route(
|
|||
sender_user,
|
||||
count,
|
||||
)?;
|
||||
}
|
||||
|
||||
if let Some(event) = &body.read_receipt {
|
||||
let mut user_receipts = BTreeMap::new();
|
||||
user_receipts.insert(
|
||||
sender_user.clone(),
|
||||
ruma::events::receipt::Receipt {
|
||||
ts: Some(MilliSecondsSinceUnixEpoch::now()),
|
||||
thread: ReceiptThread::Unthreaded,
|
||||
},
|
||||
let receipt = ruma::events::receipt::Receipt::new(
|
||||
MilliSecondsSinceUnixEpoch::now(),
|
||||
);
|
||||
|
||||
let mut receipts = BTreeMap::new();
|
||||
receipts.insert(ReceiptType::Read, user_receipts);
|
||||
let user_receipts =
|
||||
[(sender_user.clone(), receipt)].into_iter().collect();
|
||||
|
||||
let mut receipt_content = BTreeMap::new();
|
||||
receipt_content.insert(event.to_owned(), receipts);
|
||||
let receipts =
|
||||
[(ReceiptType::ReadPrivate, user_receipts)].into_iter().collect();
|
||||
|
||||
content.insert(event_id.to_owned(), receipts);
|
||||
}
|
||||
|
||||
if let Some(event_id) = &body.read_receipt {
|
||||
let receipt = ruma::events::receipt::Receipt::new(
|
||||
MilliSecondsSinceUnixEpoch::now(),
|
||||
);
|
||||
|
||||
let user_receipts =
|
||||
[(sender_user.clone(), receipt)].into_iter().collect();
|
||||
|
||||
let receipts =
|
||||
[(ReceiptType::Read, user_receipts)].into_iter().collect();
|
||||
|
||||
content.insert(event_id.to_owned(), receipts);
|
||||
}
|
||||
|
||||
if 0 < content.keys().len() {
|
||||
services()
|
||||
.rooms
|
||||
.user
|
||||
.reset_notification_counts(sender_user, &body.room_id)?;
|
||||
|
||||
services().rooms.edus.read_receipt.readreceipt_update(
|
||||
sender_user,
|
||||
&body.room_id,
|
||||
ruma::events::receipt::ReceiptEvent {
|
||||
content: ruma::events::receipt::ReceiptEventContent(
|
||||
receipt_content,
|
||||
),
|
||||
content: ruma::events::receipt::ReceiptEventContent(content),
|
||||
room_id: body.room_id.clone(),
|
||||
},
|
||||
)?;
|
||||
|
||||
for server in services().rooms.state_cache.room_servers(&body.room_id) {
|
||||
services().sending.trigger_edu_send(&server?)?;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue