[fractal] API, room: use endpoint in set_room_topic
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] API, room: use endpoint in set_room_topic
- Date: Thu, 2 Apr 2020 10:39:11 +0000 (UTC)
commit 62d651fc2927f99ff33b2088677057010531b485
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Mon Mar 9 12:51:20 2020 +0100
API, room: use endpoint in set_room_topic
fractal-matrix-api/src/backend/mod.rs | 7 +++++--
fractal-matrix-api/src/backend/room.rs | 30 ++++++++----------------------
2 files changed, 13 insertions(+), 24 deletions(-)
---
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index 45d1e091..c1cb6349 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -313,8 +313,11 @@ impl Backend {
});
}
Ok(BKCommand::SetRoomTopic(server, access_token, room_id, topic)) => {
- let r = room::set_room_topic(self, server, access_token, room_id, topic);
- bkerror2!(r, tx, BKResponse::SetRoomTopic);
+ thread::spawn(move || {
+ let query = room::set_room_topic(server, access_token, room_id, topic);
+ tx.send(BKResponse::SetRoomTopic(query))
+ .expect_log("Connection closed");
+ });
}
Ok(BKCommand::SetRoomAvatar(server, access_token, room_id, fname)) => {
let r = room::set_room_avatar(self, server, access_token, room_id, fname);
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index 3e2e2a58..279a1d77 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -469,38 +469,24 @@ pub fn set_room_name(
}
pub fn set_room_topic(
- bk: &Backend,
base: Url,
access_token: AccessToken,
room_id: RoomId,
topic: String,
) -> Result<(), Error> {
- let url = bk.url(
- base,
- &access_token,
- &format!("rooms/{}/state/m.room.topic", room_id),
- vec![],
- )?;
+ let params = CreateStateEventsForKeyParameters { access_token };
- let attrs = json!({
+ let body = json!({
"topic": topic,
});
- let tx = bk.tx.clone();
- put!(
- url,
- &attrs,
- |_| {
- tx.send(BKResponse::SetRoomTopic(Ok(())))
- .expect_log("Connection closed");
- },
- |err| {
- tx.send(BKResponse::SetRoomTopic(Err(err)))
- .expect_log("Connection closed");
- }
- );
+ create_state_events_for_key(base, ¶ms, &body, &room_id, "m.room.topic")
+ .map_err(Into::into)
+ .and_then(|request| {
+ let _ = HTTP_CLIENT.get_client()?.execute(request)?;
- Ok(())
+ Ok(())
+ })
}
pub fn set_room_avatar(
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]