diff --git a/src/commands.rs b/src/commands.rs index 363dd88..62bd5b1 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -40,7 +40,7 @@ fn tag_name(name: String) -> Result { if let Ok(tag) = name.parse() { TagName::User(tag) } else { - let msg = format!("Invalid user tag name: {}", name); + let msg = format!("Invalid user tag name: {name}"); return Err(CommandError::Error(msg)); } diff --git a/src/main.rs b/src/main.rs index 5fdd996..e1bf3f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -455,13 +455,13 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult< match worker.login(LoginStyle::Password(password)) { Ok(info) => { if let Some(msg) = info { - println!("{}", msg); + println!("{msg}"); } break; }, Err(err) => { - println!("Failed to login: {}", err); + println!("Failed to login: {err}"); continue; }, } @@ -471,7 +471,7 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult< } fn print_exit(v: T) -> N { - println!("{}", v); + println!("{v}"); process::exit(2); } @@ -532,7 +532,7 @@ fn main() -> IambResult<()> { .thread_name_fn(|| { static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0); let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst); - format!("iamb-worker-{}", id) + format!("iamb-worker-{id}") }) .build() .unwrap(); diff --git a/src/message/mod.rs b/src/message/mod.rs index 5fdfe6c..52f34d7 100644 --- a/src/message/mod.rs +++ b/src/message/mod.rs @@ -134,7 +134,7 @@ impl MessageTimeStamp { match self { MessageTimeStamp::OriginServer(ms) => { let time = millis_to_datetime(*ms).format("%T"); - let time = format!(" [{}]", time); + let time = format!(" [{time}]"); Span::raw(time).into() }, @@ -343,7 +343,7 @@ impl MessageEvent { .and_then(|r| r.content.reason.as_ref()); if let Some(r) = reason { - Cow::Owned(format!("[Redacted: {:?}]", r)) + Cow::Owned(format!("[Redacted: {r:?}]")) } else { Cow::Borrowed("[Redacted]") } diff --git a/src/windows/mod.rs b/src/windows/mod.rs index 2413c72..6f8b5a8 100644 --- a/src/windows/mod.rs +++ b/src/windows/mod.rs @@ -168,7 +168,7 @@ fn append_tags<'a>(tags: &'a Tags, spans: &mut Vec>, style: Style) { spans.push(Span::styled("User Tag: ", style)); spans.push(Span::styled(tag.as_ref(), style)); }, - tag => spans.push(Span::styled(format!("{:?}", tag), style)), + tag => spans.push(Span::styled(format!("{tag:?}"), style)), } } @@ -594,7 +594,7 @@ impl Window for IambWindow { } fn posn(index: usize, _: &mut ProgramStore) -> IambResult { - let msg = format!("Cannot find indexed buffer (index = {})", index); + let msg = format!("Cannot find indexed buffer (index = {index})"); let err = UIError::Unimplemented(msg); Err(err) @@ -852,7 +852,7 @@ impl VerifyItem { let device = self.sasv1.other_device(); if let Some(display_name) = device.display_name() { - format!("Device verification with {} ({})", display_name, state) + format!("Device verification with {display_name} ({state})") } else { format!("Device verification with device {} ({})", device.device_id(), state) } @@ -958,7 +958,7 @@ impl ListItem for VerifyItem { lines.push(Spans::from("")); for line in format_emojis(emoji).lines() { - lines.push(Spans::from(format!(" {}", line))); + lines.push(Spans::from(format!(" {line}"))); } lines.push(Spans::from("")); diff --git a/src/windows/room/chat.rs b/src/windows/room/chat.rs index 8e41a01..69c0354 100644 --- a/src/windows/room/chat.rs +++ b/src/windows/room/chat.rs @@ -383,7 +383,7 @@ impl ChatState { .map_err(IambError::from)?; // Mock up the local echo message for the scrollback. - let msg = TextMessageEventContent::plain(format!("[Attached File: {}]", name)); + let msg = TextMessageEventContent::plain(format!("[Attached File: {name}]")); let msg = MessageType::Text(msg); let msg = RoomMessageEventContent::new(msg); diff --git a/src/windows/room/mod.rs b/src/windows/room/mod.rs index 6becfab..5a59568 100644 --- a/src/windows/room/mod.rs +++ b/src/windows/room/mod.rs @@ -132,10 +132,7 @@ impl RoomState { None => format!("{:?}", store.application.get_room_title(self.id())), }; - let mut invited = vec![Span::from(format!( - "You have been invited to join {}", - name - ))]; + let mut invited = vec![Span::from(format!("You have been invited to join {name}"))]; if let Ok(Some(inviter)) = &inviter { invited.push(Span::from(" by ")); diff --git a/src/windows/room/scrollback.rs b/src/windows/room/scrollback.rs index 6a419a3..3734cb8 100644 --- a/src/windows/room/scrollback.rs +++ b/src/windows/room/scrollback.rs @@ -615,7 +615,7 @@ impl EditorActions for ScrollbackState { }, _ => { - let msg = format!("Unknown editing target: {:?}", motion); + let msg = format!("Unknown editing target: {motion:?}"); let err = EditError::Unimplemented(msg); return Err(err); @@ -702,7 +702,7 @@ impl EditorActions for ScrollbackState { }, _ => { - let msg = format!("Unknown motion: {:?}", motion); + let msg = format!("Unknown motion: {motion:?}"); let err = EditError::Unimplemented(msg); return Err(err); @@ -790,7 +790,7 @@ impl EditorActions for ScrollbackState { HistoryAction::Checkpoint => Ok(None), HistoryAction::Undo(_) => Err(EditError::Failure("Nothing to undo".into())), HistoryAction::Redo(_) => Err(EditError::Failure("Nothing to redo".into())), - _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), + _ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))), } } @@ -847,7 +847,7 @@ impl EditorActions for ScrollbackState { Ok(None) }, - _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), + _ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))), } } } @@ -874,7 +874,7 @@ impl Editable for ScrollbackState { Err(err) }, - _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), + _ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))), } } } @@ -973,7 +973,7 @@ impl Promptable for ScrollbackState { return Err(err); }, _ => { - let msg = format!("Messages scrollback doesn't support {:?}", act); + let msg = format!("Messages scrollback doesn't support {act:?}"); let err = EditError::Unimplemented(msg); return Err(err); diff --git a/src/worker.rs b/src/worker.rs index 2db1b35..15a2cf9 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -350,6 +350,7 @@ pub struct ClientWorker { settings: ApplicationSettings, client: Client, sync_handle: Option>, + rcpt_handle: Option>, } impl ClientWorker { @@ -388,9 +389,10 @@ impl ClientWorker { settings, client: client.clone(), sync_handle: None, + rcpt_handle: None, }; - let _ = tokio::spawn(async move { + tokio::spawn(async move { worker.work(rx).await; }); @@ -412,6 +414,10 @@ impl ClientWorker { if let Some(handle) = self.sync_handle.take() { handle.abort(); } + + if let Some(handle) = self.rcpt_handle.take() { + handle.abort(); + } } async fn run(&mut self, task: WorkerTask) { @@ -685,7 +691,8 @@ impl ClientWorker { ); let client = self.client.clone(); - let _ = tokio::spawn(async move { + + self.rcpt_handle = tokio::spawn(async move { // Update the displayed read receipts ever 5 seconds. let mut interval = tokio::time::interval(Duration::from_secs(5)); @@ -695,7 +702,8 @@ impl ClientWorker { let receipts = update_receipts(&client).await; store.lock().await.application.set_receipts(receipts).await; } - }); + }) + .into(); self.initialized = true; } @@ -762,7 +770,7 @@ impl ClientWorker { "Failed to create direct message room" ); - let msg = format!("Could not open a room with {}", user); + let msg = format!("Could not open a room with {user}"); let err = UIError::Failure(msg); Err(err) @@ -1007,12 +1015,12 @@ impl ClientWorker { let methods = vec![VerificationMethod::SasV1]; let request = identity.request_verification_with_methods(methods); let _req = request.await.map_err(IambError::from)?; - let info = format!("Sent verification request to {}", user_id); + let info = format!("Sent verification request to {user_id}"); Ok(InfoMessage::from(info).into()) }, None => { - let msg = format!("Could not find identity information for {}", user_id); + let msg = format!("Could not find identity information for {user_id}"); let err = UIError::Failure(msg); Err(err)