Commit c2b613292f
Unsigned
Layout: unified · split
src/commands/devices.rs +1 −1
| @@ -145,7 +145,7 @@ impl CommandCallback for DevicesCommand { | ||
| 145 | 145 | .subcommands(Self::subcommands()); |
| 146 | 146 | |
| 147 | 147 | parse_and_run(argparse, arguments, |matches| { |
| 148 | Self::run(buffer, &self.servers, &matches) | |
| 148 | Self::run(buffer, &self.servers, matches) | |
| 149 | 149 | }); |
| 150 | 150 | } |
| 151 | 151 | } |
src/commands/keys.rs +2 −4
| @@ -51,16 +51,14 @@ impl KeysCommand { | ||
| 51 | 51 | let passphrase = args |
| 52 | 52 | .args |
| 53 | 53 | .get("passphrase") |
| 54 | .map(|p| p.vals.get(0).map(|p| p.clone().into_string().ok())) | |
| 55 | .flatten() | |
| 54 | .and_then(|p| p.vals.first().map(|p| p.clone().into_string().ok())) | |
| 56 | 55 | .flatten() |
| 57 | 56 | .expect("No passphrase found"); |
| 58 | 57 | |
| 59 | 58 | let file = args |
| 60 | 59 | .args |
| 61 | 60 | .get("file") |
| 62 | .map(|f| f.vals.get(0)) | |
| 63 | .flatten() | |
| 61 | .and_then(|f| f.vals.first()) | |
| 64 | 62 | .expect("No file found"); |
| 65 | 63 | let file = Weechat::expand_home(&file.to_string_lossy()); |
| 66 | 64 | let file = PathBuf::from(file); |
src/commands/matrix.rs +2 −2
| @@ -37,7 +37,7 @@ impl MatrixCommand { | ||
| 37 | 37 | .add_argument("disconnect <server-name>") |
| 38 | 38 | .add_argument("reconnect <server-name>") |
| 39 | 39 | .add_argument("help <matrix-command> [<matrix-subcommand>]") |
| 40 | .arguments_description(&format!( | |
| 40 | .arguments_description(format!( | |
| 41 | 41 | " server: List, add, or remove Matrix servers. |
| 42 | 42 | connect: Connect to Matrix servers. |
| 43 | 43 | disconnect: Disconnect from one or all Matrix servers. |
| @@ -51,7 +51,7 @@ Use /matrix [command] help to find out more.\n", | ||
| 51 | 51 | )) |
| 52 | 52 | .add_completion("server add|delete|list|listfull") |
| 53 | 53 | .add_completion("devices list|delete|set-name %(matrix-users)") |
| 54 | .add_completion(&format!("keys {}", KeysCommand::COMPLETION)) | |
| 54 | .add_completion(format!("keys {}", KeysCommand::COMPLETION)) | |
| 55 | 55 | .add_completion("connect %(matrix_servers)") |
| 56 | 56 | .add_completion("disconnect %(matrix_servers)") |
| 57 | 57 | .add_completion("reconnect %(matrix_servers)") |
src/config.rs +6 −14
| @@ -34,18 +34,14 @@ use crate::{MatrixServer, Servers}; | ||
| 34 | 34 | |
| 35 | 35 | #[derive(EnumVariantNames)] |
| 36 | 36 | #[strum(serialize_all = "kebab_case")] |
| 37 | #[derive(Default)] | |
| 37 | 38 | pub enum RedactionStyle { |
| 39 | #[default] | |
| 38 | 40 | StrikeThrough, |
| 39 | 41 | Delete, |
| 40 | 42 | Notice, |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | impl Default for RedactionStyle { | |
| 44 | fn default() -> Self { | |
| 45 | RedactionStyle::StrikeThrough | |
| 46 | } | |
| 47 | } | |
| 48 | ||
| 49 | 45 | impl From<i32> for RedactionStyle { |
| 50 | 46 | fn from(value: i32) -> Self { |
| 51 | 47 | match value { |
| @@ -59,18 +55,14 @@ impl From<i32> for RedactionStyle { | ||
| 59 | 55 | |
| 60 | 56 | #[derive(EnumVariantNames)] |
| 61 | 57 | #[strum(serialize_all = "kebab_case")] |
| 58 | #[derive(Default)] | |
| 62 | 59 | pub enum ServerBuffer { |
| 60 | #[default] | |
| 63 | 61 | MergeWithCore, |
| 64 | 62 | MergeWithoutCore, |
| 65 | 63 | Independent, |
| 66 | 64 | } |
| 67 | 65 | |
| 68 | impl Default for ServerBuffer { | |
| 69 | fn default() -> Self { | |
| 70 | ServerBuffer::MergeWithCore | |
| 71 | } | |
| 72 | } | |
| 73 | ||
| 74 | 66 | impl From<i32> for ServerBuffer { |
| 75 | 67 | fn from(value: i32) -> Self { |
| 76 | 68 | match value { |
| @@ -225,7 +217,7 @@ impl ConfigHandle { | ||
| 225 | 217 | } |
| 226 | 218 | } |
| 227 | 219 | |
| 228 | impl<'a> LookSection<'a> { | |
| 220 | impl LookSection<'_> { | |
| 229 | 221 | pub fn server_buffer(&self) -> ServerBuffer { |
| 230 | 222 | if let ConfigOption::Enum(o) = |
| 231 | 223 | self.search_option("server_buffer").unwrap() |
| @@ -264,7 +256,7 @@ impl SectionReadCallback for ConfigHandle { | ||
| 264 | 256 | if !self.servers.contains(server_name) { |
| 265 | 257 | let server = MatrixServer::new( |
| 266 | 258 | server_name, |
| 267 | &self, | |
| 259 | self, | |
| 268 | 260 | section, |
| 269 | 261 | self.servers.clone(), |
| 270 | 262 | ); |
src/connection.rs +4 −4
| @@ -145,10 +145,10 @@ impl Connection { | ||
| 145 | 145 | /// * `room_id` - The id of the room which the message should be sent to. |
| 146 | 146 | /// |
| 147 | 147 | /// * `content` - The content of the message that will be sent to the |
| 148 | /// server. | |
| 148 | /// server. | |
| 149 | 149 | /// |
| 150 | 150 | /// * `transaction_id` - Attach an unique id to this message, later on the |
| 151 | /// event will contain the same id in the unsigned part of the event. | |
| 151 | /// event will contain the same id in the unsigned part of the event. | |
| 152 | 152 | pub async fn send_message( |
| 153 | 153 | &self, |
| 154 | 154 | room: Room, |
| @@ -216,7 +216,7 @@ impl Connection { | ||
| 216 | 216 | /// # Arguments |
| 217 | 217 | /// |
| 218 | 218 | /// * `room_id` - The id of the room where the typing notice should be |
| 219 | /// active. | |
| 219 | /// active. | |
| 220 | 220 | /// |
| 221 | 221 | /// * `typing` - Should we set or unset the typing notice. |
| 222 | 222 | pub async fn send_typing_notice( |
| @@ -235,7 +235,7 @@ impl Connection { | ||
| 235 | 235 | ) -> std::io::Result<()> { |
| 236 | 236 | server_path.push(user_name); |
| 237 | 237 | server_path.set_extension("device_id"); |
| 238 | std::fs::write(&server_path, &response.device_id.to_string()) | |
| 238 | std::fs::write(&server_path, &response.device_id) | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | fn load_device_id( |
src/lib.rs +1 −1
| @@ -109,7 +109,7 @@ impl Servers { | ||
| 109 | 109 | |
| 110 | 110 | for server in servers.values() { |
| 111 | 111 | if let Some(b) = &*server.server_buffer() { |
| 112 | if b.upgrade().map_or(false, |b| &b == buffer) { | |
| 112 | if b.upgrade().is_ok_and(|b| &b == buffer) { | |
| 113 | 113 | return BufferOwner::Server(server.clone()); |
| 114 | 114 | } |
| 115 | 115 | } |
src/render.rs +6 −9
| @@ -123,7 +123,7 @@ pub trait Render { | ||
| 123 | 123 | |
| 124 | 124 | let tags = self.event_tags( |
| 125 | 125 | event_id, |
| 126 | &sender.user_id(), | |
| 126 | sender.user_id(), | |
| 127 | 127 | &sender.nick(), |
| 128 | 128 | sender.color(), |
| 129 | 129 | ); |
| @@ -161,7 +161,7 @@ pub trait Render { | ||
| 161 | 161 | context: &Self::RenderContext, |
| 162 | 162 | ) -> RenderedContent { |
| 163 | 163 | let mut content = self.render(context); |
| 164 | let uuid_tag = format!("matrix_echo_{}", uuid.to_string()); | |
| 164 | let uuid_tag = format!("matrix_echo_{}", uuid); | |
| 165 | 165 | |
| 166 | 166 | for line in &mut content.lines { |
| 167 | 167 | let message = Weechat::remove_color(&line.message); |
| @@ -401,7 +401,7 @@ impl<C: HasUrlOrFile> Render for C { | ||
| 401 | 401 | // Convert MXC to HTTP(s) or EMXC, but fallback to MXC if unable to. |
| 402 | 402 | let mxc_url = match self.encrypted_file() { |
| 403 | 403 | Some(encrypted_file) => { |
| 404 | mxc_to_emxc(self.resolve_url(), homeserver, &encrypted_file) | |
| 404 | mxc_to_emxc(self.resolve_url(), homeserver, encrypted_file) | |
| 405 | 405 | } |
| 406 | 406 | None => mxc_to_http(self.resolve_url(), homeserver), |
| 407 | 407 | } |
| @@ -514,7 +514,7 @@ pub trait HasUrlOrFile { | ||
| 514 | 514 | #[inline] |
| 515 | 515 | fn resolve_url(&self) -> &MxcUri { |
| 516 | 516 | match self.source() { |
| 517 | MediaSource::Plain(s) => &s, | |
| 517 | MediaSource::Plain(s) => s, | |
| 518 | 518 | MediaSource::Encrypted(e) => &e.url, |
| 519 | 519 | } |
| 520 | 520 | } |
| @@ -664,7 +664,7 @@ pub fn render_membership( | ||
| 664 | 664 | Some(name) => format!( |
| 665 | 665 | "{prefix}{target} {color_action}changed their display name to{color_reset} {new}", |
| 666 | 666 | prefix = Weechat::prefix(prefix), |
| 667 | target = event.prev_content().as_ref().map(|p| p.displayname.clone()).flatten().unwrap_or(target_name), | |
| 667 | target = event.prev_content().as_ref().and_then(|p| p.displayname.clone()).unwrap_or(target_name), | |
| 668 | 668 | new = name, |
| 669 | 669 | color_action = color_action, |
| 670 | 670 | color_reset = color_reset |
| @@ -721,8 +721,6 @@ pub fn render_membership( | ||
| 721 | 721 | |
| 722 | 722 | #[cfg(test)] |
| 723 | 723 | mod tests { |
| 724 | use std::convert::TryFrom; | |
| 725 | ||
| 726 | 724 | use matrix_sdk::ruma::{ |
| 727 | 725 | events::room::{EncryptedFileInit, JsonWebKeyInit}, |
| 728 | 726 | serde::Base64, |
| @@ -745,8 +743,7 @@ mod tests { | ||
| 745 | 743 | use std::collections::BTreeMap; |
| 746 | 744 | |
| 747 | 745 | let homeserver = url::Url::parse("https://matrix.org").unwrap(); |
| 748 | let mxc_url = | |
| 749 | OwnedMxcUri::try_from("mxc://matrix.org/some-media-id").unwrap(); | |
| 746 | let mxc_url = OwnedMxcUri::from("mxc://matrix.org/some-media-id"); | |
| 750 | 747 | let mut hashes: BTreeMap<String, Base64> = BTreeMap::new(); |
| 751 | 748 | hashes.insert("sha256".to_string(), Base64::parse("aGFzaA").unwrap()); |
| 752 | 749 | let encrypt_info = EncryptedFileInit { |
src/room/members.rs +4 −4
| @@ -118,7 +118,7 @@ impl Members { | ||
| 118 | 118 | Weechat::print(&format!( |
| 119 | 119 | "{}: Error fetching a room member from the store: {}", |
| 120 | 120 | Weechat::prefix(Prefix::Error), |
| 121 | e.to_string(), | |
| 121 | e, | |
| 122 | 122 | )); |
| 123 | 123 | } |
| 124 | 124 | } |
| @@ -240,7 +240,7 @@ impl Members { | ||
| 240 | 240 | Weechat::print(&format!( |
| 241 | 241 | "{}: Error fetching a room member from the store: {}", |
| 242 | 242 | Weechat::prefix(Prefix::Error), |
| 243 | e.to_string(), | |
| 243 | e, | |
| 244 | 244 | )); |
| 245 | 245 | None |
| 246 | 246 | } |
| @@ -283,7 +283,7 @@ impl Members { | ||
| 283 | 283 | Weechat::print(&format!( |
| 284 | 284 | "{}: Error fetching the room name from the store: {}", |
| 285 | 285 | Weechat::prefix(Prefix::Error), |
| 286 | e.to_string(), | |
| 286 | e, | |
| 287 | 287 | )); |
| 288 | 288 | } |
| 289 | 289 | } |
| @@ -438,7 +438,7 @@ impl WeechatRoomMember { | ||
| 438 | 438 | // TODO: this should color the parenthesis differently. |
| 439 | 439 | format!( |
| 440 | 440 | "{}{}{} ({})", |
| 441 | Weechat::color(&self.color()), | |
| 441 | Weechat::color(self.color()), | |
| 442 | 442 | self.nick_raw(), |
| 443 | 443 | Weechat::color("reset"), |
| 444 | 444 | self.user_id(), |
src/room/mod.rs +16 −17
| @@ -113,7 +113,7 @@ struct IntMutexGuard<'a> { | ||
| 113 | 113 | inner: MutexGuard<'a, Rc<AtomicBool>>, |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | impl<'a> Drop for IntMutexGuard<'a> { | |
| 116 | impl Drop for IntMutexGuard<'_> { | |
| 117 | 117 | fn drop(&mut self) { |
| 118 | 118 | self.inner.store(false, Ordering::SeqCst) |
| 119 | 119 | } |
| @@ -557,39 +557,39 @@ impl MatrixRoom { | ||
| 557 | 557 | c.render_with_prefix(send_time, event_id, sender, &()) |
| 558 | 558 | } |
| 559 | 559 | Emote(c) => { |
| 560 | c.render_with_prefix(send_time, event_id, &sender, &sender) | |
| 560 | c.render_with_prefix(send_time, event_id, sender, sender) | |
| 561 | 561 | } |
| 562 | 562 | Notice(c) => { |
| 563 | c.render_with_prefix(send_time, event_id, &sender, &sender) | |
| 563 | c.render_with_prefix(send_time, event_id, sender, sender) | |
| 564 | 564 | } |
| 565 | 565 | ServerNotice(c) => { |
| 566 | c.render_with_prefix(send_time, event_id, &sender, &sender) | |
| 566 | c.render_with_prefix(send_time, event_id, sender, sender) | |
| 567 | 567 | } |
| 568 | 568 | Location(c) => { |
| 569 | c.render_with_prefix(send_time, event_id, &sender, &sender) | |
| 569 | c.render_with_prefix(send_time, event_id, sender, sender) | |
| 570 | 570 | } |
| 571 | 571 | Audio(c) => c.render_with_prefix( |
| 572 | 572 | send_time, |
| 573 | 573 | event_id, |
| 574 | &sender, | |
| 574 | sender, | |
| 575 | 575 | &self.homeserver, |
| 576 | 576 | ), |
| 577 | 577 | Video(c) => c.render_with_prefix( |
| 578 | 578 | send_time, |
| 579 | 579 | event_id, |
| 580 | &sender, | |
| 580 | sender, | |
| 581 | 581 | &self.homeserver, |
| 582 | 582 | ), |
| 583 | 583 | File(c) => c.render_with_prefix( |
| 584 | 584 | send_time, |
| 585 | 585 | event_id, |
| 586 | &sender, | |
| 586 | sender, | |
| 587 | 587 | &self.homeserver, |
| 588 | 588 | ), |
| 589 | 589 | Image(c) => c.render_with_prefix( |
| 590 | 590 | send_time, |
| 591 | 591 | event_id, |
| 592 | &sender, | |
| 592 | sender, | |
| 593 | 593 | &self.homeserver, |
| 594 | 594 | ), |
| 595 | 595 | _ => return None, |
| @@ -829,7 +829,7 @@ impl MatrixRoom { | ||
| 829 | 829 | message: String, |
| 830 | 830 | } |
| 831 | 831 | |
| 832 | impl<'a> From<BufferLine<'a>> for LineCopy { | |
| 832 | impl From<BufferLine<'_>> for LineCopy { | |
| 833 | 833 | fn from(line: BufferLine) -> Self { |
| 834 | 834 | Self { |
| 835 | 835 | date: line.date(), |
| @@ -869,8 +869,7 @@ impl MatrixRoom { | ||
| 869 | 869 | buffer: &Buffer, |
| 870 | 870 | rendered: RenderedEvent, |
| 871 | 871 | ) { |
| 872 | let uuid_tag = | |
| 873 | Cow::from(format!("matrix_echo_{}", transaction_id.to_string())); | |
| 872 | let uuid_tag = Cow::from(format!("matrix_echo_{}", transaction_id)); | |
| 874 | 873 | let line_contains_uuid = |l: &BufferLine| l.tags().contains(&uuid_tag); |
| 875 | 874 | |
| 876 | 875 | let mut lines = buffer.lines(); |
| @@ -896,10 +895,10 @@ impl MatrixRoom { | ||
| 896 | 895 | event_id: &EventId, |
| 897 | 896 | ) { |
| 898 | 897 | if let Some((echo, content)) = |
| 899 | self.outgoing_messages.remove(&transaction_id) | |
| 898 | self.outgoing_messages.remove(transaction_id) | |
| 900 | 899 | { |
| 901 | 900 | let event = OriginalSyncMessageLikeEvent { |
| 902 | sender: (&*self.own_user_id).to_owned(), | |
| 901 | sender: (*self.own_user_id).to_owned(), | |
| 903 | 902 | origin_server_ts: MilliSecondsSinceUnixEpoch::now(), |
| 904 | 903 | event_id: event_id.to_owned(), |
| 905 | 904 | content, |
| @@ -917,7 +916,7 @@ impl MatrixRoom { | ||
| 917 | 916 | |
| 918 | 917 | if let Ok(buffer) = self.buffer_handle().upgrade() { |
| 919 | 918 | if echo { |
| 920 | self.replace_local_echo(&transaction_id, &buffer, rendered); | |
| 919 | self.replace_local_echo(transaction_id, &buffer, rendered); | |
| 921 | 920 | } else { |
| 922 | 921 | self.print_rendered_event(rendered); |
| 923 | 922 | } |
| @@ -959,7 +958,7 @@ impl MatrixRoom { | ||
| 959 | 958 | .collect(); |
| 960 | 959 | |
| 961 | 960 | if lines |
| 962 | .get(0) | |
| 961 | .first() | |
| 963 | 962 | .map(|l| l.tags().contains(&sender_tag)) |
| 964 | 963 | .unwrap_or(false) |
| 965 | 964 | { |
| @@ -975,7 +974,7 @@ impl MatrixRoom { | ||
| 975 | 974 | event: RenderedEvent, |
| 976 | 975 | ) { |
| 977 | 976 | use std::cmp::Ordering; |
| 978 | let date = lines.get(0).map(|l| l.date()).unwrap_or_default(); | |
| 977 | let date = lines.first().map(|l| l.date()).unwrap_or_default(); | |
| 979 | 978 | |
| 980 | 979 | for (line, new) in lines.iter().zip(event.content.lines.iter()) { |
| 981 | 980 | let tags: Vec<&str> = new.tags.iter().map(|t| t.as_str()).collect(); |
src/server.rs +7 −10
| @@ -221,7 +221,7 @@ impl MatrixServer { | ||
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | let client = self.get_or_create_client()?; |
| 224 | let connection = Connection::new(&self, &client); | |
| 224 | let connection = Connection::new(self, &client); | |
| 225 | 225 | self.set_connection(connection); |
| 226 | 226 | |
| 227 | 227 | self.print_network(&format!( |
| @@ -242,7 +242,7 @@ impl MatrixServer { | ||
| 242 | 242 | let server_buffer = self.inner.server_buffer.borrow_mut(); |
| 243 | 243 | |
| 244 | 244 | if let Some(buffer) = |
| 245 | server_buffer.as_ref().map(|b| b.upgrade().ok()).flatten() | |
| 245 | server_buffer.as_ref().and_then(|b| b.upgrade().ok()) | |
| 246 | 246 | { |
| 247 | 247 | self.inner.merge_server_buffer(&buffer); |
| 248 | 248 | } |
| @@ -526,10 +526,7 @@ impl InnerServer { | ||
| 526 | 526 | |
| 527 | 527 | self.rooms.borrow_mut().insert(room_id, buffer); |
| 528 | 528 | } |
| 529 | Err(e) => self.print_error(&format!( | |
| 530 | "Error restoring room: {}", | |
| 531 | e.to_string() | |
| 532 | )), | |
| 529 | Err(e) => self.print_error(&format!("Error restoring room: {}", e)), | |
| 533 | 530 | } |
| 534 | 531 | } |
| 535 | 532 | |
| @@ -996,7 +993,7 @@ impl InnerServer { | ||
| 996 | 993 | let devices = connection |
| 997 | 994 | .client() |
| 998 | 995 | .encryption() |
| 999 | .get_user_devices(&user_id) | |
| 996 | .get_user_devices(user_id) | |
| 1000 | 997 | .await?; |
| 1001 | 998 | |
| 1002 | 999 | let lines: Vec<_> = devices |
| @@ -1013,7 +1010,7 @@ impl InnerServer { | ||
| 1013 | 1010 | device |
| 1014 | 1011 | .get_key(DeviceKeyAlgorithm::Ed25519) |
| 1015 | 1012 | .map(|f| f.to_base64()), |
| 1016 | device.display_name().as_deref(), | |
| 1013 | device.display_name(), | |
| 1017 | 1014 | false, |
| 1018 | 1015 | device_trust, |
| 1019 | 1016 | None, |
| @@ -1139,7 +1136,7 @@ impl InnerServer { | ||
| 1139 | 1136 | Fingerprint: {}\n \ |
| 1140 | 1137 | Last seen: {}\n", |
| 1141 | 1138 | bold, |
| 1142 | display_name.as_deref().unwrap_or(""), | |
| 1139 | display_name.unwrap_or(""), | |
| 1143 | 1140 | Weechat::color(&color), |
| 1144 | 1141 | device_id.as_str(), |
| 1145 | 1142 | Weechat::color("reset"), |
| @@ -1161,7 +1158,7 @@ impl InnerServer { | ||
| 1161 | 1158 | if Some(user_id.as_ref()) == connection.client().user_id() { |
| 1162 | 1159 | self.list_own_devices(connection).await |
| 1163 | 1160 | } else { |
| 1164 | self.list_other_devices(connection, &user_id).await | |
| 1161 | self.list_other_devices(connection, user_id).await | |
| 1165 | 1162 | } |
| 1166 | 1163 | } else { |
| 1167 | 1164 | self.list_own_devices(connection).await |
src/utils.rs +2 −2
| @@ -63,7 +63,7 @@ impl Edit for AnySyncMessageLikeEvent { | ||
| 63 | 63 | &self, |
| 64 | 64 | ) -> Option<(&EventId, &RoomMessageEventContentWithoutRelation)> { |
| 65 | 65 | if let AnySyncMessageLikeEvent::RoomMessage(e) = self { |
| 66 | e.as_original().map(|e| e.content.get_edit()).flatten() | |
| 66 | e.as_original().and_then(|e| e.content.get_edit()) | |
| 67 | 67 | } else { |
| 68 | 68 | None |
| 69 | 69 | } |
| @@ -85,7 +85,7 @@ impl Edit for AnyMessageLikeEvent { | ||
| 85 | 85 | &self, |
| 86 | 86 | ) -> Option<(&EventId, &RoomMessageEventContentWithoutRelation)> { |
| 87 | 87 | if let AnyMessageLikeEvent::RoomMessage(e) = self { |
| 88 | e.as_original().map(|e| e.content.get_edit()).flatten() | |
| 88 | e.as_original().and_then(|e| e.content.get_edit()) | |
| 89 | 89 | } else { |
| 90 | 90 | None |
| 91 | 91 | } |