|
|
@ -782,50 +782,53 @@ pub async fn send_transaction_message_route(
|
|
|
|
Edu::Receipt(receipt) => {
|
|
|
|
Edu::Receipt(receipt) => {
|
|
|
|
for (room_id, room_updates) in receipt.receipts {
|
|
|
|
for (room_id, room_updates) in receipt.receipts {
|
|
|
|
for (user_id, user_updates) in room_updates.read {
|
|
|
|
for (user_id, user_updates) in room_updates.read {
|
|
|
|
if let Some((event_id, _)) = user_updates
|
|
|
|
if user_id.server_name() == sender_servername {
|
|
|
|
.event_ids
|
|
|
|
if let Some((event_id, _)) = user_updates
|
|
|
|
.iter()
|
|
|
|
.event_ids
|
|
|
|
.filter_map(|id| {
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.filter_map(|id| {
|
|
|
|
|
|
|
|
services()
|
|
|
|
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.timeline
|
|
|
|
|
|
|
|
.get_pdu_count(id)
|
|
|
|
|
|
|
|
.ok()
|
|
|
|
|
|
|
|
.flatten()
|
|
|
|
|
|
|
|
.map(|r| (id, r))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.max_by_key(|(_, count)| *count)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let mut user_receipts = BTreeMap::new();
|
|
|
|
|
|
|
|
user_receipts.insert(user_id.clone(), user_updates.data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut receipts = BTreeMap::new();
|
|
|
|
|
|
|
|
receipts.insert(ReceiptType::Read, user_receipts);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut receipt_content = BTreeMap::new();
|
|
|
|
|
|
|
|
receipt_content.insert(event_id.to_owned(), receipts);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let event = ReceiptEvent {
|
|
|
|
|
|
|
|
content: ReceiptEventContent(receipt_content),
|
|
|
|
|
|
|
|
room_id: room_id.clone(),
|
|
|
|
|
|
|
|
};
|
|
|
|
services()
|
|
|
|
services()
|
|
|
|
.rooms
|
|
|
|
.rooms
|
|
|
|
.timeline
|
|
|
|
.edus
|
|
|
|
.get_pdu_count(id)
|
|
|
|
.read_receipt
|
|
|
|
.ok()
|
|
|
|
.readreceipt_update(&user_id, &room_id, event)?;
|
|
|
|
.flatten()
|
|
|
|
} else {
|
|
|
|
.map(|r| (id, r))
|
|
|
|
// TODO fetch missing events
|
|
|
|
})
|
|
|
|
debug!("No known event ids in read receipt: {:?}", user_updates);
|
|
|
|
.max_by_key(|(_, count)| *count)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
let mut user_receipts = BTreeMap::new();
|
|
|
|
|
|
|
|
user_receipts.insert(user_id.clone(), user_updates.data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut receipts = BTreeMap::new();
|
|
|
|
|
|
|
|
receipts.insert(ReceiptType::Read, user_receipts);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut receipt_content = BTreeMap::new();
|
|
|
|
|
|
|
|
receipt_content.insert(event_id.to_owned(), receipts);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let event = ReceiptEvent {
|
|
|
|
|
|
|
|
content: ReceiptEventContent(receipt_content),
|
|
|
|
|
|
|
|
room_id: room_id.clone(),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
services()
|
|
|
|
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.edus
|
|
|
|
|
|
|
|
.read_receipt
|
|
|
|
|
|
|
|
.readreceipt_update(&user_id, &room_id, event)?;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// TODO fetch missing events
|
|
|
|
|
|
|
|
debug!("No known event ids in read receipt: {:?}", user_updates);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Edu::Typing(typing) => {
|
|
|
|
Edu::Typing(typing) => {
|
|
|
|
if services()
|
|
|
|
if typing.user_id.server_name() == sender_servername
|
|
|
|
.rooms
|
|
|
|
&& services()
|
|
|
|
.state_cache
|
|
|
|
.rooms
|
|
|
|
.is_joined(&typing.user_id, &typing.room_id)?
|
|
|
|
.state_cache
|
|
|
|
|
|
|
|
.is_joined(&typing.user_id, &typing.room_id)?
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if typing.typing {
|
|
|
|
if typing.typing {
|
|
|
|
services()
|
|
|
|
services()
|
|
|
@ -849,7 +852,9 @@ pub async fn send_transaction_message_route(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Edu::DeviceListUpdate(DeviceListUpdateContent { user_id, .. }) => {
|
|
|
|
Edu::DeviceListUpdate(DeviceListUpdateContent { user_id, .. }) => {
|
|
|
|
services().users.mark_device_key_update(&user_id)?;
|
|
|
|
if user_id.server_name() == sender_servername {
|
|
|
|
|
|
|
|
services().users.mark_device_key_update(&user_id)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Edu::DirectToDevice(DirectDeviceContent {
|
|
|
|
Edu::DirectToDevice(DirectDeviceContent {
|
|
|
|
sender,
|
|
|
|
sender,
|
|
|
@ -857,77 +862,75 @@ pub async fn send_transaction_message_route(
|
|
|
|
message_id,
|
|
|
|
message_id,
|
|
|
|
messages,
|
|
|
|
messages,
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
// Check if this is a new transaction id
|
|
|
|
if sender.server_name() == sender_servername
|
|
|
|
if services()
|
|
|
|
// Check if this is a new transaction id
|
|
|
|
.transaction_ids
|
|
|
|
&& services()
|
|
|
|
.existing_txnid(&sender, None, &message_id)?
|
|
|
|
.transaction_ids
|
|
|
|
.is_some()
|
|
|
|
.existing_txnid(&sender, None, &message_id)?
|
|
|
|
|
|
|
|
.is_none()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
for (target_user_id, map) in &messages {
|
|
|
|
}
|
|
|
|
for (target_device_id_maybe, event) in map {
|
|
|
|
|
|
|
|
match target_device_id_maybe {
|
|
|
|
for (target_user_id, map) in &messages {
|
|
|
|
DeviceIdOrAllDevices::DeviceId(target_device_id) => {
|
|
|
|
for (target_device_id_maybe, event) in map {
|
|
|
|
|
|
|
|
match target_device_id_maybe {
|
|
|
|
|
|
|
|
DeviceIdOrAllDevices::DeviceId(target_device_id) => {
|
|
|
|
|
|
|
|
services().users.add_to_device_event(
|
|
|
|
|
|
|
|
&sender,
|
|
|
|
|
|
|
|
target_user_id,
|
|
|
|
|
|
|
|
target_device_id,
|
|
|
|
|
|
|
|
&ev_type.to_string(),
|
|
|
|
|
|
|
|
event.deserialize_as().map_err(|e| {
|
|
|
|
|
|
|
|
warn!("To-Device event is invalid: {event:?} {e}");
|
|
|
|
|
|
|
|
Error::BadRequest(
|
|
|
|
|
|
|
|
ErrorKind::InvalidParam,
|
|
|
|
|
|
|
|
"Event is invalid",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})?,
|
|
|
|
|
|
|
|
)?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdOrAllDevices::AllDevices => {
|
|
|
|
|
|
|
|
for target_device_id in
|
|
|
|
|
|
|
|
services().users.all_device_ids(target_user_id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
services().users.add_to_device_event(
|
|
|
|
services().users.add_to_device_event(
|
|
|
|
&sender,
|
|
|
|
&sender,
|
|
|
|
target_user_id,
|
|
|
|
target_user_id,
|
|
|
|
&target_device_id?,
|
|
|
|
target_device_id,
|
|
|
|
&ev_type.to_string(),
|
|
|
|
&ev_type.to_string(),
|
|
|
|
event.deserialize_as().map_err(|_| {
|
|
|
|
event.deserialize_as().map_err(|e| {
|
|
|
|
|
|
|
|
warn!("To-Device event is invalid: {event:?} {e}");
|
|
|
|
Error::BadRequest(
|
|
|
|
Error::BadRequest(
|
|
|
|
ErrorKind::InvalidParam,
|
|
|
|
ErrorKind::InvalidParam,
|
|
|
|
"Event is invalid",
|
|
|
|
"Event is invalid",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
})?,
|
|
|
|
})?,
|
|
|
|
)?;
|
|
|
|
)?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdOrAllDevices::AllDevices => {
|
|
|
|
|
|
|
|
for target_device_id in
|
|
|
|
|
|
|
|
services().users.all_device_ids(target_user_id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
services().users.add_to_device_event(
|
|
|
|
|
|
|
|
&sender,
|
|
|
|
|
|
|
|
target_user_id,
|
|
|
|
|
|
|
|
&target_device_id?,
|
|
|
|
|
|
|
|
&ev_type.to_string(),
|
|
|
|
|
|
|
|
event.deserialize_as().map_err(|_| {
|
|
|
|
|
|
|
|
Error::BadRequest(
|
|
|
|
|
|
|
|
ErrorKind::InvalidParam,
|
|
|
|
|
|
|
|
"Event is invalid",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
})?,
|
|
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Save transaction id with empty data
|
|
|
|
// Save transaction id with empty data
|
|
|
|
services()
|
|
|
|
services()
|
|
|
|
.transaction_ids
|
|
|
|
.transaction_ids
|
|
|
|
.add_txnid(&sender, None, &message_id, &[])?;
|
|
|
|
.add_txnid(&sender, None, &message_id, &[])?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Edu::SigningKeyUpdate(SigningKeyUpdateContent {
|
|
|
|
Edu::SigningKeyUpdate(SigningKeyUpdateContent {
|
|
|
|
user_id,
|
|
|
|
user_id,
|
|
|
|
master_key,
|
|
|
|
master_key,
|
|
|
|
self_signing_key,
|
|
|
|
self_signing_key,
|
|
|
|
}) => {
|
|
|
|
}) => {
|
|
|
|
if user_id.server_name() != sender_servername {
|
|
|
|
if user_id.server_name() == sender_servername {
|
|
|
|
continue;
|
|
|
|
if let Some(master_key) = master_key {
|
|
|
|
}
|
|
|
|
services().users.add_cross_signing_keys(
|
|
|
|
if let Some(master_key) = master_key {
|
|
|
|
&user_id,
|
|
|
|
services().users.add_cross_signing_keys(
|
|
|
|
&master_key,
|
|
|
|
&user_id,
|
|
|
|
&self_signing_key,
|
|
|
|
&master_key,
|
|
|
|
&None,
|
|
|
|
&self_signing_key,
|
|
|
|
true,
|
|
|
|
&None,
|
|
|
|
)?;
|
|
|
|
true,
|
|
|
|
}
|
|
|
|
)?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Edu::_Custom(_) => {}
|
|
|
|
Edu::_Custom(_) => {}
|
|
|
|