Commit 3354fdaa25
Unregistered key
Layout: unified · split
docs/iamb.1 +5
| @@ -117,6 +117,11 @@ Confirm an in-progress verification. | |||
| 117 | Reject an in-progress verification due to mismatched Emoji. | 117 | Reject an in-progress verification due to mismatched Emoji. |
| 118 | .It Sy ":verify request [user id]" | 118 | .It Sy ":verify request [user id]" |
| 119 | Request a new verification with the specified user. | 119 | Request a new verification with the specified user. |
| 120 | .It Sy ":verify withdraw [user id]" | ||
| 121 | Withdraw the verification of the specified user. | ||
| 122 | This is necessary when they have reset their cryptographic identity. | ||
| 123 | .It Sy ":verify pin [user id]" | ||
| 124 | Acknowledge that a user has reset their cryptographic identity. | ||
| 120 | .It Sy ":verify recover [recovery key]" | 125 | .It Sy ":verify recover [recovery key]" |
| 121 | Recover the encryption secrets from the backup on your homeserver, verifying this session. | 126 | Recover the encryption secrets from the backup on your homeserver, verifying this session. |
| 122 | .El | 127 | .El |
src/base.rs +27 −6
| @@ -108,6 +108,19 @@ pub enum VerifyAction { | |||
| 108 | Emoji, | 108 | Emoji, |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | /// An action taken against an ongoing verification request. | ||
| 112 | #[derive(Clone, Debug, Eq, PartialEq)] | ||
| 113 | pub enum VerifyUserAction { | ||
| 114 | /// Request a new verification with a user. | ||
| 115 | Request, | ||
| 116 | |||
| 117 | /// Withdraw the verification of a user. | ||
| 118 | Withdraw, | ||
| 119 | |||
| 120 | /// Pin the changed identity of a user. | ||
| 121 | Pin, | ||
| 122 | } | ||
| 123 | |||
| 111 | /// An action taken against a room's timeline. | 124 | /// An action taken against a room's timeline. |
| 112 | #[derive(Clone, Debug, Eq, PartialEq)] | 125 | #[derive(Clone, Debug, Eq, PartialEq)] |
| 113 | pub enum TimelineAction { | 126 | pub enum TimelineAction { |
| @@ -748,8 +761,8 @@ pub enum IambAction { | |||
| 748 | /// Perform an action for an in-progress verification. | 761 | /// Perform an action for an in-progress verification. |
| 749 | Verify(VerifyAction, String), | 762 | Verify(VerifyAction, String), |
| 750 | 763 | ||
| 751 | /// Request a new verification with the specified user. | 764 | /// Perform a verification action against the specified user. |
| 752 | VerifyRequest(String), | 765 | VerifyUser(VerifyUserAction, OwnedUserId), |
| 753 | 766 | ||
| 754 | /// Recover the encryption secrets for this session with the given recovery key. | 767 | /// Recover the encryption secrets for this session with the given recovery key. |
| 755 | Recover(String), | 768 | Recover(String), |
| @@ -828,7 +841,7 @@ impl ApplicationAction for IambAction { | |||
| 828 | IambAction::Timeline(..) => SequenceStatus::Break, | 841 | IambAction::Timeline(..) => SequenceStatus::Break, |
| 829 | IambAction::ToggleScrollbackFocus => SequenceStatus::Break, | 842 | IambAction::ToggleScrollbackFocus => SequenceStatus::Break, |
| 830 | IambAction::Verify(..) => SequenceStatus::Break, | 843 | IambAction::Verify(..) => SequenceStatus::Break, |
| 831 | IambAction::VerifyRequest(..) => SequenceStatus::Break, | 844 | IambAction::VerifyUser(..) => SequenceStatus::Break, |
| 832 | IambAction::Recover(..) => SequenceStatus::Break, | 845 | IambAction::Recover(..) => SequenceStatus::Break, |
| 833 | IambAction::Join(..) => SequenceStatus::Break, | 846 | IambAction::Join(..) => SequenceStatus::Break, |
| 834 | } | 847 | } |
| @@ -848,7 +861,7 @@ impl ApplicationAction for IambAction { | |||
| 848 | IambAction::Timeline(..) => SequenceStatus::Atom, | 861 | IambAction::Timeline(..) => SequenceStatus::Atom, |
| 849 | IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, | 862 | IambAction::ToggleScrollbackFocus => SequenceStatus::Atom, |
| 850 | IambAction::Verify(..) => SequenceStatus::Atom, | 863 | IambAction::Verify(..) => SequenceStatus::Atom, |
| 851 | IambAction::VerifyRequest(..) => SequenceStatus::Atom, | 864 | IambAction::VerifyUser(..) => SequenceStatus::Atom, |
| 852 | IambAction::Recover(..) => SequenceStatus::Atom, | 865 | IambAction::Recover(..) => SequenceStatus::Atom, |
| 853 | IambAction::Join(..) => SequenceStatus::Atom, | 866 | IambAction::Join(..) => SequenceStatus::Atom, |
| 854 | } | 867 | } |
| @@ -868,7 +881,7 @@ impl ApplicationAction for IambAction { | |||
| 868 | IambAction::Timeline(..) => SequenceStatus::Ignore, | 881 | IambAction::Timeline(..) => SequenceStatus::Ignore, |
| 869 | IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, | 882 | IambAction::ToggleScrollbackFocus => SequenceStatus::Ignore, |
| 870 | IambAction::Verify(..) => SequenceStatus::Ignore, | 883 | IambAction::Verify(..) => SequenceStatus::Ignore, |
| 871 | IambAction::VerifyRequest(..) => SequenceStatus::Ignore, | 884 | IambAction::VerifyUser(..) => SequenceStatus::Ignore, |
| 872 | IambAction::Recover(..) => SequenceStatus::Ignore, | 885 | IambAction::Recover(..) => SequenceStatus::Ignore, |
| 873 | IambAction::Join(..) => SequenceStatus::Ignore, | 886 | IambAction::Join(..) => SequenceStatus::Ignore, |
| 874 | } | 887 | } |
| @@ -888,7 +901,7 @@ impl ApplicationAction for IambAction { | |||
| 888 | IambAction::Timeline(..) => false, | 901 | IambAction::Timeline(..) => false, |
| 889 | IambAction::ToggleScrollbackFocus => false, | 902 | IambAction::ToggleScrollbackFocus => false, |
| 890 | IambAction::Verify(..) => false, | 903 | IambAction::Verify(..) => false, |
| 891 | IambAction::VerifyRequest(..) => false, | 904 | IambAction::VerifyUser(..) => false, |
| 892 | IambAction::Recover(..) => false, | 905 | IambAction::Recover(..) => false, |
| 893 | IambAction::Join(..) => false, | 906 | IambAction::Join(..) => false, |
| 894 | } | 907 | } |
| @@ -1464,6 +1477,13 @@ pub struct RoomInfo { | |||
| 1464 | /// filter out values when iterating over it, depending on the use case. | 1477 | /// filter out values when iterating over it, depending on the use case. |
| 1465 | pub memberships: HashMap<OwnedUserId, MemberSummary>, | 1478 | pub memberships: HashMap<OwnedUserId, MemberSummary>, |
| 1466 | 1479 | ||
| 1480 | /// List of all users with problematic identity state. | ||
| 1481 | /// | ||
| 1482 | /// This only tracks [`PinViolation`](`IdentityState::PinViolation`) and | ||
| 1483 | /// [`VerificationViolation`](`IdentityState::VerificationViolation`). The normal states don't | ||
| 1484 | /// need to be tracked. | ||
| 1485 | pub identity_violations: BTreeMap<OwnedUserId, IdentityState>, | ||
| 1486 | |||
| 1467 | /// The last time the room was rendered, used to detect if it is currently open. | 1487 | /// The last time the room was rendered, used to detect if it is currently open. |
| 1468 | pub draw_last: Option<Instant>, | 1488 | pub draw_last: Option<Instant>, |
| 1469 | 1489 | ||
| @@ -1500,6 +1520,7 @@ impl Default for RoomInfo { | |||
| 1500 | users_typing: Default::default(), | 1520 | users_typing: Default::default(), |
| 1501 | display_names: Default::default(), | 1521 | display_names: Default::default(), |
| 1502 | memberships: Default::default(), | 1522 | memberships: Default::default(), |
| 1523 | identity_violations: Default::default(), | ||
| 1503 | draw_last: Default::default(), | 1524 | draw_last: Default::default(), |
| 1504 | pinned_events: Default::default(), | 1525 | pinned_events: Default::default(), |
| 1505 | pinned_previews: Default::default(), | 1526 | pinned_previews: Default::default(), |
src/commands.rs +33 −4
| @@ -19,6 +19,7 @@ use crate::base::{ | |||
| 19 | ProgramCommands, | 19 | ProgramCommands, |
| 20 | RoomField, | 20 | RoomField, |
| 21 | VerifyAction, | 21 | VerifyAction, |
| 22 | VerifyUserAction, | ||
| 22 | }; | 23 | }; |
| 23 | use crate::prelude::*; | 24 | use crate::prelude::*; |
| 24 | 25 | ||
| @@ -247,8 +248,20 @@ fn iamb_verify(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | |||
| 247 | "confirm" => VerifyAction::Confirm, | 248 | "confirm" => VerifyAction::Confirm, |
| 248 | "mismatch" => VerifyAction::Mismatch, | 249 | "mismatch" => VerifyAction::Mismatch, |
| 249 | "emoji" => VerifyAction::Emoji, | 250 | "emoji" => VerifyAction::Emoji, |
| 250 | "request" => { | 251 | "request" | "withdraw" | "pin" => { |
| 251 | let iact = IambAction::VerifyRequest(args.remove(1)); | 252 | let user_id = match OwnedUserId::try_from(args.remove(1)) { |
| 253 | Ok(user_id) => user_id, | ||
| 254 | Err(err) => return Err(CommandError::ParseFailed(err.to_string())), | ||
| 255 | }; | ||
| 256 | |||
| 257 | let act = match args[0].as_str() { | ||
| 258 | "request" => VerifyUserAction::Request, | ||
| 259 | "withdraw" => VerifyUserAction::Withdraw, | ||
| 260 | "pin" => VerifyUserAction::Pin, | ||
| 261 | _ => unreachable!(), | ||
| 262 | }; | ||
| 263 | |||
| 264 | let iact = IambAction::VerifyUser(act, user_id); | ||
| 252 | let step = CommandStep::Continue(iact.into(), ctx.context.clone()); | 265 | let step = CommandStep::Continue(iact.into(), ctx.context.clone()); |
| 253 | 266 | ||
| 254 | return Ok(step); | 267 | return Ok(step); |
| @@ -1351,7 +1364,7 @@ pub fn setup_commands(aliases: &Aliases) -> Result<ProgramCommands, CommandError | |||
| 1351 | mod tests { | 1364 | mod tests { |
| 1352 | use super::*; | 1365 | use super::*; |
| 1353 | 1366 | ||
| 1354 | use matrix_sdk::ruma::{owned_room_id, user_id}; | 1367 | use matrix_sdk::ruma::{owned_room_id, owned_user_id, user_id}; |
| 1355 | use modalkit::actions::WindowAction; | 1368 | use modalkit::actions::WindowAction; |
| 1356 | use modalkit::editing::context::EditContext; | 1369 | use modalkit::editing::context::EditContext; |
| 1357 | 1370 | ||
| @@ -1387,7 +1400,20 @@ mod tests { | |||
| 1387 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | 1400 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 1388 | 1401 | ||
| 1389 | let res = cmds.input_cmd(":verify request @user1:example.com", ctx.clone()).unwrap(); | 1402 | let res = cmds.input_cmd(":verify request @user1:example.com", ctx.clone()).unwrap(); |
| 1390 | let act = IambAction::VerifyRequest("@user1:example.com".into()); | 1403 | let act = |
| 1404 | IambAction::VerifyUser(VerifyUserAction::Request, owned_user_id!("@user1:example.com")); | ||
| 1405 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 1406 | |||
| 1407 | let res = cmds.input_cmd(":verify withdraw @user1:example.com", ctx.clone()).unwrap(); | ||
| 1408 | let act = IambAction::VerifyUser( | ||
| 1409 | VerifyUserAction::Withdraw, | ||
| 1410 | owned_user_id!("@user1:example.com"), | ||
| 1411 | ); | ||
| 1412 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | ||
| 1413 | |||
| 1414 | let res = cmds.input_cmd(":verify pin @user1:example.com", ctx.clone()).unwrap(); | ||
| 1415 | let act = | ||
| 1416 | IambAction::VerifyUser(VerifyUserAction::Pin, owned_user_id!("@user1:example.com")); | ||
| 1391 | assert_eq!(res, vec![(act.into(), ctx.clone())]); | 1417 | assert_eq!(res, vec![(act.into(), ctx.clone())]); |
| 1392 | 1418 | ||
| 1393 | let res = cmds | 1419 | let res = cmds |
| @@ -1433,6 +1459,9 @@ mod tests { | |||
| 1433 | 1459 | ||
| 1434 | let res = cmds.input_cmd(":verify mismatch a b c d e f", ctx.clone()); | 1460 | let res = cmds.input_cmd(":verify mismatch a b c d e f", ctx.clone()); |
| 1435 | assert_eq!(res, Err(CommandError::InvalidArgument)); | 1461 | assert_eq!(res, Err(CommandError::InvalidArgument)); |
| 1462 | |||
| 1463 | let res = cmds.input_cmd(":verify request foobar", ctx.clone()); | ||
| 1464 | assert!(matches!(res, Err(CommandError::ParseFailed(_)))); | ||
| 1436 | } | 1465 | } |
| 1437 | 1466 | ||
| 1438 | #[test] | 1467 | #[test] |
src/completions.rs +4 −1
| @@ -362,8 +362,11 @@ fn complete_iamb_keys( | |||
| 362 | 362 | ||
| 363 | /// Tab completion for `:verify` | 363 | /// Tab completion for `:verify` |
| 364 | fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> { | 364 | fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> { |
| 365 | let user_subcmds = ["request", "withdraw", "pin"]; | ||
| 365 | let subcmds = [ | 366 | let subcmds = [ |
| 366 | "request", | 367 | "request", |
| 368 | "withdraw", | ||
| 369 | "pin", | ||
| 367 | "accept", | 370 | "accept", |
| 368 | "confirm", | 371 | "confirm", |
| 369 | "cancel", | 372 | "cancel", |
| @@ -373,7 +376,7 @@ fn complete_iamb_verify(args: Vec<String>, store: &ChatStore) -> Vec<String> { | |||
| 373 | ]; | 376 | ]; |
| 374 | match args.len() { | 377 | match args.len() { |
| 375 | 1 => complete_choices(&args[0], &subcmds), | 378 | 1 => complete_choices(&args[0], &subcmds), |
| 376 | 2 if args[0] == "request" => complete_users(&args[1], store), | 379 | 2 if user_subcmds.contains(&args[0].as_str()) => complete_users(&args[1], store), |
| 377 | 2 if args[0] == "recover" => vec![], | 380 | 2 if args[0] == "recover" => vec![], |
| 378 | 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store), | 381 | 2 if subcmds.contains(&args[0].as_str()) => complete_verification(&args[1], store), |
| 379 | _ => vec![], | 382 | _ => vec![], |
src/main.rs +2 −6
| @@ -687,12 +687,8 @@ impl Application { | |||
| 687 | IambAction::Verify(act, flow_id) => { | 687 | IambAction::Verify(act, flow_id) => { |
| 688 | return verifications::iamb_verify(act, flow_id, store).await; | 688 | return verifications::iamb_verify(act, flow_id, store).await; |
| 689 | }, | 689 | }, |
| 690 | IambAction::VerifyRequest(user_id) => { | 690 | IambAction::VerifyUser(act, user_id) => { |
| 691 | let Ok(user_id) = <&UserId>::try_from(user_id.as_str()) else { | 691 | return verifications::iamb_verify_user(act, &user_id, store).await; |
| 692 | return Err(IambError::InvalidUserId(user_id).into()); | ||
| 693 | }; | ||
| 694 | |||
| 695 | return verifications::iamb_verify_request(user_id, store).await; | ||
| 696 | }, | 692 | }, |
| 697 | IambAction::Recover(key) => { | 693 | IambAction::Recover(key) => { |
| 698 | return verifications::iamb_recover(key, store).await; | 694 | return verifications::iamb_recover(key, store).await; |
src/prelude.rs +1
| @@ -46,6 +46,7 @@ pub use matrix_sdk::{ | |||
| 46 | encryption::verification::VerificationRequest, | 46 | encryption::verification::VerificationRequest, |
| 47 | room::Room as MatrixRoom, | 47 | room::Room as MatrixRoom, |
| 48 | }; | 48 | }; |
| 49 | pub use matrix_sdk_crypto::IdentityState; | ||
| 49 | pub use modalkit::actions::{ | 50 | pub use modalkit::actions::{ |
| 50 | Action, | 51 | Action, |
| 51 | Editable, | 52 | Editable, |
src/verifications.rs +25 −8
| @@ -2,7 +2,7 @@ use matrix_sdk::encryption::verification::{Verification, VerificationRequestStat | |||
| 2 | use matrix_sdk::ruma::OwnedDeviceId; | 2 | use matrix_sdk::ruma::OwnedDeviceId; |
| 3 | use matrix_sdk::ruma::events::key::verification::VerificationMethod; | 3 | use matrix_sdk::ruma::events::key::verification::VerificationMethod; |
| 4 | 4 | ||
| 5 | use crate::base::VerifyAction; | 5 | use crate::base::{VerifyAction, VerifyUserAction}; |
| 6 | use crate::prelude::*; | 6 | use crate::prelude::*; |
| 7 | 7 | ||
| 8 | const SUPPORTED_METHODS: [VerificationMethod; 3] = [ | 8 | const SUPPORTED_METHODS: [VerificationMethod; 3] = [ |
| @@ -197,7 +197,8 @@ pub async fn iamb_verify( | |||
| 197 | } | 197 | } |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | pub async fn iamb_verify_request( | 200 | pub async fn iamb_verify_user( |
| 201 | act: VerifyUserAction, | ||
| 201 | user_id: &UserId, | 202 | user_id: &UserId, |
| 202 | store: &mut ProgramStore, | 203 | store: &mut ProgramStore, |
| 203 | ) -> IambResult<EditInfo> { | 204 | ) -> IambResult<EditInfo> { |
| @@ -209,14 +210,30 @@ pub async fn iamb_verify_request( | |||
| 209 | return Err(err); | 210 | return Err(err); |
| 210 | }; | 211 | }; |
| 211 | 212 | ||
| 212 | let request = identity.request_verification_with_methods(SUPPORTED_METHODS.into()); | 213 | match act { |
| 213 | let request = request.await.map_err(IambError::from)?; | 214 | VerifyUserAction::Request => { |
| 215 | let request = identity.request_verification_with_methods(SUPPORTED_METHODS.into()); | ||
| 216 | let request = request.await.map_err(IambError::from)?; | ||
| 217 | |||
| 218 | let flow_id = request.flow_id().to_owned(); | ||
| 219 | store.application.verifications.insert(flow_id, request); | ||
| 214 | 220 | ||
| 215 | let flow_id = request.flow_id().to_owned(); | 221 | let info = format!("Sent verification request to {user_id}"); |
| 216 | store.application.verifications.insert(flow_id, request); | 222 | Ok(Some(InfoMessage::from(info))) |
| 223 | }, | ||
| 224 | VerifyUserAction::Withdraw => { | ||
| 225 | identity.withdraw_verification().await.map_err(IambError::from)?; | ||
| 217 | 226 | ||
| 218 | let info = format!("Sent verification request to {user_id}"); | 227 | let info = format!("Withdrawn verification of {user_id}"); |
| 219 | Ok(Some(InfoMessage::from(info))) | 228 | Ok(Some(InfoMessage::from(info))) |
| 229 | }, | ||
| 230 | VerifyUserAction::Pin => { | ||
| 231 | identity.pin().await.map_err(IambError::from)?; | ||
| 232 | |||
| 233 | let info = format!("Pinned identity of {user_id}"); | ||
| 234 | Ok(Some(InfoMessage::from(info))) | ||
| 235 | }, | ||
| 236 | } | ||
| 220 | } | 237 | } |
| 221 | 238 | ||
| 222 | pub async fn iamb_recover(key: String, store: &ProgramStore) -> IambResult<EditInfo> { | 239 | pub async fn iamb_recover(key: String, store: &ProgramStore) -> IambResult<EditInfo> { |
src/windows/room/chat.rs +42 −8
| @@ -1313,11 +1313,14 @@ impl StatefulWidget for Chat<'_> { | |||
| 1313 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { | 1313 | fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State) { |
| 1314 | state.complete_pending_jump(self.store); | 1314 | state.complete_pending_jump(self.store); |
| 1315 | 1315 | ||
| 1316 | let info = self.store.application.rooms.get_or_default(state.id().to_owned()); | ||
| 1316 | let settings = &self.store.application.settings; | 1317 | let settings = &self.store.application.settings; |
| 1317 | let theme = &settings.theme; | 1318 | let theme = &settings.theme; |
| 1319 | let mut msgbar_style = theme.msgbar.default; | ||
| 1320 | let mut msgbar_readonly = false; | ||
| 1318 | 1321 | ||
| 1319 | // Determine whether we have a description to show for the message bar. | 1322 | // Determine whether we have a description to show for the message bar. |
| 1320 | let desc_spans = match (&state.editing, &state.reply_to, state.thread()) { | 1323 | let mut desc_spans = match (&state.editing, &state.reply_to, state.thread()) { |
| 1321 | (None, None, None) => { | 1324 | (None, None, None) => { |
| 1322 | if state.room.is_tombstoned() { | 1325 | if state.room.is_tombstoned() { |
| 1323 | Some( | 1326 | Some( |
| @@ -1337,26 +1340,51 @@ impl StatefulWidget for Chat<'_> { | |||
| 1337 | (Some(_), None, None) => Some(Line::from("Editing message")), | 1340 | (Some(_), None, None) => Some(Line::from("Editing message")), |
| 1338 | (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")), | 1341 | (Some(_), None, Some(_)) => Some(Line::from("Editing message in thread")), |
| 1339 | (editing, Some(_), thread) => { | 1342 | (editing, Some(_), thread) => { |
| 1340 | self.store.application.rooms.get(state.id()).and_then(|room| { | 1343 | state.get_reply_to(info).map(|msg| { |
| 1341 | let msg = state.get_reply_to(room)?; | ||
| 1342 | let user = self | 1344 | let user = self |
| 1343 | .store | 1345 | .store |
| 1344 | .application | 1346 | .application |
| 1345 | .settings | 1347 | .settings |
| 1346 | .get_user_span(msg.sender.as_ref(), room.display_names.get(&msg.sender)); | 1348 | .get_user_span(msg.sender.as_ref(), info.display_names.get(&msg.sender)); |
| 1347 | let prefix = match (editing.is_some(), thread.is_some()) { | 1349 | let prefix = match (editing.is_some(), thread.is_some()) { |
| 1348 | (true, false) => Span::from("Editing reply to "), | 1350 | (true, false) => Span::from("Editing reply to "), |
| 1349 | (true, true) => Span::from("Editing reply in thread to "), | 1351 | (true, true) => Span::from("Editing reply in thread to "), |
| 1350 | (false, false) => Span::from("Replying to "), | 1352 | (false, false) => Span::from("Replying to "), |
| 1351 | (false, true) => Span::from("Replying in thread to "), | 1353 | (false, true) => Span::from("Replying in thread to "), |
| 1352 | }; | 1354 | }; |
| 1353 | let spans = Line::from(vec![prefix, user]); | 1355 | Line::from(vec![prefix, user]) |
| 1354 | |||
| 1355 | spans.into() | ||
| 1356 | }) | 1356 | }) |
| 1357 | }, | 1357 | }, |
| 1358 | }; | 1358 | }; |
| 1359 | 1359 | ||
| 1360 | if desc_spans.is_none() && | ||
| 1361 | let Some((user_id, _)) = info | ||
| 1362 | .identity_violations | ||
| 1363 | .iter() | ||
| 1364 | .find(|(_, state)| **state == IdentityState::PinViolation) | ||
| 1365 | { | ||
| 1366 | let text1 = Span::from("Cryptographic identity of "); | ||
| 1367 | let user = self | ||
| 1368 | .store | ||
| 1369 | .application | ||
| 1370 | .settings | ||
| 1371 | .get_user_span(user_id, info.display_names.get(user_id)); | ||
| 1372 | let text2 = | ||
| 1373 | Span::from(format!(" has changed. Use `:verify pin {user_id}` to acknowledge.")); | ||
| 1374 | |||
| 1375 | desc_spans = Some(Line::from(vec![text1, user, text2])); | ||
| 1376 | } | ||
| 1377 | |||
| 1378 | if let Some((user_id, _)) = info | ||
| 1379 | .identity_violations | ||
| 1380 | .iter() | ||
| 1381 | .find(|(_, state)| **state == IdentityState::VerificationViolation) | ||
| 1382 | { | ||
| 1383 | state.tbox.set_text(format!("Cryptographic identity of {user_id} was reset. Use `:verify withdraw {user_id}` to acknowledge")); | ||
| 1384 | msgbar_readonly = true; | ||
| 1385 | msgbar_style = theme.cmdbar.error; | ||
| 1386 | } | ||
| 1387 | |||
| 1360 | // Determine the region to show each UI element. | 1388 | // Determine the region to show each UI element. |
| 1361 | let lines = state.tbox.has_lines(5).max(1) as u16; | 1389 | let lines = state.tbox.has_lines(5).max(1) as u16; |
| 1362 | let drawh = area.height; | 1390 | let drawh = area.height; |
| @@ -1402,11 +1430,17 @@ impl StatefulWidget for Chat<'_> { | |||
| 1402 | (true, None, None) => Line::from("> "), | 1430 | (true, None, None) => Line::from("> "), |
| 1403 | }; | 1431 | }; |
| 1404 | 1432 | ||
| 1405 | let tbox = TextBox::new().style(theme.msgbar.default).prompt(prompt); | 1433 | let tbox = TextBox::new().style(msgbar_style).prompt(prompt); |
| 1434 | state.tbox.set_readonly(msgbar_readonly); | ||
| 1406 | state | 1435 | state |
| 1407 | .tbox | 1436 | .tbox |
| 1408 | .set_ignorecase(self.store.application.settings.tunables.ignorecase); | 1437 | .set_ignorecase(self.store.application.settings.tunables.ignorecase); |
| 1409 | tbox.render(textarea, buf, &mut state.tbox); | 1438 | tbox.render(textarea, buf, &mut state.tbox); |
| 1439 | if msgbar_readonly { | ||
| 1440 | // Clear the msgbar here. If it is still readonly on the next render, the content will | ||
| 1441 | // be overwritten anyway and if not the content would stay. | ||
| 1442 | state.tbox.reset(); | ||
| 1443 | } | ||
| 1410 | 1444 | ||
| 1411 | // Render the message scrollback. | 1445 | // Render the message scrollback. |
| 1412 | let scrollback_style = self.store.application.settings.theme.timeline.default; | 1446 | let scrollback_style = self.store.application.settings.theme.timeline.default; |
src/worker.rs +49 −16
| @@ -641,9 +641,10 @@ fn members_insert( | |||
| 641 | pub(crate) async fn subscribe_room_updates( | 641 | pub(crate) async fn subscribe_room_updates( |
| 642 | room: MatrixRoom, | 642 | room: MatrixRoom, |
| 643 | store: AsyncProgramStore, | 643 | store: AsyncProgramStore, |
| 644 | ) -> Result<JoinHandle<()>, matrix_sdk::event_cache::EventCacheError> { | 644 | ) -> Result<JoinHandle<()>, MatrixError> { |
| 645 | let (cache, drop_handle) = room.client().event_cache().room(room.room_id()).await?; | 645 | let (cache, drop_handle) = room.client().event_cache().room(room.room_id()).await?; |
| 646 | let (initial_events, mut events_sub) = cache.subscribe().await?; | 646 | let (initial_events, mut events_sub) = cache.subscribe().await?; |
| 647 | let identity_changes = room.subscribe_to_identity_status_changes().await?; | ||
| 647 | 648 | ||
| 648 | Ok(tokio::spawn(async move { | 649 | Ok(tokio::spawn(async move { |
| 649 | let _drop_handle = drop_handle; | 650 | let _drop_handle = drop_handle; |
| @@ -658,24 +659,56 @@ pub(crate) async fn subscribe_room_updates( | |||
| 658 | insert_msgs_and_receipts(msgs, info, presences, previews, settings); | 659 | insert_msgs_and_receipts(msgs, info, presences, previews, settings); |
| 659 | } | 660 | } |
| 660 | 661 | ||
| 661 | while let Ok(update) = events_sub.recv().await { | 662 | futures::pin_mut!(identity_changes); |
| 662 | match update { | 663 | loop { |
| 663 | RoomEventCacheUpdate::UpdateTimelineEvents(diffs) => { | 664 | tokio::select! { |
| 664 | handle_timeline_update(diffs, &room, &store).await; | 665 | update = events_sub.recv() => { |
| 665 | }, | 666 | let Ok(update) = update else { |
| 666 | RoomEventCacheUpdate::AddReadReceiptEvent { event } => { | 667 | // The sender side has gone away, so just exit the loop. |
| 667 | handle_receipt_update(event, &room, &store).await; | 668 | return |
| 668 | }, | 669 | }; |
| 669 | RoomEventCacheUpdate::MoveReadMarkerTo { .. } => { | 670 | match update { |
| 670 | // XXX: Support the fully_read marker | 671 | RoomEventCacheUpdate::UpdateTimelineEvents(diffs) => { |
| 671 | }, | 672 | handle_timeline_update(diffs, &room, &store).await; |
| 672 | RoomEventCacheUpdate::UpdateMembers { ambiguity_changes, .. } => { | 673 | }, |
| 674 | RoomEventCacheUpdate::AddReadReceiptEvent { event } => { | ||
| 675 | handle_receipt_update(event, &room, &store).await; | ||
| 676 | }, | ||
| 677 | RoomEventCacheUpdate::MoveReadMarkerTo { .. } => { | ||
| 678 | // XXX: Support the fully_read marker | ||
| 679 | }, | ||
| 680 | RoomEventCacheUpdate::UpdateMembers { ambiguity_changes, .. } => { | ||
| 681 | let mut locked = store.lock().await; | ||
| 682 | let info = locked.application.rooms.get_or_default(room.room_id().to_owned()); | ||
| 683 | for (_, change) in ambiguity_changes.into_iter() { | ||
| 684 | info.display_names.apply_ambiguity_change(change); | ||
| 685 | } | ||
| 686 | }, | ||
| 687 | } | ||
| 688 | } | ||
| 689 | |||
| 690 | update = identity_changes.next() => { | ||
| 691 | let Some(update) = update else { | ||
| 692 | // The sender side has gone away, so just exit the loop. | ||
| 693 | return | ||
| 694 | }; | ||
| 695 | |||
| 673 | let mut locked = store.lock().await; | 696 | let mut locked = store.lock().await; |
| 674 | let info = locked.application.rooms.get_or_default(room.room_id().to_owned()); | 697 | let info = locked.application.rooms.get_or_default(room.room_id().to_owned()); |
| 675 | for (_, change) in ambiguity_changes.into_iter() { | 698 | |
| 676 | info.display_names.apply_ambiguity_change(change); | 699 | for change in update { |
| 700 | match change.changed_to { | ||
| 701 | IdentityState::Verified | | ||
| 702 | IdentityState::Pinned => { | ||
| 703 | info.identity_violations.remove(&change.user_id); | ||
| 704 | } | ||
| 705 | IdentityState::PinViolation | | ||
| 706 | IdentityState::VerificationViolation => { | ||
| 707 | info.identity_violations.insert(change.user_id, change.changed_to); | ||
| 708 | } | ||
| 709 | } | ||
| 677 | } | 710 | } |
| 678 | }, | 711 | } |
| 679 | } | 712 | } |
| 680 | } | 713 | } |
| 681 | })) | 714 | })) |