[fractal] Backend: remove internal_tx
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] Backend: remove internal_tx
- Date: Mon, 13 Apr 2020 06:36:25 +0000 (UTC)
commit 5f718d5b28544b94e30d8f9a279606ad42254689
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Sat Apr 4 09:35:55 2020 +0200
Backend: remove internal_tx
fractal-matrix-api/src/backend/mod.rs | 9 +++--
fractal-matrix-api/src/backend/room.rs | 61 ++++++++++++++-------------------
fractal-matrix-api/src/backend/types.rs | 1 -
3 files changed, 31 insertions(+), 40 deletions(-)
---
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index 0cf39760..41f0f4ae 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -36,7 +36,6 @@ impl Backend {
};
Backend {
tx,
- internal_tx: None,
data: Arc::new(Mutex::new(data)),
user_info_cache: CacheMap::new().timeout(60 * 60),
limit_threads: Arc::new((Mutex::new(0u8), Condvar::new())),
@@ -46,7 +45,6 @@ impl Backend {
pub fn run(mut self) -> Sender<BKCommand> {
let (apptx, rx): (Sender<BKCommand>, Receiver<BKCommand>) = channel();
- self.internal_tx = Some(apptx.clone());
thread::spawn(move || loop {
let cmd = rx.recv();
if !self.command_recv(cmd) {
@@ -218,7 +216,12 @@ impl Backend {
});
}
Ok(BKCommand::GetRoomMessagesFromMsg(server, access_token, room_id, from)) => {
- room::get_room_messages_from_msg(self, server, access_token, room_id, from)
+ thread::spawn(move || {
+ let query =
+ room::get_room_messages_from_msg(server, access_token, room_id, from);
+ tx.send(BKResponse::RoomMessagesTo(query))
+ .expect_log("Connection closed");
+ });
}
Ok(BKCommand::GetMessageContext(server, access_token, message)) => {
thread::spawn(move || {
diff --git a/fractal-matrix-api/src/backend/room.rs b/fractal-matrix-api/src/backend/room.rs
index 39b44de4..c48c2084 100644
--- a/fractal-matrix-api/src/backend/room.rs
+++ b/fractal-matrix-api/src/backend/room.rs
@@ -21,7 +21,6 @@ use crate::util::ContentType;
use crate::util::ResultExpectLog;
use crate::util::HTTP_CLIENT;
-use crate::backend::types::BKCommand;
use crate::backend::types::BKResponse;
use crate::backend::types::Backend;
use crate::backend::types::BackendData;
@@ -93,23 +92,22 @@ use serde_json::Value as JsonValue;
// FIXME: Remove this function, this is used only to request information we should already have
// when opening a room
-pub fn set_room(bk: &Backend, base: Url, access_token: AccessToken, room_id: RoomId) {
- if let Some(itx) = bk.internal_tx.clone() {
- itx.send(BKCommand::GetRoomAvatar(
- base.clone(),
- access_token.clone(),
- room_id.clone(),
- ))
- .expect_log("Connection closed");
-
- let tx = bk.tx.clone();
-
- thread::spawn(move || {
- let query = get_room_detail(base, access_token, room_id, "m.room.topic".into());
- tx.send(BKResponse::RoomDetail(query))
- .expect_log("Connection closed");
- });
- }
+pub fn set_room(bk: &Backend, server: Url, access_token: AccessToken, room_id: RoomId) {
+ let tx = bk.tx.clone();
+
+ thread::spawn(clone!(server, access_token, room_id => move || {
+ let query = get_room_avatar(server, access_token, room_id);
+ tx.send(BKResponse::RoomAvatar(query))
+ .expect_log("Connection closed");
+ }));
+
+ let tx = bk.tx.clone();
+
+ thread::spawn(move || {
+ let query = get_room_detail(server, access_token, room_id, "m.room.topic".into());
+ tx.send(BKResponse::RoomDetail(query))
+ .expect_log("Connection closed");
+ });
}
fn get_room_detail(
@@ -232,24 +230,15 @@ pub fn get_room_messages(
}
pub fn get_room_messages_from_msg(
- bk: &Backend,
- baseu: Url,
- tk: AccessToken,
+ base: Url,
+ access_token: AccessToken,
room_id: RoomId,
msg: Message,
-) {
+) -> Result<(Vec<Message>, RoomId, Option<String>), Error> {
// first of all, we calculate the from param using the context api, then we call the
// normal get_room_messages
- let itx = bk.internal_tx.clone();
-
- thread::spawn(move || {
- if let Ok(from) = get_prev_batch_from(baseu.clone(), tk.clone(), &room_id, &msg.id) {
- if let Some(t) = itx {
- t.send(BKCommand::GetRoomMessages(baseu, tk, room_id, from))
- .expect_log("Connection closed");
- }
- }
- });
+ get_prev_batch_from(base.clone(), access_token.clone(), &room_id, &msg.id)
+ .and_then(|from| get_room_messages(base, access_token, room_id, from))
}
pub fn get_message_context(
@@ -537,7 +526,6 @@ pub fn attach_file(
.unwrap_or_default();
let tx = bk.tx.clone();
- let itx = bk.internal_tx.clone();
if fname.starts_with("mxc://") && thumb.starts_with("mxc://") {
tx.send(BKResponse::SentMsg(send_msg(baseu, tk, msg)))
@@ -570,10 +558,11 @@ pub fn attach_file(
let query = upload_file(baseu.clone(), tk.clone(), &fname).map(|response| {
msg.url = Some(response.content_uri.to_string());
- if let Some(t) = itx {
- t.send(BKCommand::SendMsg(baseu, tk, msg.clone()))
+ thread::spawn(clone!(msg, tx => move || {
+ let query = redact_msg(baseu, tk, msg);
+ tx.send(BKResponse::SentMsgRedaction(query))
.expect_log("Connection closed");
- }
+ }));
msg
});
diff --git a/fractal-matrix-api/src/backend/types.rs b/fractal-matrix-api/src/backend/types.rs
index 6f995854..287e39e7 100644
--- a/fractal-matrix-api/src/backend/types.rs
+++ b/fractal-matrix-api/src/backend/types.rs
@@ -156,7 +156,6 @@ pub struct BackendData {
pub struct Backend {
pub tx: Sender<BKResponse>,
pub data: Arc<Mutex<BackendData>>,
- pub internal_tx: Option<Sender<BKCommand>>,
// user info cache, uid -> (name, avatar)
pub user_info_cache: CacheMap<UserId, Arc<Mutex<(String, String)>>>,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]