replace send_file_dm with open_dm resolver (per review)
This commit is contained in:
parent
19f1fa4f28
commit
07941421c1
4 changed files with 26 additions and 44 deletions
|
|
@ -185,7 +185,7 @@ pub async fn send_message(client: &Client, room_ref: &str, body: &str) -> Daemon
|
|||
}
|
||||
|
||||
/// Find the existing DM room with `user_id` or create one. Shared by
|
||||
/// `send_dm` and `send_file_dm`. `direct_targets()` (cached state) is
|
||||
/// `send_dm` and `open_dm`. `direct_targets()` (cached state) is
|
||||
/// used rather than the async `is_direct()`.
|
||||
async fn resolve_or_create_dm(
|
||||
client: &Client,
|
||||
|
|
@ -304,20 +304,19 @@ pub async fn send_file(
|
|||
upload_attachment(&room, path, caption).await
|
||||
}
|
||||
|
||||
pub async fn send_file_dm(
|
||||
client: &Client,
|
||||
user_id: &str,
|
||||
path: &str,
|
||||
caption: Option<&str>,
|
||||
) -> DaemonResponse {
|
||||
/// Resolve (find-or-create) the DM room with `user_id` and return its
|
||||
/// room id without sending anything. The caller then uses the room-based
|
||||
/// tools (`send_file`, `send_message`, …) against that id — so there is
|
||||
/// no per-tool `_dm` variant.
|
||||
pub async fn open_dm(client: &Client, user_id: &str) -> DaemonResponse {
|
||||
let room = match resolve_or_create_dm(client, user_id).await {
|
||||
Ok(r) => r,
|
||||
Err(e) => return e,
|
||||
};
|
||||
if let Some(reject) = unread_guard(&room) {
|
||||
return reject;
|
||||
}
|
||||
upload_attachment(&room, path, caption).await
|
||||
DaemonResponse::ok(&serde_json::json!({
|
||||
"room_id": room.room_id().to_string(),
|
||||
"user_id": user_id,
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn send_reaction(
|
||||
|
|
|
|||
Loading…
Reference in a new issue