mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-16 05:36:50 +00:00
refactor: Ruma upstreaming, half-baked edition
Co-authored-by: Jade Ellis <jade@ellis.link>
This commit is contained in:
142 files changed
+2736
-2288
No files matched your search
@@ -421,7 +421,7 @@ impl Service {
|
||||
let keys_changed = self
|
||||
.services
|
||||
.users
|
||||
.room_keys_changed(room_id, Some(since.0), None)
|
||||
.room_keys_changed(&room_id, Some(since.0), None)
|
||||
.ready_filter(|(user_id, _)| self.services.globals.user_is_local(user_id));
|
||||
|
||||
pin_mut!(keys_changed);
|
||||
@@ -431,21 +431,13 @@ impl Service {
|
||||
}
|
||||
|
||||
max_edu_count.fetch_max(count, Ordering::Relaxed);
|
||||
if !device_list_changes.insert(user_id.into()) {
|
||||
if !device_list_changes.insert(user_id.clone()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Empty prev id forces synapse to resync; because synapse resyncs,
|
||||
// we can just insert placeholder data
|
||||
let edu = Edu::DeviceListUpdate(DeviceListUpdateContent {
|
||||
user_id: user_id.into(),
|
||||
device_id: device_id!("placeholder").to_owned(),
|
||||
device_display_name: Some("Placeholder".to_owned()),
|
||||
stream_id: uint!(1),
|
||||
prev_id: Vec::new(),
|
||||
deleted: None,
|
||||
keys: None,
|
||||
});
|
||||
let edu = Edu::DeviceListUpdate(DeviceListUpdateContent::new(user_id, device_id!("placeholder").to_owned(), uint!(1)));
|
||||
|
||||
let mut buf = EduBuf::new();
|
||||
serde_json::to_writer(&mut buf, &edu)
|
||||
@@ -478,7 +470,6 @@ impl Service {
|
||||
.services
|
||||
.state_cache
|
||||
.server_rooms(server_name)
|
||||
.map(ToOwned::to_owned)
|
||||
.broad_filter_map(|room_id| async move {
|
||||
let receipt_map = self
|
||||
.select_edus_receipts_room(&room_id, since, max_edu_count, &mut num)
|
||||
@@ -497,7 +488,7 @@ impl Service {
|
||||
return None;
|
||||
}
|
||||
|
||||
let receipt_content = Edu::Receipt(ReceiptContent { receipts });
|
||||
let receipt_content = Edu::Receipt(ReceiptContent::new(receipts));
|
||||
|
||||
let mut buf = EduBuf::new();
|
||||
serde_json::to_writer(&mut buf, &receipt_content)
|
||||
@@ -555,10 +546,7 @@ impl Service {
|
||||
.remove(&user_id)
|
||||
.expect("our read receipts always have the user here");
|
||||
|
||||
let receipt_data = ReceiptData {
|
||||
data: receipt,
|
||||
event_ids: vec![event_id.clone()],
|
||||
};
|
||||
let receipt_data = ReceiptData::new(receipt, vec![event_id.clone()]);
|
||||
|
||||
if read.insert(user_id, receipt_data).is_none() {
|
||||
*num = num.saturating_add(1);
|
||||
@@ -568,7 +556,7 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
ReceiptMap { read }
|
||||
ReceiptMap::new(read)
|
||||
}
|
||||
|
||||
/// Look for presence
|
||||
@@ -616,16 +604,9 @@ impl Service {
|
||||
continue;
|
||||
};
|
||||
|
||||
let update = PresenceUpdate {
|
||||
user_id: user_id.into(),
|
||||
presence: presence_event.content.presence,
|
||||
currently_active: presence_event.content.currently_active.unwrap_or(false),
|
||||
status_msg: presence_event.content.status_msg,
|
||||
last_active_ago: presence_event
|
||||
.content
|
||||
.last_active_ago
|
||||
.unwrap_or_else(|| uint!(0)),
|
||||
};
|
||||
let mut update = PresenceUpdate::new(user_id.to_owned(), presence_event.content.presence, presence_event.content.last_active_ago.unwrap_or_else(|| uint!(0)));
|
||||
update.currently_active = presence_event.content.currently_active.unwrap_or_default();
|
||||
update.status_msg = presence_event.content.status_msg;
|
||||
|
||||
presence_updates.insert(user_id.into(), update);
|
||||
if presence_updates.len() >= SELECT_PRESENCE_LIMIT {
|
||||
@@ -637,9 +618,7 @@ impl Service {
|
||||
return None;
|
||||
}
|
||||
|
||||
let presence_content = Edu::Presence(PresenceContent {
|
||||
push: presence_updates.into_values().collect(),
|
||||
});
|
||||
let presence_content = Edu::Presence(PresenceContent::new(presence_updates.into_values().collect()));
|
||||
|
||||
let mut buf = EduBuf::new();
|
||||
serde_json::to_writer(&mut buf, &presence_content)
|
||||
@@ -685,7 +664,7 @@ impl Service {
|
||||
.filter(|event| matches!(event, SendingEvent::Pdu(_)))
|
||||
.count(),
|
||||
);
|
||||
let mut edu_jsons: Vec<EphemeralData> = Vec::with_capacity(
|
||||
let mut edu_jsons: Vec<Raw<EphemeralData>> = Vec::with_capacity(
|
||||
events
|
||||
.iter()
|
||||
.filter(|event| matches!(event, SendingEvent::Edu(_)))
|
||||
@@ -701,7 +680,7 @@ impl Service {
|
||||
| SendingEvent::Edu(edu) =>
|
||||
if appservice.receive_ephemeral {
|
||||
if let Ok(edu) = serde_json::from_slice(edu) {
|
||||
edu_jsons.push(edu);
|
||||
edu_jsons.push(Raw::from_json(edu));
|
||||
}
|
||||
},
|
||||
| SendingEvent::Flush => {}, // flush only; no new content
|
||||
@@ -719,15 +698,14 @@ impl Service {
|
||||
//debug_assert!(pdu_jsons.len() + edu_jsons.len() > 0, "sending empty
|
||||
// transaction");
|
||||
|
||||
let mut request = ruma::api::appservice::event::push_events::v1::Request::new(txn_id.into(), pdu_jsons);
|
||||
request.ephemeral = edu_jsons;
|
||||
request.to_device = Vec::new(); // TODO
|
||||
|
||||
match self
|
||||
.send_appservice_request(
|
||||
appservice,
|
||||
ruma::api::appservice::event::push_events::v1::Request {
|
||||
events: pdu_jsons,
|
||||
txn_id: txn_id.into(),
|
||||
ephemeral: edu_jsons,
|
||||
to_device: Vec::new(), // TODO
|
||||
},
|
||||
request,
|
||||
)
|
||||
.await
|
||||
{
|
||||
@@ -850,18 +828,14 @@ impl Service {
|
||||
|
||||
let txn_hash = calculate_hash(preimage);
|
||||
let txn_id = &*URL_SAFE_NO_PAD.encode(txn_hash);
|
||||
let request = send_transaction_message::v1::Request {
|
||||
transaction_id: txn_id.into(),
|
||||
origin: self.server.name.clone(),
|
||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||
pdus,
|
||||
edus,
|
||||
};
|
||||
let mut request = send_transaction_message::v1::Request::new(txn_id.into(), self.server.name.clone(), MilliSecondsSinceUnixEpoch::now());
|
||||
request.pdus = pdus;
|
||||
request.edus = edus;
|
||||
|
||||
let result = self
|
||||
.services
|
||||
.federation
|
||||
.execute_on(&self.services.client.sender, &server, request)
|
||||
.execute_signed(&self.services.client.sender, &server, request)
|
||||
.await;
|
||||
|
||||
for (event_id, result) in result.iter().flat_map(|resp| resp.pdus.iter()) {
|
||||
@@ -896,7 +870,7 @@ impl Service {
|
||||
.get("room_id")
|
||||
.and_then(|val| RoomId::parse(val.as_str()?).ok())
|
||||
{
|
||||
match self.services.state.get_room_version(room_id).await {
|
||||
match self.services.state.get_room_version(&room_id).await {
|
||||
| Ok(room_version_id) => match room_version_id {
|
||||
| RoomVersionId::V1 | RoomVersionId::V2 => {},
|
||||
| _ => _ = pdu_json.remove("event_id"),
|
||||
|
||||
Reference in new issue
Block a user