[fractal] API, media: Call functions directly instead of using the loop
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] API, media: Call functions directly instead of using the loop
- Date: Fri, 24 Apr 2020 06:48:14 +0000 (UTC)
commit 167208d79ca766ad00ad4c70d02268f4031f4486
Author: Alejandro DomÃnguez <adomu net-c com>
Date: Fri Apr 17 08:38:24 2020 +0200
API, media: Call functions directly instead of using the loop
fractal-gtk/src/actions/message.rs | 12 ++++++++++--
fractal-matrix-api/src/backend/mod.rs | 9 ---------
fractal-matrix-api/src/backend/types.rs | 1 -
3 files changed, 10 insertions(+), 12 deletions(-)
---
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index 53c4637e..96bd4444 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -1,6 +1,7 @@
use fractal_api::clone;
use fractal_api::identifiers::RoomId;
use fractal_api::r0::AccessToken;
+use fractal_api::util::{dw_media, ContentType, ResultExpectLog};
use log::error;
use std::cell::RefCell;
use std::convert::TryFrom;
@@ -9,9 +10,10 @@ use std::rc::Rc;
use std::sync::mpsc::channel;
use std::sync::mpsc::TryRecvError;
use std::sync::mpsc::{Receiver, Sender};
+use std::thread;
use crate::actions::AppState;
-use crate::backend::BKCommand;
+use crate::backend::{BKCommand, BKResponse};
use crate::error::Error;
use crate::i18n::i18n;
use crate::types::Message;
@@ -121,7 +123,13 @@ pub fn new(
open_with.connect_activate(clone!(server_url => move |_, data| {
if let Some(m) = get_message(data) {
let url = m.url.unwrap_or_default();
- let _ = b.send(BKCommand::GetMedia(server_url.clone(), url));
+ let server_url = server_url.clone();
+ let tx = b.clone();
+ thread::spawn(move || {
+ let fname = dw_media(server_url, &url, ContentType::Download, None);
+ tx.send(BKCommand::SendBKResponse(BKResponse::Media(fname)))
+ .expect_log("Connection closed");
+ });
}
}));
diff --git a/fractal-matrix-api/src/backend/mod.rs b/fractal-matrix-api/src/backend/mod.rs
index 8ddbe917..ef015bbf 100644
--- a/fractal-matrix-api/src/backend/mod.rs
+++ b/fractal-matrix-api/src/backend/mod.rs
@@ -5,8 +5,6 @@ use std::sync::mpsc::{Receiver, Sender};
use std::sync::{Arc, Mutex};
use std::thread;
-use crate::util::dw_media;
-use crate::util::ContentType;
use crate::util::ResultExpectLog;
use crate::cache::CacheMap;
@@ -269,13 +267,6 @@ impl Backend {
prev_batch,
ctx,
),
- Ok(BKCommand::GetMedia(server, media)) => {
- thread::spawn(move || {
- let fname = dw_media(server, &media, ContentType::Download, None);
- tx.send(BKResponse::Media(fname))
- .expect_log("Connection closed");
- });
- }
// Directory module
Ok(BKCommand::DirectoryProtocols(server, access_token)) => {
diff --git a/fractal-matrix-api/src/backend/types.rs b/fractal-matrix-api/src/backend/types.rs
index 47b2bf1d..0a03ef1d 100644
--- a/fractal-matrix-api/src/backend/types.rs
+++ b/fractal-matrix-api/src/backend/types.rs
@@ -40,7 +40,6 @@ pub enum BKCommand {
Sender<(Vec<Message>, String)>,
),
GetAvatarAsync(Url, Option<Member>, Sender<String>),
- GetMedia(Url, String),
GetUserInfoAsync(Url, UserId, Option<Sender<(String, String)>>),
SendMsg(Url, AccessToken, Message),
SendMsgRedaction(Url, AccessToken, Message),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]