Commit c3f299c6 authored by Daniel Garcia Moreno's avatar Daniel Garcia Moreno Committed by Daniel Garcia Moreno

api: Log every channel sender send error

We were ignoring channel send errors and it could be interesting to have
a log about this not sent messages.

This patch adds a new trait to extend the Result<(), SendError<T>> type
and provide a new method called expect_log, that doesn't panic on error
but logs the message in that case.
parent 0b71ffdd
Pipeline #113718 failed with stages
in 1 minute and 33 seconds
......@@ -9,6 +9,7 @@ use std::thread;
use crate::util::cache_path;
use crate::util::media;
use crate::util::ResultExpectLog;
use crate::util::HTTP_CLIENT;
use crate::r0::directory::post_public_rooms::request as post_public_rooms;
......@@ -47,10 +48,12 @@ pub fn protocols(bk: &Backend) {
.flat_map(|(_, protocol)| protocol.instances.into_iter())
.collect();
let _ = tx.send(BKResponse::DirectoryProtocols(protocols));
tx.send(BKResponse::DirectoryProtocols(protocols))
.expect_log("Connection closed");
}
Err(err) => {
let _ = tx.send(BKResponse::DirectoryError(err));
tx.send(BKResponse::DirectoryError(err))
.expect_log("Connection closed");
}
}
});
......@@ -134,10 +137,12 @@ pub fn room_search(
})
.collect();
let _ = tx.send(BKResponse::DirectorySearch(rooms));
tx.send(BKResponse::DirectorySearch(rooms))
.expect_log("Connection closed");
}
Err(err) => {
let _ = tx.send(BKResponse::DirectoryError(err));
tx.send(BKResponse::DirectoryError(err))
.expect_log("Connection closed");
}
}
});
......
......@@ -12,6 +12,7 @@ use crate::util::get_room_media_list;
use crate::util::resolve_media_url;
use crate::util::semaphore;
use crate::util::thumb;
use crate::util::ResultExpectLog;
use crate::types::Message;
......@@ -21,10 +22,10 @@ pub fn get_thumb_async(bk: &Backend, media: String, tx: Sender<String>) -> Resul
semaphore(bk.limit_threads.clone(), move || {
match thumb(&baseu, &media, None) {
Ok(fname) => {
let _ = tx.send(fname);
tx.send(fname).expect_log("Connection closed");
}
Err(_) => {
let _ = tx.send(String::new());
tx.send(String::new()).expect_log("Connection closed");
}
};
});
......@@ -38,10 +39,10 @@ pub fn get_media_async(bk: &Backend, media: String, tx: Sender<String>) -> Resul
semaphore(bk.limit_threads.clone(), move || {
match util::media(&baseu, &media, None) {
Ok(fname) => {
let _ = tx.send(fname);
tx.send(fname).expect_log("Connection closed");
}
Err(_) => {
let _ = tx.send(String::new());
tx.send(String::new()).expect_log("Connection closed");
}
};
});
......@@ -69,10 +70,11 @@ pub fn get_media_list_async(
&prev_batch,
) {
Ok(media_list) => {
let _ = tx.send(media_list);
tx.send(media_list).expect_log("Connection closed");
}
Err(_) => {
let _ = tx.send((Vec::new(), String::new()));
tx.send((Vec::new(), String::new()))
.expect_log("Connection closed");
}
});
......@@ -86,10 +88,12 @@ pub fn get_media(bk: &Backend, media: String) -> Result<(), Error> {
thread::spawn(move || {
match util::media(&baseu, &media, None) {
Ok(fname) => {
let _ = tx.send(BKResponse::Media(fname));
tx.send(BKResponse::Media(fname))
.expect_log("Connection closed");
}
Err(err) => {
let _ = tx.send(BKResponse::MediaError(err));
tx.send(BKResponse::MediaError(err))
.expect_log("Connection closed");
}
};
});
......@@ -103,10 +107,10 @@ pub fn get_media_url(bk: &Backend, media: String, tx: Sender<String>) -> Result<
semaphore(bk.limit_threads.clone(), move || {
match resolve_media_url(&baseu, &media, false, 0, 0) {
Ok(uri) => {
let _ = tx.send(uri.to_string());
tx.send(uri.to_string()).expect_log("Connection closed");
}
Err(_) => {
let _ = tx.send(String::new());
tx.send(String::new()).expect_log("Connection closed");
}
};
});
......@@ -124,10 +128,10 @@ pub fn get_file_async(url: String, tx: Sender<String>) -> Result<(), Error> {
thread::spawn(move || {
match download_file(&url, fname, None) {
Ok(fname) => {
let _ = tx.send(fname);
tx.send(fname).expect_log("Connection closed");
}
Err(_) => {
let _ = tx.send(String::new());
tx.send(String::new()).expect_log("Connection closed");
}
};
});
......
......@@ -7,6 +7,7 @@ use std::thread;
use url::Url;
use crate::util::client_url;
use crate::util::ResultExpectLog;
use crate::error::Error;
......@@ -212,13 +213,15 @@ impl Backend {
Ok(BKCommand::NewRoom(name, privacy, internalid)) => {
let r = room::new_room(self, &name, privacy, internalid.clone());
if let Err(e) = r {
let _ = tx.send(BKResponse::NewRoomError(e, internalid));
tx.send(BKResponse::NewRoomError(e, internalid))
.expect_log("Connection closed");
}
}
Ok(BKCommand::DirectChat(user, internalid)) => {
let r = room::direct_chat(self, &user, internalid.clone());
if let Err(e) = r {
let _ = tx.send(BKResponse::NewRoomError(e, internalid));
tx.send(BKResponse::NewRoomError(e, internalid))
.expect_log("Connection closed");
}
}
Ok(BKCommand::AddToFav(roomid, tofav)) => {
......@@ -302,7 +305,8 @@ impl Backend {
// Internal commands
Ok(BKCommand::ShutDown) => {
let _ = tx.send(BKResponse::ShutDown);
tx.send(BKResponse::ShutDown)
.expect_log("Connection closed");
return false;
}
Err(_) => {
......
......@@ -20,6 +20,7 @@ use crate::r0::account::UserIdentifier;
use crate::r0::server::domain_info::request as domain_info;
use crate::r0::server::domain_info::Response as DomainInfoResponse;
use crate::r0::Medium;
use crate::util::ResultExpectLog;
use crate::util::HTTP_CLIENT;
use crate::backend::types::BKResponse;
......@@ -57,11 +58,14 @@ pub fn guest(bk: &Backend, server: &str) -> Result<(), Error> {
data.lock().unwrap().user_id = uid.clone();
data.lock().unwrap().access_token = tk.clone();
data.lock().unwrap().since = None;
let _ = tx.send(BKResponse::Token(uid, tk, dev));
let _ = tx.send(BKResponse::Rooms(vec![], None));
tx.send(BKResponse::Token(uid, tk, dev))
.expect_log("Connection closed");
tx.send(BKResponse::Rooms(vec![], None))
.expect_log("Connection closed");
}
Err(err) => {
let _ = tx.send(BKResponse::GuestLoginError(err));
tx.send(BKResponse::GuestLoginError(err))
.expect_log("Connection closed");
}
}
});
......@@ -113,16 +117,19 @@ pub fn login(bk: &Backend, user: String, password: String, server: &str) -> Resu
let dev = response.device_id;
if uid.is_empty() || tk.is_empty() {
let _ = tx.send(BKResponse::LoginError(Error::BackendError));
tx.send(BKResponse::LoginError(Error::BackendError))
.expect_log("Connection closed");
} else {
data.lock().unwrap().user_id = uid.clone();
data.lock().unwrap().access_token = tk.clone();
data.lock().unwrap().since = None;
let _ = tx.send(BKResponse::Token(uid, tk, dev));
tx.send(BKResponse::Token(uid, tk, dev))
.expect_log("Connection closed");
}
}
Err(err) => {
let _ = tx.send(BKResponse::LoginError(err));
tx.send(BKResponse::LoginError(err))
.expect_log("Connection closed");
}
}
});
......@@ -135,7 +142,9 @@ pub fn set_token(bk: &Backend, token: String, uid: String, server: &str) -> Resu
bk.data.lock().unwrap().access_token = token.clone();
bk.data.lock().unwrap().user_id = uid.clone();
bk.data.lock().unwrap().since = None;
let _ = bk.tx.send(BKResponse::Token(uid, token, None));
bk.tx
.send(BKResponse::Token(uid, token, None))
.expect_log("Connection closed");
Ok(())
}
......@@ -164,10 +173,11 @@ pub fn logout(bk: &Backend) {
data.lock().unwrap().user_id = Default::default();
data.lock().unwrap().access_token = Default::default();
data.lock().unwrap().since = None;
let _ = tx.send(BKResponse::Logout);
tx.send(BKResponse::Logout).expect_log("Connection closed");
}
Err(err) => {
let _ = tx.send(BKResponse::LogoutError(err));
tx.send(BKResponse::LogoutError(err))
.expect_log("Connection closed");
}
}
});
......@@ -206,10 +216,12 @@ pub fn register(bk: &Backend, user: String, password: String, server: &str) -> R
data.lock().unwrap().user_id = uid.clone();
data.lock().unwrap().access_token = tk.clone();
data.lock().unwrap().since = None;
let _ = tx.send(BKResponse::Token(uid, tk, dev));
tx.send(BKResponse::Token(uid, tk, dev))
.expect_log("Connection closed");
}
Err(err) => {
let _ = tx.send(BKResponse::LoginError(err));
tx.send(BKResponse::LoginError(err))
.expect_log("Connection closed");
}
}
});
......
......@@ -18,6 +18,7 @@ use crate::util::cache_path;
use crate::util::json_q;
use crate::util::put_media;
use crate::util::thumb;
use crate::util::ResultExpectLog;
use crate::util::{client_url, media_url};
use crate::backend::types::BKCommand;
......@@ -55,10 +56,12 @@ pub fn get_room_detail(bk: &Backend, roomid: String, key: String) -> Result<(),
let k = keys.split('.').last().unwrap();
let value = String::from(r[&k].as_str().unwrap_or_default());
let _ = tx.send(BKResponse::RoomDetail(roomid, key, value));
tx.send(BKResponse::RoomDetail(roomid, key, value))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::RoomDetailError(err));
tx.send(BKResponse::RoomDetailError(err))
.expect_log("Connection closed");
}
);
......@@ -77,16 +80,19 @@ pub fn get_room_avatar(bk: &Backend, roomid: String) -> Result<(), Error> {
if let Some(ref avatar) = avatar {
let _ = thumb(&baseu, avatar.as_str(), dest.as_ref().map(String::as_str));
}
let _ = tx.send(BKResponse::RoomAvatar(roomid, avatar));
tx.send(BKResponse::RoomAvatar(roomid, avatar))
.expect_log("Connection closed");
},
|err: Error| match err {
Error::MatrixError(ref js)
if js["errcode"].as_str().unwrap_or_default() == "M_NOT_FOUND" =>
{
let _ = tx.send(BKResponse::RoomAvatar(roomid, None));
tx.send(BKResponse::RoomAvatar(roomid, None))
.expect_log("Connection closed");
}
_ => {
let _ = tx.send(BKResponse::RoomAvatarError(err));
tx.send(BKResponse::RoomAvatarError(err))
.expect_log("Connection closed");
}
}
);
......@@ -110,10 +116,12 @@ pub fn get_room_members(bk: &Backend, roomid: String) -> Result<(), Error> {
member
})
.collect();
let _ = tx.send(BKResponse::RoomMembers(roomid, ms));
tx.send(BKResponse::RoomMembers(roomid, ms))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::RoomMembersError(err));
tx.send(BKResponse::RoomMembersError(err))
.expect_log("Connection closed");
}
);
......@@ -146,10 +154,12 @@ pub fn get_room_messages(bk: &Backend, roomid: String, from: String) -> Result<(
let evs = array.unwrap().iter().rev();
let list = Message::from_json_events_iter(&roomid, evs);
let prev_batch = r["end"].as_str().map(String::from);
let _ = tx.send(BKResponse::RoomMessagesTo(list, roomid, prev_batch));
tx.send(BKResponse::RoomMessagesTo(list, roomid, prev_batch))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::RoomMembersError(err));
tx.send(BKResponse::RoomMembersError(err))
.expect_log("Connection closed");
}
);
......@@ -166,7 +176,8 @@ pub fn get_room_messages_from_msg(bk: &Backend, roomid: String, msg: Message) ->
thread::spawn(move || {
if let Ok(from) = util::get_prev_batch_from(&baseu, &tk, &roomid, &msg.id) {
if let Some(t) = tx {
let _ = t.send(BKCommand::GetRoomMessages(roomid, from));
t.send(BKCommand::GetRoomMessages(roomid, from))
.expect_log("Connection closed");
}
}
});
......@@ -216,14 +227,17 @@ fn parse_context(
if let Err(err) =
parse_context(tx.clone(), tk, baseu, roomid, &id.unwrap(), limit * 2)
{
let _ = tx.send(BKResponse::RoomMessagesError(err));
tx.send(BKResponse::RoomMessagesError(err))
.expect_log("Connection closed");
}
} else {
let _ = tx.send(BKResponse::RoomMessagesTo(ms, roomid, None));
tx.send(BKResponse::RoomMessagesTo(ms, roomid, None))
.expect_log("Connection closed");
}
},
|err| {
let _ = tx.send(BKResponse::RoomMessagesError(err));
tx.send(BKResponse::RoomMessagesError(err))
.expect_log("Connection closed");
}
);
......@@ -278,10 +292,12 @@ pub fn send_msg(bk: &Backend, msg: Message) -> Result<(), Error> {
&attrs,
move |js: JsonValue| {
let evid = js["event_id"].as_str().unwrap_or_default();
let _ = tx.send(BKResponse::SentMsg(msg.id, evid.to_string()));
tx.send(BKResponse::SentMsg(msg.id, evid.to_string()))
.expect_log("Connection closed");
},
|_| {
let _ = tx.send(BKResponse::SendMsgError(Error::SendMsgError(msg.id)));
tx.send(BKResponse::SendMsgError(Error::SendMsgError(msg.id)))
.expect_log("Connection closed");
}
);
......@@ -299,7 +315,8 @@ pub fn send_typing(bk: &Backend, roomid: String) -> Result<(), Error> {
let tx = bk.tx.clone();
query!("put", &url, &attrs, move |_| {}, |err| {
let _ = tx.send(BKResponse::SendTypingError(err));
tx.send(BKResponse::SendTypingError(err))
.expect_log("Connection closed");
});
Ok(())
......@@ -326,12 +343,14 @@ pub fn redact_msg(bk: &Backend, msg: &Message) -> Result<(), Error> {
&attrs,
move |js: JsonValue| {
let evid = js["event_id"].as_str().unwrap_or_default();
let _ = tx.send(BKResponse::SentMsgRedaction(msgid, evid.to_string()));
tx.send(BKResponse::SentMsgRedaction(msgid, evid.to_string()))
.expect_log("Connection closed");
},
|_| {
let _ = tx.send(BKResponse::SendMsgRedactionError(
tx.send(BKResponse::SendMsgRedactionError(
Error::SendMsgRedactionError(msgid),
));
))
.expect_log("Connection closed");
}
);
......@@ -347,10 +366,12 @@ pub fn join_room(bk: &Backend, roomid: String) -> Result<(), Error> {
&url,
move |_: JsonValue| {
data.lock().unwrap().join_to_room = roomid.clone();
let _ = tx.send(BKResponse::JoinRoom);
tx.send(BKResponse::JoinRoom)
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::JoinRoomError(err));
tx.send(BKResponse::JoinRoomError(err))
.expect_log("Connection closed");
}
);
......@@ -364,10 +385,12 @@ pub fn leave_room(bk: &Backend, roomid: &str) -> Result<(), Error> {
post!(
&url,
move |_: JsonValue| {
let _ = tx.send(BKResponse::LeaveRoom);
tx.send(BKResponse::LeaveRoom)
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::LeaveRoomError(err));
tx.send(BKResponse::LeaveRoomError(err))
.expect_log("Connection closed");
}
);
......@@ -386,10 +409,12 @@ pub fn mark_as_read(bk: &Backend, roomid: &str, eventid: &str) -> Result<(), Err
post!(
&url,
move |_: JsonValue| {
let _ = tx.send(BKResponse::MarkedAsRead(r, e));
tx.send(BKResponse::MarkedAsRead(r, e))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::MarkAsReadError(err));
tx.send(BKResponse::MarkAsReadError(err))
.expect_log("Connection closed");
}
);
......@@ -420,10 +445,12 @@ pub fn set_room_name(bk: &Backend, roomid: &str, name: &str) -> Result<(), Error
&url,
&attrs,
|_| {
let _ = tx.send(BKResponse::SetRoomName);
tx.send(BKResponse::SetRoomName)
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::SetRoomNameError(err));
tx.send(BKResponse::SetRoomNameError(err))
.expect_log("Connection closed");
}
);
......@@ -443,10 +470,12 @@ pub fn set_room_topic(bk: &Backend, roomid: &str, topic: &str) -> Result<(), Err
&url,
&attrs,
|_| {
let _ = tx.send(BKResponse::SetRoomTopic);
tx.send(BKResponse::SetRoomTopic)
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::SetRoomTopicError(err));
tx.send(BKResponse::SetRoomTopicError(err))
.expect_log("Connection closed");
}
);
......@@ -468,7 +497,8 @@ pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), E
thread::spawn(move || {
match put_media(mediaurl.as_str(), contents) {
Err(err) => {
let _ = tx.send(BKResponse::SetRoomAvatarError(err));
tx.send(BKResponse::SetRoomAvatarError(err))
.expect_log("Connection closed");
}
Ok(js) => {
let uri = js["content_uri"].as_str().unwrap_or_default();
......@@ -477,10 +507,12 @@ pub fn set_room_avatar(bk: &Backend, roomid: &str, avatar: &str) -> Result<(), E
&roomurl,
&attrs,
|_| {
let _ = tx.send(BKResponse::SetRoomAvatar);
tx.send(BKResponse::SetRoomAvatar)
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::SetRoomAvatarError(err));
tx.send(BKResponse::SetRoomAvatarError(err))
.expect_log("Connection closed");
}
);
}
......@@ -509,7 +541,8 @@ pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> {
if thumb != "" {
match upload_file(&tk, &baseu, &thumb) {
Err(err) => {
let _ = tx.send(BKResponse::AttachFileError(err));
tx.send(BKResponse::AttachFileError(err))
.expect_log("Connection closed");
}
Ok(thumb_uri) => {
msg.thumb = Some(thumb_uri.to_string());
......@@ -524,14 +557,17 @@ pub fn attach_file(bk: &Backend, mut msg: Message) -> Result<(), Error> {
match upload_file(&tk, &baseu, &fname) {
Err(err) => {
let _ = tx.send(BKResponse::AttachFileError(err));
tx.send(BKResponse::AttachFileError(err))
.expect_log("Connection closed");
}
Ok(uri) => {
msg.url = Some(uri.to_string());
if let Some(t) = itx {
let _ = t.send(BKCommand::SendMsg(msg.clone()));
t.send(BKCommand::SendMsg(msg.clone()))
.expect_log("Connection closed");
}
let _ = tx.send(BKResponse::AttachedFile(msg));
tx.send(BKResponse::AttachedFile(msg))
.expect_log("Connection closed");
}
};
});
......@@ -584,10 +620,12 @@ pub fn new_room(
let id = String::from(r["room_id"].as_str().unwrap_or_default());
let mut r = Room::new(id, RoomMembership::Joined(RoomTag::None));
r.name = Some(n);
let _ = tx.send(BKResponse::NewRoom(r, internal_id));
tx.send(BKResponse::NewRoom(r, internal_id))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::NewRoomError(err, internal_id));
tx.send(BKResponse::NewRoomError(err, internal_id))
.expect_log("Connection closed");
}
);
Ok(())
......@@ -658,12 +696,14 @@ pub fn direct_chat(bk: &Backend, user: &Member, internal_id: String) -> Result<(
let mut r = Room::new(id.clone(), RoomMembership::Joined(RoomTag::None));
r.name = m.alias.clone();
r.direct = true;
let _ = tx.send(BKResponse::NewRoom(r, internal_id));
tx.send(BKResponse::NewRoom(r, internal_id))
.expect_log("Connection closed");
update_direct_chats(direct_url, data, m.uid.clone(), id);
},
|err| {
let _ = tx.send(BKResponse::NewRoomError(err, internal_id));
tx.send(BKResponse::NewRoomError(err, internal_id))
.expect_log("Connection closed");
}
);
......@@ -688,10 +728,12 @@ pub fn add_to_fav(bk: &Backend, roomid: String, tofav: bool) -> Result<(), Error
&url,
&attrs,
|_| {
let _ = tx.send(BKResponse::AddedToFav(roomid.clone(), tofav));
tx.send(BKResponse::AddedToFav(roomid.clone(), tofav))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::AddToFavError(err));
tx.send(BKResponse::AddToFavError(err))
.expect_log("Connection closed");
}
);
......@@ -707,7 +749,8 @@ pub fn invite(bk: &Backend, roomid: &str, userid: &str) -> Result<(), Error> {
let tx = bk.tx.clone();
post!(&url, &attrs, |_| {}, |err| {
let _ = tx.send(BKResponse::InviteError(err));
tx.send(BKResponse::InviteError(err))
.expect_log("Connection closed");
});
Ok(())
......
......@@ -3,6 +3,7 @@ use serde_json::json;
use crate::backend::BackendData;
use crate::util::json_q;
use crate::util::ResultExpectLog;
use crate::util::{client_url, scalar_url};
use std::sync::{Arc, Mutex};
use std::thread;
......@@ -42,10 +43,12 @@ pub fn list(bk: &Backend) -> Result<(), Error> {
let group = StickerGroup::from_json(sticker_group);
stickers.push(group);
}
let _ = tx.send(BKResponse::Stickers(stickers));
tx.send(BKResponse::Stickers(stickers))
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::StickersError(err));
tx.send(BKResponse::StickersError(err))
.expect_log("Connection closed");
}
);
......@@ -77,7 +80,7 @@ pub fn get_sticker_widget_id(bk: &Backend, then: BKCommand) -> Result<(), Error>
d.lock().unwrap().sticker_widget = widget_id;
if let Some(t) = itx {
let _ = t.send(then);
t.send(then).expect_log("Connection closed");
}
},
|err| {
......@@ -92,7 +95,7 @@ pub fn get_sticker_widget_id(bk: &Backend, then: BKCommand) -> Result<(), Error>
}
if let Some(t) = itx {
let _ = t.send(then);
t.send(then).expect_log("Connection closed");
}
}
);
......@@ -126,10 +129,12 @@ pub fn send(bk: &Backend, roomid: &str, sticker: &Sticker) -> Result<(), Error>
&attrs,
move |js: JsonValue| {
let evid = js["event_id"].as_str().unwrap_or_default();
let _ = tx.send(BKResponse::SentMsg(id, evid.to_string()));
tx.send(BKResponse::SentMsg(id, evid.to_string()))
.expect_log("Connection closed");
},
|_| {
let _ = tx.send(BKResponse::SendMsgError(Error::SendMsgError(id)));
tx.send(BKResponse::SendMsgError(Error::SendMsgError(id)))
.expect_log("Connection closed");
}
);
......@@ -156,10 +161,12 @@ pub fn purchase(bk: &Backend, group: &StickerGroup) -> Result<(), Error> {
get!(
&url,
|_| if let Some(t) = itx {
let _ = t.send(BKCommand::ListStickers);
t.send(BKCommand::ListStickers)
.expect_log("Connection closed");
},
|err| {
let _ = tx.send(BKResponse::StickersError(err));
tx.send(BKResponse::StickersError(err))
.expect_log("Connection closed");
}
);
......
......@@ -18,6 +18,7 @@ use crate::types::Room;
use crate::types::RoomMembership;
use crate::types::RoomTag;
use crate::util::parse_m_direct;
use crate::util::ResultExpectLog;
use log::error;
use reqwest::Client;
......@@ -111,7 +112,8 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) {
// New rooms
let rs = Room::from_sync_response(&response, &userid, &base);
let _ = tx.send(BKResponse::UpdateRooms(rs));
tx.send(BKResponse::UpdateRooms(rs))
.expect_log("Connection closed");
// Message events
let msgs = join
......@@ -121,7 +123,8 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) {
Message::from_json_events_iter(&k, events).into_iter()
})
.collect();
let _ = tx.send(BKResponse::RoomMessages(msgs));
tx.send(BKResponse::RoomMessages(msgs))
.expect_log("Connection closed");
// Room notifications
for (k, room) in join.iter() {
......@@ -129,7 +132,8 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) {
highlight_count: h,
notification_count: n,
} = room.unread_notifications;
let _ = tx.send(BKResponse::RoomNotifications(k.clone(), n, h));
tx.send(BKResponse::RoomNotifications(k.clone(), n, h))
.expect_log("Connection closed");
}
// Typing notifications
......@@ -164,7 +168,8 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) {
typing_room
})
.collect();
let _ = tx.send(BKResponse::UpdateRooms(rooms));
tx.send(BKResponse::UpdateRooms(rooms))
.expect_log("Connection closed");
// Other events
join.iter()
......@@ -191,20 +196,24 @@ pub fn sync(bk: &Backend, new_since: Option<String>, initial: bool) {
.as_str()
.map(Into::into)
.unwrap_or_default();
let _ = tx.send(BKResponse::RoomName(ev.room.clone(), name));
tx.send(BKResponse::RoomName(ev.room.clone(), name))
.expect_log("Connection closed");
}
"m.room.topic" => {
let t = ev.content["topic"]
.as_str()
.map(Into::into)
.unwrap_or_default();
let _ = tx.send(BKResponse::RoomTopic(ev.room.clone(), t));
tx.send(BKResponse::RoomTopic(ev.room.clone(), t))
.expect_log("Connection closed");