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