Commit 4fc71c9291
Unregistered key
Layout: unified · split
src/base.rs +1 −3
| @@ -1346,9 +1346,7 @@ impl ChatStore { | |||
| 1346 | 1346 | ||
| 1347 | /// Get a joined room. | 1347 | /// Get a joined room. |
| 1348 | pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> { | 1348 | pub fn get_joined_room(&self, room_id: &RoomId) -> Option<MatrixRoom> { |
| 1349 | let Some(room) = self.worker.client.get_room(room_id) else { | 1349 | let room = self.worker.client.get_room(room_id)?; |
| 1350 | return None; | ||
| 1351 | }; | ||
| 1352 | 1350 | ||
| 1353 | if room.state() == MatrixRoomState::Joined { | 1351 | if room.state() == MatrixRoomState::Joined { |
| 1354 | Some(room) | 1352 | Some(room) |
src/config.rs +1 −1
| @@ -1173,7 +1173,7 @@ mod tests { | |||
| 1173 | let j = "j".parse::<TerminalKey>().unwrap(); | 1173 | let j = "j".parse::<TerminalKey>().unwrap(); |
| 1174 | let esc = "<Esc>".parse::<TerminalKey>().unwrap(); | 1174 | let esc = "<Esc>".parse::<TerminalKey>().unwrap(); |
| 1175 | 1175 | ||
| 1176 | let jj = Keys(vec![j.clone(), j], "jj".into()); | 1176 | let jj = Keys(vec![j, j], "jj".into()); |
| 1177 | let run = mapped.get(&jj).unwrap(); | 1177 | let run = mapped.get(&jj).unwrap(); |
| 1178 | let exp = Keys(vec![esc], "<Esc>".into()); | 1178 | let exp = Keys(vec![esc], "<Esc>".into()); |
| 1179 | assert_eq!(run, &exp); | 1179 | assert_eq!(run, &exp); |
src/message/html.rs +1
| @@ -260,6 +260,7 @@ pub enum StyleTreeNode { | |||
| 260 | Anchor(Box<StyleTreeNode>, char, Url), | 260 | Anchor(Box<StyleTreeNode>, char, Url), |
| 261 | Blockquote(Box<StyleTreeNode>), | 261 | Blockquote(Box<StyleTreeNode>), |
| 262 | Break, | 262 | Break, |
| 263 | #[allow(dead_code)] | ||
| 263 | Code(Box<StyleTreeNode>, Option<String>), | 264 | Code(Box<StyleTreeNode>, Option<String>), |
| 264 | Header(Box<StyleTreeNode>, usize), | 265 | Header(Box<StyleTreeNode>, usize), |
| 265 | Image(Option<String>), | 266 | Image(Option<String>), |
src/message/mod.rs +5 −4
| @@ -5,6 +5,7 @@ use std::collections::hash_map::DefaultHasher; | |||
| 5 | use std::collections::hash_set; | 5 | use std::collections::hash_set; |
| 6 | use std::collections::BTreeMap; | 6 | use std::collections::BTreeMap; |
| 7 | use std::convert::TryFrom; | 7 | use std::convert::TryFrom; |
| 8 | use std::fmt::{self, Display}; | ||
| 8 | use std::hash::{Hash, Hasher}; | 9 | use std::hash::{Hash, Hasher}; |
| 9 | use std::ops::{Deref, DerefMut}; | 10 | use std::ops::{Deref, DerefMut}; |
| 10 | 11 | ||
| @@ -1144,9 +1145,9 @@ impl From<RoomMessageEvent> for Message { | |||
| 1144 | } | 1145 | } |
| 1145 | } | 1146 | } |
| 1146 | 1147 | ||
| 1147 | impl ToString for Message { | 1148 | impl Display for Message { |
| 1148 | fn to_string(&self) -> String { | 1149 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1149 | self.event.body().into_owned() | 1150 | write!(f, "{}", self.event.body()) |
| 1150 | } | 1151 | } |
| 1151 | } | 1152 | } |
| 1152 | 1153 | ||
| @@ -1423,7 +1424,7 @@ pub mod tests { | |||
| 1423 | "Alt text".to_string(), | 1424 | "Alt text".to_string(), |
| 1424 | "mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into() | 1425 | "mxc://matrix.org/jDErsDugkNlfavzLTjJNUKAH".into() |
| 1425 | ) | 1426 | ) |
| 1426 | .info(Some(Box::new(ImageInfo::default()))) | 1427 | .info(Some(Box::default())) |
| 1427 | ))), | 1428 | ))), |
| 1428 | "[Attached Image: Alt text]".to_string() | 1429 | "[Attached Image: Alt text]".to_string() |
| 1429 | ); | 1430 | ); |
src/windows/mod.rs +28 −25
| @@ -7,6 +7,7 @@ | |||
| 7 | //! example, [sending messages][crate::base::SendAction] delegate to the [room window][RoomState], | 7 | //! example, [sending messages][crate::base::SendAction] delegate to the [room window][RoomState], |
| 8 | //! where we have the message bar and room ID easily accesible and resetable. | 8 | //! where we have the message bar and room ID easily accesible and resetable. |
| 9 | use std::cmp::{Ord, Ordering, PartialOrd}; | 9 | use std::cmp::{Ord, Ordering, PartialOrd}; |
| 10 | use std::fmt::{self, Display}; | ||
| 10 | use std::ops::Deref; | 11 | use std::ops::Deref; |
| 11 | use std::sync::Arc; | 12 | use std::sync::Arc; |
| 12 | use std::time::{Duration, Instant}; | 13 | use std::time::{Duration, Instant}; |
| @@ -820,7 +821,7 @@ impl GenericChatItem { | |||
| 820 | let name = info.name.clone().unwrap_or_default(); | 821 | let name = info.name.clone().unwrap_or_default(); |
| 821 | let alias = room.canonical_alias(); | 822 | let alias = room.canonical_alias(); |
| 822 | let unread = info.unreads(&store.application.settings); | 823 | let unread = info.unreads(&store.application.settings); |
| 823 | info.tags = room_info.deref().1.clone(); | 824 | info.tags.clone_from(&room_info.deref().1); |
| 824 | 825 | ||
| 825 | if let Some(alias) = &alias { | 826 | if let Some(alias) = &alias { |
| 826 | store.application.names.insert(alias.to_string(), room_id.to_owned()); | 827 | store.application.names.insert(alias.to_string(), room_id.to_owned()); |
| @@ -870,9 +871,9 @@ impl RoomLikeItem for GenericChatItem { | |||
| 870 | } | 871 | } |
| 871 | } | 872 | } |
| 872 | 873 | ||
| 873 | impl ToString for GenericChatItem { | 874 | impl Display for GenericChatItem { |
| 874 | fn to_string(&self) -> String { | 875 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 875 | return self.name.clone(); | 876 | write!(f, "{}", self.name) |
| 876 | } | 877 | } |
| 877 | } | 878 | } |
| 878 | 879 | ||
| @@ -930,7 +931,7 @@ impl RoomItem { | |||
| 930 | let name = info.name.clone().unwrap_or_default(); | 931 | let name = info.name.clone().unwrap_or_default(); |
| 931 | let alias = room.canonical_alias(); | 932 | let alias = room.canonical_alias(); |
| 932 | let unread = info.unreads(&store.application.settings); | 933 | let unread = info.unreads(&store.application.settings); |
| 933 | info.tags = room_info.deref().1.clone(); | 934 | info.tags.clone_from(&room_info.deref().1); |
| 934 | 935 | ||
| 935 | if let Some(alias) = &alias { | 936 | if let Some(alias) = &alias { |
| 936 | store.application.names.insert(alias.to_string(), room_id.to_owned()); | 937 | store.application.names.insert(alias.to_string(), room_id.to_owned()); |
| @@ -980,9 +981,9 @@ impl RoomLikeItem for RoomItem { | |||
| 980 | } | 981 | } |
| 981 | } | 982 | } |
| 982 | 983 | ||
| 983 | impl ToString for RoomItem { | 984 | impl Display for RoomItem { |
| 984 | fn to_string(&self) -> String { | 985 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 985 | return self.name.clone(); | 986 | write!(f, ":verify request {}", self.name) |
| 986 | } | 987 | } |
| 987 | } | 988 | } |
| 988 | 989 | ||
| @@ -1034,7 +1035,7 @@ impl DirectItem { | |||
| 1034 | let info = store.application.rooms.get_or_default(room_id); | 1035 | let info = store.application.rooms.get_or_default(room_id); |
| 1035 | let name = info.name.clone().unwrap_or_default(); | 1036 | let name = info.name.clone().unwrap_or_default(); |
| 1036 | let unread = info.unreads(&store.application.settings); | 1037 | let unread = info.unreads(&store.application.settings); |
| 1037 | info.tags = room_info.deref().1.clone(); | 1038 | info.tags.clone_from(&room_info.deref().1); |
| 1038 | 1039 | ||
| 1039 | DirectItem { room_info, name, alias, unread } | 1040 | DirectItem { room_info, name, alias, unread } |
| 1040 | } | 1041 | } |
| @@ -1080,9 +1081,9 @@ impl RoomLikeItem for DirectItem { | |||
| 1080 | } | 1081 | } |
| 1081 | } | 1082 | } |
| 1082 | 1083 | ||
| 1083 | impl ToString for DirectItem { | 1084 | impl Display for DirectItem { |
| 1084 | fn to_string(&self) -> String { | 1085 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1085 | return self.name.clone(); | 1086 | write!(f, ":verify request {}", self.name) |
| 1086 | } | 1087 | } |
| 1087 | } | 1088 | } |
| 1088 | 1089 | ||
| @@ -1179,9 +1180,9 @@ impl RoomLikeItem for SpaceItem { | |||
| 1179 | } | 1180 | } |
| 1180 | } | 1181 | } |
| 1181 | 1182 | ||
| 1182 | impl ToString for SpaceItem { | 1183 | impl Display for SpaceItem { |
| 1183 | fn to_string(&self) -> String { | 1184 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1184 | return self.room_id().to_string(); | 1185 | write!(f, ":verify request {}", self.room_id()) |
| 1185 | } | 1186 | } |
| 1186 | } | 1187 | } |
| 1187 | 1188 | ||
| @@ -1300,16 +1301,18 @@ impl From<(&String, &SasVerification)> for VerifyItem { | |||
| 1300 | } | 1301 | } |
| 1301 | } | 1302 | } |
| 1302 | 1303 | ||
| 1303 | impl ToString for VerifyItem { | 1304 | impl Display for VerifyItem { |
| 1304 | fn to_string(&self) -> String { | 1305 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1305 | if self.sasv1.is_done() { | 1306 | if self.sasv1.is_done() { |
| 1306 | String::new() | 1307 | return Ok(()); |
| 1307 | } else if self.sasv1.is_cancelled() { | 1308 | } |
| 1308 | format!(":verify request {}", self.sasv1.other_user_id()) | 1309 | |
| 1310 | if self.sasv1.is_cancelled() { | ||
| 1311 | write!(f, ":verify request {}", self.sasv1.other_user_id()) | ||
| 1309 | } else if self.sasv1.emoji().is_some() { | 1312 | } else if self.sasv1.emoji().is_some() { |
| 1310 | format!(":verify confirm {}", self.user_dev) | 1313 | write!(f, ":verify confirm {}", self.user_dev) |
| 1311 | } else { | 1314 | } else { |
| 1312 | format!(":verify accept {}", self.user_dev) | 1315 | write!(f, ":verify accept {}", self.user_dev) |
| 1313 | } | 1316 | } |
| 1314 | } | 1317 | } |
| 1315 | } | 1318 | } |
| @@ -1413,9 +1416,9 @@ impl MemberItem { | |||
| 1413 | } | 1416 | } |
| 1414 | } | 1417 | } |
| 1415 | 1418 | ||
| 1416 | impl ToString for MemberItem { | 1419 | impl Display for MemberItem { |
| 1417 | fn to_string(&self) -> String { | 1420 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
| 1418 | self.member.user_id().to_string() | 1421 | write!(f, "{}", self.member.user_id()) |
| 1419 | } | 1422 | } |
| 1420 | } | 1423 | } |
| 1421 | 1424 | ||
src/windows/room/scrollback.rs +5 −5
| @@ -1457,11 +1457,11 @@ mod tests { | |||
| 1457 | assert_eq!(scrollback.cursor, MessageCursor::latest()); | 1457 | assert_eq!(scrollback.cursor, MessageCursor::latest()); |
| 1458 | 1458 | ||
| 1459 | // Search backwards to MSG4. | 1459 | // Search backwards to MSG4. |
| 1460 | scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); | 1460 | scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap(); |
| 1461 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); | 1461 | assert_eq!(scrollback.cursor, MSG4_KEY.clone().into()); |
| 1462 | 1462 | ||
| 1463 | // Search backwards to MSG2. | 1463 | // Search backwards to MSG2. |
| 1464 | scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); | 1464 | scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap(); |
| 1465 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); | 1465 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); |
| 1466 | assert_eq!( | 1466 | assert_eq!( |
| 1467 | std::mem::take(&mut store.application.need_load) | 1467 | std::mem::take(&mut store.application.need_load) |
| @@ -1472,7 +1472,7 @@ mod tests { | |||
| 1472 | ); | 1472 | ); |
| 1473 | 1473 | ||
| 1474 | // Can't go any further; need_load now contains the room ID. | 1474 | // Can't go any further; need_load now contains the room ID. |
| 1475 | scrollback.search(prev.clone(), 1.into(), &ctx, &mut store).unwrap(); | 1475 | scrollback.search(prev, 1.into(), &ctx, &mut store).unwrap(); |
| 1476 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); | 1476 | assert_eq!(scrollback.cursor, MSG2_KEY.clone().into()); |
| 1477 | assert_eq!( | 1477 | assert_eq!( |
| 1478 | std::mem::take(&mut store.application.need_load) | 1478 | std::mem::take(&mut store.application.need_load) |
| @@ -1482,11 +1482,11 @@ mod tests { | |||
| 1482 | ); | 1482 | ); |
| 1483 | 1483 | ||
| 1484 | // Search forward twice to MSG1. | 1484 | // Search forward twice to MSG1. |
| 1485 | scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap(); | 1485 | scrollback.search(next, 2.into(), &ctx, &mut store).unwrap(); |
| 1486 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); | 1486 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); |
| 1487 | 1487 | ||
| 1488 | // Can't go any further. | 1488 | // Can't go any further. |
| 1489 | scrollback.search(next.clone(), 2.into(), &ctx, &mut store).unwrap(); | 1489 | scrollback.search(next, 2.into(), &ctx, &mut store).unwrap(); |
| 1490 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); | 1490 | assert_eq!(scrollback.cursor, MSG1_KEY.clone().into()); |
| 1491 | } | 1491 | } |
| 1492 | 1492 | ||