refactor: put endpoints into modules
This commit is contained in:
parent
485a24398b
commit
c1c62b7eb4
33 changed files with 4153 additions and 3848 deletions
45
src/client_server/presence.rs
Normal file
45
src/client_server/presence.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use super::State;
|
||||
use crate::{utils, ConduitResult, Database, Ruma};
|
||||
use ruma::api::client::r0::presence::set_presence;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[cfg(feature = "conduit_bin")]
|
||||
use rocket::put;
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "conduit_bin",
|
||||
put("/_matrix/client/r0/presence/<_>/status", data = "<body>")
|
||||
)]
|
||||
pub fn set_presence_route(
|
||||
db: State<'_, Database>,
|
||||
body: Ruma<set_presence::Request>,
|
||||
) -> ConduitResult<set_presence::Response> {
|
||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
||||
|
||||
for room_id in db.rooms.rooms_joined(&sender_id) {
|
||||
let room_id = room_id?;
|
||||
|
||||
db.rooms.edus.update_presence(
|
||||
&sender_id,
|
||||
&room_id,
|
||||
ruma::events::presence::PresenceEvent {
|
||||
content: ruma::events::presence::PresenceEventContent {
|
||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
||||
currently_active: None,
|
||||
displayname: db.users.displayname(&sender_id)?,
|
||||
last_active_ago: Some(
|
||||
utils::millis_since_unix_epoch()
|
||||
.try_into()
|
||||
.expect("time is valid"),
|
||||
),
|
||||
presence: body.presence,
|
||||
status_msg: body.status_msg.clone(),
|
||||
},
|
||||
sender: sender_id.clone(),
|
||||
},
|
||||
&db.globals,
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(set_presence::Response.into())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue