diff --git a/Cargo.toml b/Cargo.toml
index 78496e4..950924a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -108,5 +108,5 @@ maintainer-scripts = "debian/"
systemd-units = { unit-name = "matrix-conduit" }
# For flamegraphs:
-#[profile.release]
-#debug = true
+[profile.release]
+debug = true
diff --git a/src/client_server/presence.rs b/src/client_server/presence.rs
index 175853f..9f4f7a3 100644
--- a/src/client_server/presence.rs
+++ b/src/client_server/presence.rs
@@ -1,10 +1,10 @@
use super::State;
use crate::{utils, ConduitResult, Database, Ruma};
-use ruma::api::client::r0::presence::set_presence;
-use std::convert::TryInto;
+use ruma::api::client::r0::presence::{get_presence, set_presence};
+use std::{convert::TryInto, time::Duration};
#[cfg(feature = "conduit_bin")]
-use rocket::put;
+use rocket::{get, put};
#[cfg_attr(
feature = "conduit_bin",
@@ -46,3 +46,48 @@ pub async fn set_presence_route(
Ok(set_presence::Response.into())
}
+
+#[cfg_attr(
+ feature = "conduit_bin",
+ get("/_matrix/client/r0/presence/<_>/status", data = "
")
+)]
+#[tracing::instrument(skip(db, body))]
+pub async fn get_presence_route(
+ db: State<'_, Database>,
+ body: Ruma>,
+) -> ConduitResult {
+ let sender_user = body.sender_user.as_ref().expect("user is authenticated");
+
+ let mut presence_event = None;
+
+ for room_id in db
+ .rooms
+ .get_shared_rooms(vec![sender_user.clone(), body.user_id.clone()])
+ {
+ let room_id = room_id?;
+
+ if let Some(presence) = db
+ .rooms
+ .edus
+ .get_last_presence_event(&sender_user, &room_id)?
+ {
+ presence_event = Some(presence);
+ }
+ }
+
+ if let Some(presence) = presence_event {
+ Ok(get_presence::Response {
+ // TODO: Should ruma just use the presenceeventcontent type here?
+ status_msg: presence.content.status_msg,
+ currently_active: presence.content.currently_active,
+ last_active_ago: presence
+ .content
+ .last_active_ago
+ .map(|millis| Duration::from_millis(millis.into())),
+ presence: presence.content.presence,
+ }
+ .into())
+ } else {
+ todo!();
+ }
+}
diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs
index 56000e0..3bf2e06 100644
--- a/src/database/rooms/edus.rs
+++ b/src/database/rooms/edus.rs
@@ -367,6 +367,47 @@ impl RoomEdus {
.transpose()
}
+ pub fn get_last_presence_event(
+ &self,
+ user_id: &UserId,
+ room_id: &RoomId,
+ ) -> Result