Commit cda6bf1180
Unregistered key
Layout: unified · split
Cargo.toml +1 −1
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | [package] |
| 2 | 2 | name = "iamb" |
| 3 | 3 | version = "0.0.11" |
| 4 | edition = "2018" | |
| 4 | edition = "2024" | |
| 5 | 5 | authors = ["Ulyssa <git@ulyssa.dev>"] |
| 6 | 6 | repository = "https://github.com/ulyssa/iamb" |
| 7 | 7 | homepage = "https://iamb.chat" |
src/base.rs +28 −27
| @@ -13,10 +13,10 @@ use std::time::{Duration, Instant}; | ||
| 13 | 13 | |
| 14 | 14 | use emojis::Emoji; |
| 15 | 15 | |
| 16 | use matrix_sdk::ruma::OwnedTransactionId; | |
| 16 | 17 | use matrix_sdk::ruma::events::receipt::ReceiptThread; |
| 17 | 18 | use matrix_sdk::ruma::events::room::MediaSource; |
| 18 | 19 | use matrix_sdk::ruma::events::sticker::StickerEvent; |
| 19 | use matrix_sdk::ruma::OwnedTransactionId; | |
| 20 | 20 | use ratatui::{ |
| 21 | 21 | buffer::Buffer, |
| 22 | 22 | layout::{Alignment, Rect}, |
| @@ -25,21 +25,30 @@ use ratatui::{ | ||
| 25 | 25 | }; |
| 26 | 26 | use ratatui_image::picker::{Picker, ProtocolType}; |
| 27 | 27 | use serde::{ |
| 28 | de::Error as SerdeError, | |
| 29 | de::Visitor, | |
| 30 | 28 | Deserialize, |
| 31 | 29 | Deserializer, |
| 32 | 30 | Serialize, |
| 33 | 31 | Serializer, |
| 32 | de::Error as SerdeError, | |
| 33 | de::Visitor, | |
| 34 | 34 | }; |
| 35 | 35 | use tokio::sync::Mutex as AsyncMutex; |
| 36 | 36 | use url::Url; |
| 37 | 37 | |
| 38 | 38 | use matrix_sdk::{ |
| 39 | RoomState as MatrixRoomState, | |
| 39 | 40 | encryption::verification::SasVerification, |
| 40 | 41 | room::Room as MatrixRoom, |
| 41 | 42 | ruma::{ |
| 43 | EventId, | |
| 44 | OwnedEventId, | |
| 45 | OwnedRoomId, | |
| 46 | OwnedUserId, | |
| 47 | RoomId, | |
| 48 | UserId, | |
| 42 | 49 | events::{ |
| 50 | AnySyncStateEvent, | |
| 51 | MessageLikeEvent, | |
| 43 | 52 | reaction::ReactionEvent, |
| 44 | 53 | relation::{Replacement, Thread}, |
| 45 | 54 | room::encrypted::RoomEncryptedEvent, |
| @@ -52,18 +61,9 @@ use matrix_sdk::{ | ||
| 52 | 61 | }, |
| 53 | 62 | room::redaction::{OriginalSyncRoomRedactionEvent, SyncRoomRedactionEvent}, |
| 54 | 63 | tag::{TagName, Tags}, |
| 55 | AnySyncStateEvent, | |
| 56 | MessageLikeEvent, | |
| 57 | 64 | }, |
| 58 | 65 | presence::PresenceState, |
| 59 | EventId, | |
| 60 | OwnedEventId, | |
| 61 | OwnedRoomId, | |
| 62 | OwnedUserId, | |
| 63 | RoomId, | |
| 64 | UserId, | |
| 65 | 66 | }, |
| 66 | RoomState as MatrixRoomState, | |
| 67 | 67 | }; |
| 68 | 68 | |
| 69 | 69 | use modalkit::{ |
| @@ -77,7 +77,7 @@ use modalkit::{ | ||
| 77 | 77 | ApplicationStore, |
| 78 | 78 | ApplicationWindowId, |
| 79 | 79 | }, |
| 80 | completion::{complete_path, Completer, CompletionMap}, | |
| 80 | completion::{Completer, CompletionMap, complete_path}, | |
| 81 | 81 | context::EditContext, |
| 82 | 82 | cursor::Cursor, |
| 83 | 83 | rope::EditRope, |
| @@ -97,7 +97,7 @@ use crate::{ | ||
| 97 | 97 | config::{ApplicationSettings, ImagePreviewProtocolValues}, |
| 98 | 98 | message::{Message, MessageEvent, MessageKey, MessageTimeStamp, Messages}, |
| 99 | 99 | notifications::NotificationHandle, |
| 100 | preview::{source_from_event, PreviewManager}, | |
| 100 | preview::{PreviewManager, source_from_event}, | |
| 101 | 101 | worker::Requester, |
| 102 | 102 | }; |
| 103 | 103 | |
| @@ -1175,11 +1175,11 @@ impl RoomInfo { | ||
| 1175 | 1175 | } |
| 1176 | 1176 | }, |
| 1177 | 1177 | Some(EventLocation::Message(Some(root), key)) => { |
| 1178 | if let Some(thread) = self.threads.get_mut(root) { | |
| 1179 | if let Some(msg) = thread.get_mut(key) { | |
| 1180 | let ev = SyncRoomRedactionEvent::Original(ev); | |
| 1181 | msg.redact(ev); | |
| 1182 | } | |
| 1178 | if let Some(thread) = self.threads.get_mut(root) && | |
| 1179 | let Some(msg) = thread.get_mut(key) | |
| 1180 | { | |
| 1181 | let ev = SyncRoomRedactionEvent::Original(ev); | |
| 1182 | msg.redact(ev); | |
| 1183 | 1183 | } |
| 1184 | 1184 | }, |
| 1185 | 1185 | Some(EventLocation::Reaction(event_id)) => { |
| @@ -1403,13 +1403,12 @@ impl RoomInfo { | ||
| 1403 | 1403 | let source = source_from_event(&ev); |
| 1404 | 1404 | self.insert(ev); |
| 1405 | 1405 | |
| 1406 | if let Some((event_id, source)) = source { | |
| 1407 | if let (Some(msg), Some(image_preview)) = | |
| 1406 | if let Some((event_id, source)) = source && | |
| 1407 | let (Some(msg), Some(image_preview)) = | |
| 1408 | 1408 | (self.get_event_mut(&event_id), &settings.tunables.image_preview) |
| 1409 | { | |
| 1410 | msg.image_preview = Some(source.clone()); | |
| 1411 | previews.register_preview(settings, source, image_preview.size, worker) | |
| 1412 | } | |
| 1409 | { | |
| 1410 | msg.image_preview = Some(source.clone()); | |
| 1411 | previews.register_preview(settings, source, image_preview.size, worker) | |
| 1413 | 1412 | } |
| 1414 | 1413 | } |
| 1415 | 1414 | |
| @@ -1622,7 +1621,9 @@ fn picker_from_termios(protocol_type: Option<ProtocolType>) -> Option<Picker> { | ||
| 1622 | 1621 | /// Windows cannot guess the right protocol, and always needs type and font_size. |
| 1623 | 1622 | #[cfg(windows)] |
| 1624 | 1623 | fn picker_from_termios(_: Option<ProtocolType>) -> Option<Picker> { |
| 1625 | tracing::error!("\"image_preview\" requires \"protocol\" with \"type\" and \"font_size\" options on Windows."); | |
| 1624 | tracing::error!( | |
| 1625 | "\"image_preview\" requires \"protocol\" with \"type\" and \"font_size\" options on Windows." | |
| 1626 | ); | |
| 1626 | 1627 | None |
| 1627 | 1628 | } |
| 1628 | 1629 | |
| @@ -2360,9 +2361,9 @@ pub mod tests { | ||
| 2360 | 2361 | use crate::config::user_style_from_color; |
| 2361 | 2362 | use crate::tests::*; |
| 2362 | 2363 | use matrix_sdk::ruma::{ |
| 2364 | MilliSecondsSinceUnixEpoch, | |
| 2363 | 2365 | events::{reaction::ReactionEventContent, relation::Annotation}, |
| 2364 | 2366 | owned_event_id, |
| 2365 | MilliSecondsSinceUnixEpoch, | |
| 2366 | 2367 | }; |
| 2367 | 2368 | use pretty_assertions::assert_eq; |
| 2368 | 2369 | use ratatui::style::Color; |
src/commands.rs +4 −4
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | //! [modalkit::env::vim::command] for additional Vim commands we pull in. |
| 5 | 5 | use std::{convert::TryFrom, str::FromStr as _}; |
| 6 | 6 | |
| 7 | use matrix_sdk::ruma::{events::tag::TagName, OwnedRoomId, OwnedUserId}; | |
| 7 | use matrix_sdk::ruma::{OwnedRoomId, OwnedUserId, events::tag::TagName}; | |
| 8 | 8 | |
| 9 | 9 | use modalkit::{ |
| 10 | 10 | commands::{CommandError, CommandResult, CommandStep}, |
| @@ -550,7 +550,7 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 550 | 550 | RoomAction::Show(RoomField::CanonicalAlias).into() |
| 551 | 551 | }, |
| 552 | 552 | ("canonicalalias" | "canon", "show", Some(_)) => { |
| 553 | return Result::Err(CommandError::InvalidArgument) | |
| 553 | return Result::Err(CommandError::InvalidArgument); | |
| 554 | 554 | }, |
| 555 | 555 | |
| 556 | 556 | // :room canonicalalias set |
| @@ -558,7 +558,7 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 558 | 558 | RoomAction::Set(RoomField::CanonicalAlias, s).into() |
| 559 | 559 | }, |
| 560 | 560 | ("canonicalalias" | "canon", "set", None) => { |
| 561 | return Result::Err(CommandError::InvalidArgument) | |
| 561 | return Result::Err(CommandError::InvalidArgument); | |
| 562 | 562 | }, |
| 563 | 563 | |
| 564 | 564 | // :room canonicalalias unset |
| @@ -566,7 +566,7 @@ fn iamb_room(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { | ||
| 566 | 566 | RoomAction::Unset(RoomField::CanonicalAlias).into() |
| 567 | 567 | }, |
| 568 | 568 | ("canonicalalias" | "canon", "unset", Some(_)) => { |
| 569 | return Result::Err(CommandError::InvalidArgument) | |
| 569 | return Result::Err(CommandError::InvalidArgument); | |
| 570 | 570 | }, |
| 571 | 571 | |
| 572 | 572 | // :room id show |
src/config.rs +40 −32
| @@ -12,14 +12,14 @@ use std::process; | ||
| 12 | 12 | use std::str::FromStr; |
| 13 | 13 | |
| 14 | 14 | use clap::Parser; |
| 15 | use matrix_sdk::EncryptionState; | |
| 15 | 16 | use matrix_sdk::authentication::matrix::MatrixSession; |
| 16 | 17 | use matrix_sdk::reqwest::header::{HeaderMap, HeaderValue}; |
| 17 | 18 | use matrix_sdk::ruma::{OwnedDeviceId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UserId}; |
| 18 | use matrix_sdk::EncryptionState; | |
| 19 | 19 | use ratatui::style::{Color, Modifier as StyleModifier, Style}; |
| 20 | 20 | use ratatui::text::Span; |
| 21 | 21 | use ratatui_image::picker::ProtocolType; |
| 22 | use serde::{de::Error as SerdeError, de::Visitor, Deserialize, Deserializer, Serialize}; | |
| 22 | use serde::{Deserialize, Deserializer, Serialize, de::Error as SerdeError, de::Visitor}; | |
| 23 | 23 | use url::Url; |
| 24 | 24 | |
| 25 | 25 | use modalkit::{env::vim::VimMode, key::TerminalKey, keybindings::InputKey}; |
| @@ -428,7 +428,7 @@ impl Visitor<'_> for EncryptionIndicatorLocationVisitor { | ||
| 428 | 428 | "title" => location |= EncryptionIndicatorLocation::TITLE, |
| 429 | 429 | "prompt" => location |= EncryptionIndicatorLocation::PROMPT, |
| 430 | 430 | _ => { |
| 431 | return Err(E::custom("could not parse into an encryption indicator location")) | |
| 431 | return Err(E::custom("could not parse into an encryption indicator location")); | |
| 432 | 432 | }, |
| 433 | 433 | }; |
| 434 | 434 | } |
| @@ -511,7 +511,7 @@ impl Visitor<'_> for NotifyViaVisitor { | ||
| 511 | 511 | }, |
| 512 | 512 | #[cfg(not(feature = "desktop"))] |
| 513 | 513 | "desktop" => { |
| 514 | return Err(E::custom("desktop notification support was compiled out")) | |
| 514 | return Err(E::custom("desktop notification support was compiled out")); | |
| 515 | 515 | }, |
| 516 | 516 | _ => return Err(E::custom("could not parse into a notify destination")), |
| 517 | 517 | }; |
| @@ -1231,10 +1231,10 @@ impl ApplicationSettings { | ||
| 1231 | 1231 | For more information try '--help'", |
| 1232 | 1232 | ); |
| 1233 | 1233 | } |
| 1234 | if let Ok(i) = input.trim().parse::<usize>() { | |
| 1235 | if i < profiles.len() { | |
| 1236 | break profiles.into_iter().nth(i).unwrap(); | |
| 1237 | } | |
| 1234 | if let Ok(i) = input.trim().parse::<usize>() && | |
| 1235 | i < profiles.len() | |
| 1236 | { | |
| 1237 | break profiles.into_iter().nth(i).unwrap(); | |
| 1238 | 1238 | } |
| 1239 | 1239 | println!("\nInvalid index."); |
| 1240 | 1240 | } |
| @@ -1749,16 +1749,18 @@ mod tests { | ||
| 1749 | 1749 | |
| 1750 | 1750 | // Always shows in the title: |
| 1751 | 1751 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_some()); |
| 1752 | assert!(enc | |
| 1753 | .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1754 | .is_some()); | |
| 1752 | assert!( | |
| 1753 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1754 | .is_some() | |
| 1755 | ); | |
| 1755 | 1756 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some()); |
| 1756 | 1757 | |
| 1757 | 1758 | // Doesn't show in the prompt: |
| 1758 | 1759 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); |
| 1759 | assert!(enc | |
| 1760 | .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1761 | .is_none()); | |
| 1760 | assert!( | |
| 1761 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1762 | .is_none() | |
| 1763 | ); | |
| 1762 | 1764 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none()); |
| 1763 | 1765 | } |
| 1764 | 1766 | |
| @@ -1773,14 +1775,16 @@ mod tests { | ||
| 1773 | 1775 | |
| 1774 | 1776 | // Never shows in the title or the prompt: |
| 1775 | 1777 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); |
| 1776 | assert!(enc | |
| 1777 | .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1778 | .is_none()); | |
| 1778 | assert!( | |
| 1779 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1780 | .is_none() | |
| 1781 | ); | |
| 1779 | 1782 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none()); |
| 1780 | 1783 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none()); |
| 1781 | assert!(enc | |
| 1782 | .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1783 | .is_none()); | |
| 1784 | assert!( | |
| 1785 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1786 | .is_none() | |
| 1787 | ); | |
| 1784 | 1788 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none()); |
| 1785 | 1789 | } |
| 1786 | 1790 | |
| @@ -1798,15 +1802,17 @@ mod tests { | ||
| 1798 | 1802 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some()); |
| 1799 | 1803 | |
| 1800 | 1804 | // But is hidden when unencrypted: |
| 1801 | assert!(enc | |
| 1802 | .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1803 | .is_none()); | |
| 1805 | assert!( | |
| 1806 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1807 | .is_none() | |
| 1808 | ); | |
| 1804 | 1809 | |
| 1805 | 1810 | // Doesn't show in the title: |
| 1806 | 1811 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none()); |
| 1807 | assert!(enc | |
| 1808 | .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1809 | .is_none()); | |
| 1812 | assert!( | |
| 1813 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1814 | .is_none() | |
| 1815 | ); | |
| 1810 | 1816 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none()); |
| 1811 | 1817 | } |
| 1812 | 1818 | #[test] |
| @@ -1819,13 +1825,15 @@ mod tests { | ||
| 1819 | 1825 | }; |
| 1820 | 1826 | |
| 1821 | 1827 | // Shows in both the prompt and title when unencrypted or unknown: |
| 1822 | assert!(enc | |
| 1823 | .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1824 | .is_some()); | |
| 1828 | assert!( | |
| 1829 | enc.get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted) | |
| 1830 | .is_some() | |
| 1831 | ); | |
| 1825 | 1832 | assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some()); |
| 1826 | assert!(enc | |
| 1827 | .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1828 | .is_some()); | |
| 1833 | assert!( | |
| 1834 | enc.get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted) | |
| 1835 | .is_some() | |
| 1836 | ); | |
| 1829 | 1837 | assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some()); |
| 1830 | 1838 | |
| 1831 | 1839 | // But is hidden when encrypted: |
src/keybindings.rs +14 −15
| @@ -4,9 +4,9 @@ | ||
| 4 | 4 | //! keys come from [modalkit::env::vim::keybindings]. |
| 5 | 5 | use modalkit::{ |
| 6 | 6 | actions::{InsertTextAction, MacroAction, WindowAction}, |
| 7 | env::vim::keybindings::{InputStep, VimBindings}, | |
| 8 | env::vim::VimMode, | |
| 9 | 7 | env::CommonKeyClass, |
| 8 | env::vim::VimMode, | |
| 9 | env::vim::keybindings::{InputStep, VimBindings}, | |
| 10 | 10 | key::TerminalKey, |
| 11 | 11 | keybindings::{EdgeEvent, EdgeRepeat, InputBindings}, |
| 12 | 12 | prelude::*, |
| @@ -60,12 +60,9 @@ pub fn setup_keybindings() -> Keybindings { | ||
| 60 | 60 | ism.add_mapping(VimMode::Visual, &cwcm, &stoggle); |
| 61 | 61 | |
| 62 | 62 | let shift_enter = vec![once(&shift_enter)]; |
| 63 | let newline = IambStep::new().actions(vec![InsertTextAction::Type( | |
| 64 | Char::Single('\n').into(), | |
| 65 | MoveDir1D::Previous, | |
| 66 | 1.into(), | |
| 67 | ) | |
| 68 | .into()]); | |
| 63 | let newline = IambStep::new().actions(vec![ | |
| 64 | InsertTextAction::Type(Char::Single('\n').into(), MoveDir1D::Previous, 1.into()).into(), | |
| 65 | ]); | |
| 69 | 66 | ism.add_mapping(VimMode::Insert, &cwm, &newline); |
| 70 | 67 | ism.add_mapping(VimMode::Insert, &shift_enter, &newline); |
| 71 | 68 | |
| @@ -92,13 +89,15 @@ impl InputBindings<TerminalKey, IambStep> for ApplicationSettings { | ||
| 92 | 89 | let ctrl_f = "<C-F>".parse::<TerminalKey>().unwrap(); |
| 93 | 90 | |
| 94 | 91 | let vsplit_open = IambStep::new() |
| 95 | .actions(vec![WindowAction::Split( | |
| 96 | OpenTarget::Cursor(MATRIX_ID_WORD.clone()), | |
| 97 | Axis::Vertical, | |
| 98 | MoveDir1D::Next, | |
| 99 | 1.into(), | |
| 100 | ) | |
| 101 | .into()]) | |
| 92 | .actions(vec![ | |
| 93 | WindowAction::Split( | |
| 94 | OpenTarget::Cursor(MATRIX_ID_WORD.clone()), | |
| 95 | Axis::Vertical, | |
| 96 | MoveDir1D::Next, | |
| 97 | 1.into(), | |
| 98 | ) | |
| 99 | .into(), | |
| 100 | ]) | |
| 102 | 101 | .goto(VimMode::Normal); |
| 103 | 102 | |
| 104 | 103 | let cwf = vec![once(&ctrl_w), once(&key_f)]; |
src/main.rs +17 −14
| @@ -19,21 +19,21 @@ | ||
| 19 | 19 | use std::collections::VecDeque; |
| 20 | 20 | use std::convert::TryFrom; |
| 21 | 21 | use std::fmt::Display; |
| 22 | use std::fs::{create_dir_all, File}; | |
| 23 | use std::io::{stdout, BufWriter, Stdout, Write}; | |
| 22 | use std::fs::{File, create_dir_all}; | |
| 23 | use std::io::{BufWriter, Stdout, Write, stdout}; | |
| 24 | 24 | use std::ops::DerefMut; |
| 25 | 25 | use std::process; |
| 26 | use std::sync::atomic::{AtomicUsize, Ordering}; | |
| 27 | 26 | use std::sync::Arc; |
| 27 | use std::sync::atomic::{AtomicUsize, Ordering}; | |
| 28 | 28 | use std::time::{Duration, Instant}; |
| 29 | 29 | |
| 30 | 30 | use clap::{CommandFactory, Parser}; |
| 31 | use matrix_sdk::ruma::api::error::ErrorKind; | |
| 32 | 31 | use matrix_sdk::ruma::OwnedUserId; |
| 32 | use matrix_sdk::ruma::api::error::ErrorKind; | |
| 33 | 33 | use matrix_sdk_crypto::encrypt_room_key_export; |
| 34 | 34 | use modalkit::keybindings::InputBindings; |
| 35 | use rand::distr::Alphanumeric; | |
| 36 | 35 | use rand::RngExt as _; |
| 36 | use rand::distr::Alphanumeric; | |
| 37 | 37 | use temp_dir::TempDir; |
| 38 | 38 | use tokio::sync::Mutex as AsyncMutex; |
| 39 | 39 | use tracing::Level; |
| @@ -43,8 +43,6 @@ use modalkit::crossterm::{ | ||
| 43 | 43 | self, |
| 44 | 44 | cursor::{SetCursorStyle, Show as CursorShow}, |
| 45 | 45 | event::{ |
| 46 | poll, | |
| 47 | read, | |
| 48 | 46 | DisableBracketedPaste, |
| 49 | 47 | DisableFocusChange, |
| 50 | 48 | DisableMouseCapture, |
| @@ -57,18 +55,20 @@ use modalkit::crossterm::{ | ||
| 57 | 55 | MouseEventKind, |
| 58 | 56 | PopKeyboardEnhancementFlags, |
| 59 | 57 | PushKeyboardEnhancementFlags, |
| 58 | poll, | |
| 59 | read, | |
| 60 | 60 | }, |
| 61 | 61 | execute, |
| 62 | 62 | terminal::{EnterAlternateScreen, LeaveAlternateScreen, SetTitle}, |
| 63 | 63 | }; |
| 64 | 64 | |
| 65 | 65 | use ratatui::{ |
| 66 | Terminal, | |
| 66 | 67 | backend::CrosstermBackend, |
| 67 | 68 | layout::Rect, |
| 68 | 69 | style::{Color, Modifier, Style}, |
| 69 | 70 | text::Span, |
| 70 | 71 | widgets::Paragraph, |
| 71 | Terminal, | |
| 72 | 72 | }; |
| 73 | 73 | |
| 74 | 74 | mod base; |
| @@ -104,7 +104,7 @@ use crate::{ | ||
| 104 | 104 | }, |
| 105 | 105 | config::{ApplicationSettings, Iamb}, |
| 106 | 106 | windows::IambWindow, |
| 107 | worker::{create_room, ClientWorker, LoginStyle, Requester}, | |
| 107 | worker::{ClientWorker, LoginStyle, Requester, create_room}, | |
| 108 | 108 | }; |
| 109 | 109 | |
| 110 | 110 | use modalkit::{ |
| @@ -127,20 +127,20 @@ use modalkit::{ | ||
| 127 | 127 | errors::{EditError, UIError}, |
| 128 | 128 | key::TerminalKey, |
| 129 | 129 | keybindings::{ |
| 130 | dialog::{Pager, PromptYesNo}, | |
| 131 | 130 | BindingMachine, |
| 131 | dialog::{Pager, PromptYesNo}, | |
| 132 | 132 | }, |
| 133 | 133 | prelude::*, |
| 134 | 134 | ui::FocusList, |
| 135 | 135 | }; |
| 136 | 136 | |
| 137 | 137 | use modalkit_ratatui::{ |
| 138 | cmdbar::CommandBarState, | |
| 139 | screen::{Screen, ScreenState, TabbedLayoutDescription}, | |
| 140 | windows::{WindowLayoutDescription, WindowLayoutState}, | |
| 141 | 138 | TerminalCursor, |
| 142 | 139 | TerminalExtOps, |
| 143 | 140 | Window, |
| 141 | cmdbar::CommandBarState, | |
| 142 | screen::{Screen, ScreenState, TabbedLayoutDescription}, | |
| 143 | windows::{WindowLayoutDescription, WindowLayoutState}, | |
| 144 | 144 | }; |
| 145 | 145 | |
| 146 | 146 | fn config_tab_to_desc( |
| @@ -1059,7 +1059,10 @@ async fn run(settings: ApplicationSettings) -> IambResult<()> { | ||
| 1059 | 1059 | match res { |
| 1060 | 1060 | Err(UIError::Application(IambError::Matrix(e))) => { |
| 1061 | 1061 | if let Some(ErrorKind::UnknownToken { .. }) = e.client_api_error_kind() { |
| 1062 | print_exit(format!("Server did not recognize our API token; did you log out from this session elsewhere?\nTry deleting `{}` to force a clean login.", settings.session_json.display())) | |
| 1062 | print_exit(format!( | |
| 1063 | "Server did not recognize our API token; did you log out from this session elsewhere?\nTry deleting `{}` to force a clean login.", | |
| 1064 | settings.session_json.display() | |
| 1065 | )) | |
| 1063 | 1066 | } else { |
| 1064 | 1067 | print_exit(e) |
| 1065 | 1068 | } |
src/message/compose.rs +2 −2
| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | //! Code for converting composed messages into content to send to the homeserver. |
| 2 | 2 | use comrak::{markdown_to_html, options::Options}; |
| 3 | 3 | use nom::{ |
| 4 | IResult, | |
| 5 | Parser as _, | |
| 4 | 6 | branch::alt, |
| 5 | 7 | bytes::complete::tag, |
| 6 | 8 | character::complete::space0, |
| 7 | 9 | combinator::value, |
| 8 | IResult, | |
| 9 | Parser as _, | |
| 10 | 10 | }; |
| 11 | 11 | |
| 12 | 12 | use matrix_sdk::ruma::events::room::message::{ |
src/message/html.rs +1 −1
| @@ -20,7 +20,7 @@ use unicode_segmentation::UnicodeSegmentation; | ||
| 20 | 20 | use url::Url; |
| 21 | 21 | |
| 22 | 22 | use html5ever::{ |
| 23 | driver::{parse_fragment, ParseOpts}, | |
| 23 | driver::{ParseOpts, parse_fragment}, | |
| 24 | 24 | interface::{Attribute, QualName}, |
| 25 | 25 | local_name, |
| 26 | 26 | ns, |
src/message/mod.rs +26 −28
| @@ -1,25 +1,32 @@ | ||
| 1 | 1 | //! # Room Messages |
| 2 | 2 | use std::borrow::Cow; |
| 3 | 3 | use std::cmp::{Ord, Ordering, PartialOrd}; |
| 4 | use std::collections::hash_map::DefaultHasher; | |
| 5 | 4 | use std::collections::BTreeMap; |
| 5 | use std::collections::hash_map::DefaultHasher; | |
| 6 | 6 | use std::convert::{TryFrom, TryInto}; |
| 7 | 7 | use std::fmt::{self, Display}; |
| 8 | 8 | use std::hash::{Hash, Hasher}; |
| 9 | 9 | use std::ops::{Deref, DerefMut}; |
| 10 | 10 | |
| 11 | 11 | use chrono::{DateTime, Local as LocalTz}; |
| 12 | use humansize::{format_size, DECIMAL}; | |
| 12 | use humansize::{DECIMAL, format_size}; | |
| 13 | use matrix_sdk::ruma::OwnedTransactionId; | |
| 13 | 14 | use matrix_sdk::ruma::events::receipt::ReceiptThread; |
| 14 | 15 | use matrix_sdk::ruma::events::room::MediaSource; |
| 15 | 16 | use matrix_sdk::ruma::events::sticker::StickerEvent; |
| 16 | 17 | use matrix_sdk::ruma::events::{AnyRedactionEvent, MessageLikeEvent}; |
| 17 | use matrix_sdk::ruma::OwnedTransactionId; | |
| 18 | 18 | use matrix_sdk::send_queue::SendHandle; |
| 19 | 19 | use unicode_width::UnicodeWidthStr; |
| 20 | 20 | |
| 21 | 21 | use matrix_sdk::ruma::{ |
| 22 | EventId, | |
| 23 | MilliSecondsSinceUnixEpoch, | |
| 24 | OwnedEventId, | |
| 25 | OwnedUserId, | |
| 26 | UInt, | |
| 22 | 27 | events::{ |
| 28 | AnySyncStateEvent, | |
| 29 | RedactedUnsigned, | |
| 23 | 30 | relation::Thread, |
| 24 | 31 | room::{ |
| 25 | 32 | encrypted::{ |
| @@ -39,14 +46,7 @@ use matrix_sdk::ruma::{ | ||
| 39 | 46 | }, |
| 40 | 47 | redaction::SyncRoomRedactionEvent, |
| 41 | 48 | }, |
| 42 | AnySyncStateEvent, | |
| 43 | RedactedUnsigned, | |
| 44 | 49 | }, |
| 45 | EventId, | |
| 46 | MilliSecondsSinceUnixEpoch, | |
| 47 | OwnedEventId, | |
| 48 | OwnedUserId, | |
| 49 | UInt, | |
| 50 | 50 | }; |
| 51 | 51 | |
| 52 | 52 | use ratatui::{ |
| @@ -64,7 +64,7 @@ use crate::preview::{ImageStatus, PreviewManager}; | ||
| 64 | 64 | use crate::{ |
| 65 | 65 | base::RoomInfo, |
| 66 | 66 | config::ApplicationSettings, |
| 67 | message::html::{parse_matrix_html, StyleTree}, | |
| 67 | message::html::{StyleTree, parse_matrix_html}, | |
| 68 | 68 | util::{replace_emojis_in_str, space, space_span, take_width, wrapped_text}, |
| 69 | 69 | }; |
| 70 | 70 | |
| @@ -188,13 +188,12 @@ fn placeholder_frame( | ||
| 188 | 188 | placeholder.push('\u{230d}'); |
| 189 | 189 | placeholder.push_str(&"\n".repeat((height - 1) / 2)); |
| 190 | 190 | |
| 191 | if *height > 2 { | |
| 192 | if let Some(text) = text { | |
| 193 | if text.width() <= width - 2 { | |
| 194 | placeholder.push(' '); | |
| 195 | placeholder.push_str(text); | |
| 196 | } | |
| 197 | } | |
| 191 | if *height > 2 && | |
| 192 | let Some(text) = text && | |
| 193 | text.width() <= width - 2 | |
| 194 | { | |
| 195 | placeholder.push(' '); | |
| 196 | placeholder.push_str(text); | |
| 198 | 197 | } |
| 199 | 198 | |
| 200 | 199 | placeholder.push_str(&"\n".repeat(height / 2)); |
| @@ -239,7 +238,7 @@ pub struct MessageTimeStamp(pub MilliSecondsSinceUnixEpoch); | ||
| 239 | 238 | |
| 240 | 239 | impl MessageTimeStamp { |
| 241 | 240 | fn as_datetime(self) -> DateTime<LocalTz> { |
| 242 | let time = i64::from(self.0 .0) / 1000; | |
| 241 | let time = i64::from(self.0.0) / 1000; | |
| 243 | 242 | let time = DateTime::from_timestamp(time, 0).unwrap_or_default(); |
| 244 | 243 | time.into() |
| 245 | 244 | } |
| @@ -275,7 +274,7 @@ impl TryFrom<&MessageTimeStamp> for usize { | ||
| 275 | 274 | type Error = TimeStampIntError; |
| 276 | 275 | |
| 277 | 276 | fn try_from(ts: &MessageTimeStamp) -> Result<Self, Self::Error> { |
| 278 | let n = usize::try_from(u64::from(ts.0 .0))?; | |
| 277 | let n = usize::try_from(u64::from(ts.0.0))?; | |
| 279 | 278 | |
| 280 | 279 | Ok(n) |
| 281 | 280 | } |
| @@ -1154,13 +1153,12 @@ impl Message { | ||
| 1154 | 1153 | settings: &'a ApplicationSettings, |
| 1155 | 1154 | width: usize, |
| 1156 | 1155 | ) -> SenderSpan<'a> { |
| 1157 | if let Some(prev) = prev { | |
| 1158 | if self.sender == prev.sender && | |
| 1159 | self.timestamp.same_day(prev.timestamp) && | |
| 1160 | !self.event.is_emote() | |
| 1161 | { | |
| 1162 | return SenderSpan::None; | |
| 1163 | } | |
| 1156 | if let Some(prev) = prev && | |
| 1157 | self.sender == prev.sender && | |
| 1158 | self.timestamp.same_day(prev.timestamp) && | |
| 1159 | !self.event.is_emote() | |
| 1160 | { | |
| 1161 | return SenderSpan::None; | |
| 1164 | 1162 | } |
| 1165 | 1163 | |
| 1166 | 1164 | let Span { content, style } = self.sender_span(info, settings); |
| @@ -1266,6 +1264,7 @@ impl Display for Message { | ||
| 1266 | 1264 | #[cfg(test)] |
| 1267 | 1265 | pub mod tests { |
| 1268 | 1266 | use matrix_sdk::ruma::events::room::{ |
| 1267 | ImageInfo, | |
| 1269 | 1268 | message::{ |
| 1270 | 1269 | AudioInfo, |
| 1271 | 1270 | AudioMessageEventContent, |
| @@ -1275,7 +1274,6 @@ pub mod tests { | ||
| 1275 | 1274 | VideoInfo, |
| 1276 | 1275 | VideoMessageEventContent, |
| 1277 | 1276 | }, |
| 1278 | ImageInfo, | |
| 1279 | 1277 | }; |
| 1280 | 1278 | |
| 1281 | 1279 | use super::*; |
src/message/state.rs +3 −3
| @@ -3,14 +3,14 @@ use std::borrow::Cow; | ||
| 3 | 3 | use std::str::FromStr; |
| 4 | 4 | |
| 5 | 5 | use matrix_sdk::ruma::{ |
| 6 | OwnedRoomId, | |
| 7 | UserId, | |
| 6 | 8 | events::{ |
| 7 | room::member::MembershipChange, | |
| 8 | 9 | AnyStateEventContentChange, |
| 9 | 10 | AnySyncStateEvent, |
| 10 | 11 | StateEventContentChange, |
| 12 | room::member::MembershipChange, | |
| 11 | 13 | }, |
| 12 | OwnedRoomId, | |
| 13 | UserId, | |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | 16 | use super::html::{StyleTree, StyleTreeNode}; |
src/notifications.rs +12 −12
| @@ -1,18 +1,18 @@ | ||
| 1 | 1 | use std::time::SystemTime; |
| 2 | 2 | |
| 3 | 3 | use matrix_sdk::{ |
| 4 | Client, | |
| 5 | EncryptionState, | |
| 4 | 6 | deserialized_responses::RawAnySyncOrStrippedTimelineEvent, |
| 5 | 7 | notification_settings::{IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode}, |
| 6 | 8 | room::Room as MatrixRoom, |
| 7 | 9 | ruma::{ |
| 8 | events::{room::message::MessageType, AnyMessageLikeEventContent, AnySyncTimelineEvent}, | |
| 9 | serde::Raw, | |
| 10 | 10 | MilliSecondsSinceUnixEpoch, |
| 11 | 11 | OwnedRoomId, |
| 12 | 12 | RoomId, |
| 13 | events::{AnyMessageLikeEventContent, AnySyncTimelineEvent, room::message::MessageType}, | |
| 14 | serde::Raw, | |
| 13 | 15 | }, |
| 14 | Client, | |
| 15 | EncryptionState, | |
| 16 | 16 | }; |
| 17 | 17 | use unicode_segmentation::UnicodeSegmentation; |
| 18 | 18 | |
| @@ -208,14 +208,14 @@ async fn global_or_room_mode( | ||
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | fn is_missing_mention(body: &Option<String>, mode: RoomNotificationMode, client: &Client) -> bool { |
| 211 | if let Some(body) = body { | |
| 212 | if mode == RoomNotificationMode::MentionsAndKeywordsOnly { | |
| 213 | let mentioned = match client.user_id() { | |
| 214 | Some(user_id) => body.contains(user_id.localpart()), | |
| 215 | _ => false, | |
| 216 | }; | |
| 217 | return !mentioned; | |
| 218 | } | |
| 211 | if let Some(body) = body && | |
| 212 | mode == RoomNotificationMode::MentionsAndKeywordsOnly | |
| 213 | { | |
| 214 | let mentioned = match client.user_id() { | |
| 215 | Some(user_id) => body.contains(user_id.localpart()), | |
| 216 | _ => false, | |
| 217 | }; | |
| 218 | return !mentioned; | |
| 219 | 219 | } |
| 220 | 220 | false |
| 221 | 221 | } |
src/preview.rs +9 −9
| @@ -1,21 +1,21 @@ | ||
| 1 | 1 | use std::{collections::HashMap, sync::Arc}; |
| 2 | 2 | |
| 3 | 3 | use matrix_sdk::{ |
| 4 | Media, | |
| 4 | 5 | media::{MediaFormat, MediaRequestParameters, UniqueKey}, |
| 5 | 6 | ruma::{ |
| 7 | OwnedEventId, | |
| 6 | 8 | events::{ |
| 9 | MessageLikeEvent, | |
| 7 | 10 | room::{ |
| 8 | message::{MessageType, RoomMessageEventContent}, | |
| 9 | 11 | MediaSource, |
| 12 | message::{MessageType, RoomMessageEventContent}, | |
| 10 | 13 | }, |
| 11 | MessageLikeEvent, | |
| 12 | 14 | }, |
| 13 | OwnedEventId, | |
| 14 | 15 | }, |
| 15 | Media, | |
| 16 | 16 | }; |
| 17 | 17 | use ratatui::layout::Rect; |
| 18 | use ratatui_image::{picker::Picker, protocol::Protocol, Resize}; | |
| 18 | use ratatui_image::{Resize, picker::Picker, protocol::Protocol}; | |
| 19 | 19 | use tokio::sync::Semaphore; |
| 20 | 20 | |
| 21 | 21 | use crate::{ |
| @@ -110,10 +110,10 @@ impl PreviewManager { | ||
| 110 | 110 | pub fn source_from_event( |
| 111 | 111 | ev: &MessageLikeEvent<RoomMessageEventContent>, |
| 112 | 112 | ) -> Option<(OwnedEventId, MediaSource)> { |
| 113 | if let MessageLikeEvent::Original(ev) = &ev { | |
| 114 | if let MessageType::Image(c) = &ev.content.msgtype { | |
| 115 | return Some((ev.event_id.clone(), c.source.clone())); | |
| 116 | } | |
| 113 | if let MessageLikeEvent::Original(ev) = &ev && | |
| 114 | let MessageType::Image(c) = &ev.content.msgtype | |
| 115 | { | |
| 116 | return Some((ev.event_id.clone(), c.source.clone())); | |
| 117 | 117 | } |
| 118 | 118 | None |
| 119 | 119 | } |
src/tests.rs +4 −4
| @@ -3,16 +3,16 @@ use std::{collections::HashMap, iter::FromIterator as _}; | ||
| 3 | 3 | |
| 4 | 4 | use matrix_sdk::ruma::MilliSecondsSinceUnixEpoch; |
| 5 | 5 | use matrix_sdk::ruma::{ |
| 6 | event_id, | |
| 7 | events::room::message::RoomMessageEventContent, | |
| 8 | server_name, | |
| 9 | user_id, | |
| 10 | 6 | EventId, |
| 11 | 7 | OwnedEventId, |
| 12 | 8 | OwnedRoomId, |
| 13 | 9 | OwnedUserId, |
| 14 | 10 | RoomId, |
| 15 | 11 | UInt, |
| 12 | event_id, | |
| 13 | events::room::message::RoomMessageEventContent, | |
| 14 | server_name, | |
| 15 | user_id, | |
| 16 | 16 | }; |
| 17 | 17 | |
| 18 | 18 | use lazy_static::lazy_static; |
src/windows/mod.rs +15 −17
| @@ -13,17 +13,17 @@ use std::sync::Arc; | ||
| 13 | 13 | use std::time::{Duration, Instant}; |
| 14 | 14 | |
| 15 | 15 | use matrix_sdk::{ |
| 16 | encryption::verification::{format_emojis, SasVerification}, | |
| 16 | RoomState as MatrixRoomState, | |
| 17 | encryption::verification::{SasVerification, format_emojis}, | |
| 17 | 18 | room::{Room as MatrixRoom, RoomMember}, |
| 18 | 19 | ruma::{ |
| 19 | events::room::member::MembershipState, | |
| 20 | events::tag::{TagName, Tags}, | |
| 21 | 20 | OwnedRoomAliasId, |
| 22 | 21 | OwnedRoomId, |
| 23 | 22 | RoomAliasId, |
| 24 | 23 | RoomId, |
| 24 | events::room::member::MembershipState, | |
| 25 | events::tag::{TagName, Tags}, | |
| 25 | 26 | }, |
| 26 | RoomState as MatrixRoomState, | |
| 27 | 27 | }; |
| 28 | 28 | |
| 29 | 29 | use ratatui::{ |
| @@ -51,11 +51,11 @@ use modalkit::{ | ||
| 51 | 51 | }; |
| 52 | 52 | |
| 53 | 53 | use modalkit_ratatui::{ |
| 54 | list::{List, ListCursor, ListItem, ListState}, | |
| 55 | 54 | TermOffset, |
| 56 | 55 | TerminalCursor, |
| 57 | 56 | Window, |
| 58 | 57 | WindowOps, |
| 58 | list::{List, ListCursor, ListItem, ListState}, | |
| 59 | 59 | }; |
| 60 | 60 | |
| 61 | 61 | use crate::base::{ |
| @@ -576,17 +576,15 @@ impl WindowOps<IambInfo> for IambWindow { | ||
| 576 | 576 | None => true, |
| 577 | 577 | }; |
| 578 | 578 | |
| 579 | if need_fetch { | |
| 580 | if let Ok(mems) = store.application.worker.members(room_id.clone()) { | |
| 581 | let mut items = mems | |
| 582 | .into_iter() | |
| 583 | .map(|m| MemberItem::new(m, room_id.clone())) | |
| 584 | .collect::<Vec<_>>(); | |
| 585 | let fields = &store.application.settings.tunables.sort.members; | |
| 586 | items.sort_by(|a, b| user_fields_cmp(a, b, fields)); | |
| 587 | state.set(items); | |
| 588 | *last_fetch = Some(Instant::now()); | |
| 589 | } | |
| 579 | if need_fetch && let Ok(mems) = store.application.worker.members(room_id.clone()) { | |
| 580 | let mut items = mems | |
| 581 | .into_iter() | |
| 582 | .map(|m| MemberItem::new(m, room_id.clone())) | |
| 583 | .collect::<Vec<_>>(); | |
| 584 | let fields = &store.application.settings.tunables.sort.members; | |
| 585 | items.sort_by(|a, b| user_fields_cmp(a, b, fields)); | |
| 586 | state.set(items); | |
| 587 | *last_fetch = Some(Instant::now()); | |
| 590 | 588 | } |
| 591 | 589 | |
| 592 | 590 | List::new(store) |
| @@ -1743,7 +1741,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for MemberItem { | ||
| 1743 | 1741 | #[cfg(test)] |
| 1744 | 1742 | mod tests { |
| 1745 | 1743 | use super::*; |
| 1746 | use matrix_sdk::ruma::{room_alias_id, server_name, MilliSecondsSinceUnixEpoch}; | |
| 1744 | use matrix_sdk::ruma::{MilliSecondsSinceUnixEpoch, room_alias_id, server_name}; | |
| 1747 | 1745 | |
| 1748 | 1746 | #[derive(Debug, Eq, PartialEq)] |
| 1749 | 1747 | struct TestRoomItem { |
src/windows/room/chat.rs +18 −14
| @@ -5,18 +5,22 @@ use std::fs; | ||
| 5 | 5 | use std::ops::Deref; |
| 6 | 6 | use std::path::{Path, PathBuf}; |
| 7 | 7 | |
| 8 | use edit::edit_with_builder as external_edit; | |
| 9 | 8 | use edit::Builder; |
| 9 | use edit::edit_with_builder as external_edit; | |
| 10 | 10 | use modalkit::editing::store::RegisterError; |
| 11 | 11 | use std::process::Command; |
| 12 | 12 | use tokio; |
| 13 | 13 | use url::Url; |
| 14 | 14 | |
| 15 | 15 | use matrix_sdk::{ |
| 16 | RoomState, | |
| 16 | 17 | attachment::AttachmentConfig, |
| 17 | 18 | media::{MediaFormat, MediaRequestParameters}, |
| 18 | 19 | room::Room as MatrixRoom, |
| 19 | 20 | ruma::{ |
| 21 | OwnedEventId, | |
| 22 | OwnedRoomId, | |
| 23 | RoomId, | |
| 20 | 24 | events::reaction::ReactionEventContent, |
| 21 | 25 | events::relation::{Annotation, Replacement}, |
| 22 | 26 | events::room::message::{ |
| @@ -27,12 +31,8 @@ use matrix_sdk::{ | ||
| 27 | 31 | Relation, |
| 28 | 32 | ReplyWithinThread, |
| 29 | 33 | }, |
| 30 | OwnedEventId, | |
| 31 | OwnedRoomId, | |
| 32 | RoomId, | |
| 33 | 34 | }, |
| 34 | 35 | send_queue::RoomSendQueueError, |
| 35 | RoomState, | |
| 36 | 36 | }; |
| 37 | 37 | |
| 38 | 38 | use ratatui::{ |
| @@ -45,10 +45,10 @@ use ratatui::{ | ||
| 45 | 45 | use modalkit::keybindings::dialog::{MultiChoice, MultiChoiceItem, PromptYesNo}; |
| 46 | 46 | |
| 47 | 47 | use modalkit_ratatui::{ |
| 48 | textbox::{TextBox, TextBoxState}, | |
| 49 | 48 | PromptActions, |
| 50 | 49 | TerminalCursor, |
| 51 | 50 | WindowOps, |
| 51 | textbox::{TextBox, TextBoxState}, | |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | 54 | use modalkit::actions::{ |
| @@ -87,7 +87,7 @@ use crate::base::{ | ||
| 87 | 87 | }; |
| 88 | 88 | |
| 89 | 89 | use crate::config::EncryptionIndicatorLocation; |
| 90 | use crate::message::{text_to_message, MessageEvent, MessageId, MessageKey, TreeGenState}; | |
| 90 | use crate::message::{MessageEvent, MessageId, MessageKey, TreeGenState, text_to_message}; | |
| 91 | 91 | use crate::worker::Requester; |
| 92 | 92 | |
| 93 | 93 | use super::scrollback::{Scrollback, ScrollbackState}; |
| @@ -373,7 +373,9 @@ impl ChatState { | ||
| 373 | 373 | { |
| 374 | 374 | emoji.to_string() |
| 375 | 375 | } else { |
| 376 | let msg = format!("{reaction:?} is not a known Emoji shortcode; do you want to react with exactly {reaction:?}?"); | |
| 376 | let msg = format!( | |
| 377 | "{reaction:?} is not a known Emoji shortcode; do you want to react with exactly {reaction:?}?" | |
| 378 | ); | |
| 377 | 379 | let act = IambAction::Message(MessageAction::React(reaction, true)); |
| 378 | 380 | let prompt = PromptYesNo::new(msg, vec![Action::from(act)]); |
| 379 | 381 | let prompt = Box::new(prompt); |
| @@ -495,7 +497,9 @@ impl ChatState { | ||
| 495 | 497 | { |
| 496 | 498 | Some(emoji.to_string()) |
| 497 | 499 | } else { |
| 498 | let msg = format!("{reaction:?} is not a known Emoji shortcode; do you want to remove exactly {reaction:?}?"); | |
| 500 | let msg = format!( | |
| 501 | "{reaction:?} is not a known Emoji shortcode; do you want to remove exactly {reaction:?}?" | |
| 502 | ); | |
| 499 | 503 | let act = |
| 500 | 504 | IambAction::Message(MessageAction::Unreact(Some(reaction), true)); |
| 501 | 505 | let prompt = PromptYesNo::new(msg, vec![Action::from(act)]); |
| @@ -694,10 +698,10 @@ impl ChatState { | ||
| 694 | 698 | // Jump to the end of the scrollback to show the message. |
| 695 | 699 | self.scrollback.goto_latest(); |
| 696 | 700 | |
| 697 | if tunables.read_receipt_trigger.on_message() { | |
| 698 | if let Some(thread) = self.scrollback.get_thread(info) { | |
| 699 | info.fully_read(settings.profile.user_id.clone(), thread.1.clone()); | |
| 700 | } | |
| 701 | if tunables.read_receipt_trigger.on_message() && | |
| 702 | let Some(thread) = self.scrollback.get_thread(info) | |
| 703 | { | |
| 704 | info.fully_read(settings.profile.user_id.clone(), thread.1.clone()); | |
| 701 | 705 | } |
| 702 | 706 | |
| 703 | 707 | Ok(None) |
| @@ -1158,7 +1162,7 @@ mod tests { | ||
| 1158 | 1162 | |
| 1159 | 1163 | use modalkit::actions::{EditAction, InsertTextAction}; |
| 1160 | 1164 | |
| 1161 | use crate::tests::{mock_store, TEST_ROOM1_ID}; | |
| 1165 | use crate::tests::{TEST_ROOM1_ID, mock_store}; | |
| 1162 | 1166 | |
| 1163 | 1167 | macro_rules! move_line { |
| 1164 | 1168 | ($dir: expr, $count: expr) => { |
src/windows/room/mod.rs +18 −18
| @@ -3,9 +3,15 @@ use std::collections::HashSet; | ||
| 3 | 3 | |
| 4 | 4 | use matrix_sdk::ruma::api::error::ErrorKind as ClientApiErrorKind; |
| 5 | 5 | use matrix_sdk::{ |
| 6 | RoomDisplayName, | |
| 7 | RoomState as MatrixRoomState, | |
| 6 | 8 | notification_settings::RoomNotificationMode, |
| 7 | 9 | room::Room as MatrixRoom, |
| 8 | 10 | ruma::{ |
| 11 | OwnedEventId, | |
| 12 | OwnedRoomAliasId, | |
| 13 | OwnedUserId, | |
| 14 | RoomId, | |
| 9 | 15 | events::{ |
| 10 | 16 | room::{ |
| 11 | 17 | canonical_alias::RoomCanonicalAliasEventContent, |
| @@ -15,13 +21,7 @@ use matrix_sdk::{ | ||
| 15 | 21 | }, |
| 16 | 22 | tag::{TagInfo, Tags}, |
| 17 | 23 | }, |
| 18 | OwnedEventId, | |
| 19 | OwnedRoomAliasId, | |
| 20 | OwnedUserId, | |
| 21 | RoomId, | |
| 22 | 24 | }, |
| 23 | RoomDisplayName, | |
| 24 | RoomState as MatrixRoomState, | |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | use ratatui::{ |
| @@ -230,14 +230,14 @@ pub async fn room_command( | ||
| 230 | 230 | let user_id = store.application.settings.profile.user_id.clone(); |
| 231 | 231 | let info = store.application.get_room_info(id.to_owned()); |
| 232 | 232 | let messages = info.get_thread(None).expect("room main timeline doesn't exist"); |
| 233 | if let Some((key, _)) = messages.last_key_value() { | |
| 234 | if let Some(event_id) = key.id.as_origin() { | |
| 235 | info.set_receipt( | |
| 236 | matrix_sdk::ruma::events::receipt::ReceiptThread::Main, | |
| 237 | user_id, | |
| 238 | event_id.to_owned(), | |
| 239 | ); | |
| 240 | } | |
| 233 | if let Some((key, _)) = messages.last_key_value() && | |
| 234 | let Some(event_id) = key.id.as_origin() | |
| 235 | { | |
| 236 | info.set_receipt( | |
| 237 | matrix_sdk::ruma::events::receipt::ReceiptThread::Main, | |
| 238 | user_id, | |
| 239 | event_id.to_owned(), | |
| 240 | ); | |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
| @@ -665,10 +665,10 @@ impl RoomState { | ||
| 665 | 665 | let style = Style::default().add_modifier(StyleModifier::BOLD); |
| 666 | 666 | let mut spans = vec![]; |
| 667 | 667 | |
| 668 | if let RoomState::Chat(chat) = self { | |
| 669 | if chat.thread().is_some() { | |
| 670 | spans.push("Thread in ".into()); | |
| 671 | } | |
| 668 | if let RoomState::Chat(chat) = self && | |
| 669 | chat.thread().is_some() | |
| 670 | { | |
| 671 | spans.push("Thread in ".into()); | |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | spans.push(Span::styled(title, style)); |
src/windows/room/space.rs +4 −4
| @@ -3,9 +3,9 @@ use std::ops::{Deref, DerefMut}; | ||
| 3 | 3 | use std::str::FromStr; |
| 4 | 4 | use std::time::{Duration, Instant}; |
| 5 | 5 | |
| 6 | use matrix_sdk::ruma::events::space::child::SpaceChildEventContent; | |
| 7 | use matrix_sdk::ruma::events::StateEventType; | |
| 8 | 6 | use matrix_sdk::ruma::OwnedSpaceChildOrder; |
| 7 | use matrix_sdk::ruma::events::StateEventType; | |
| 8 | use matrix_sdk::ruma::events::space::child::SpaceChildEventContent; | |
| 9 | 9 | use matrix_sdk::{ |
| 10 | 10 | room::Room as MatrixRoom, |
| 11 | 11 | ruma::{OwnedRoomId, RoomId}, |
| @@ -21,10 +21,10 @@ use ratatui::{ | ||
| 21 | 21 | }; |
| 22 | 22 | |
| 23 | 23 | use modalkit_ratatui::{ |
| 24 | list::{List, ListState}, | |
| 25 | 24 | TermOffset, |
| 26 | 25 | TerminalCursor, |
| 27 | 26 | WindowOps, |
| 27 | list::{List, ListState}, | |
| 28 | 28 | }; |
| 29 | 29 | |
| 30 | 30 | use crate::base::{ |
| @@ -38,7 +38,7 @@ use crate::base::{ | ||
| 38 | 38 | SpaceAction, |
| 39 | 39 | }; |
| 40 | 40 | |
| 41 | use crate::windows::{room_fields_cmp, RoomItem, RoomLikeItem}; | |
| 41 | use crate::windows::{RoomItem, RoomLikeItem, room_fields_cmp}; | |
| 42 | 42 | |
| 43 | 43 | const SPACE_HIERARCHY_DEBOUNCE: Duration = Duration::from_secs(5); |
| 44 | 44 | |
src/windows/welcome.rs +1 −1
| @@ -3,7 +3,7 @@ use std::ops::{Deref, DerefMut}; | ||
| 3 | 3 | |
| 4 | 4 | use ratatui::{buffer::Buffer, layout::Rect}; |
| 5 | 5 | |
| 6 | use modalkit_ratatui::{textbox::TextBoxState, TermOffset, TerminalCursor, WindowOps}; | |
| 6 | use modalkit_ratatui::{TermOffset, TerminalCursor, WindowOps, textbox::TextBoxState}; | |
| 7 | 7 | |
| 8 | 8 | use modalkit::editing::completion::CompletionList; |
| 9 | 9 | use modalkit::prelude::*; |
src/worker.rs +39 −40
| @@ -7,53 +7,71 @@ use std::convert::TryFrom; | ||
| 7 | 7 | use std::fmt::{Debug, Formatter}; |
| 8 | 8 | use std::ops::DerefMut; |
| 9 | 9 | use std::str::FromStr; |
| 10 | use std::sync::mpsc::{sync_channel, Receiver, SyncSender}; | |
| 11 | 10 | use std::sync::Arc; |
| 11 | use std::sync::mpsc::{Receiver, SyncSender, sync_channel}; | |
| 12 | 12 | use std::time::{Duration, Instant}; |
| 13 | 13 | |
| 14 | use futures::{stream::FuturesUnordered, StreamExt}; | |
| 14 | use futures::{StreamExt, stream::FuturesUnordered}; | |
| 15 | 15 | use gethostname::gethostname; |
| 16 | use matrix_sdk::ruma::events::AnyMessageLikeEventContent; | |
| 16 | 17 | use matrix_sdk::ruma::events::relation::Thread; |
| 17 | use matrix_sdk::ruma::events::room::message::Relation; | |
| 18 | 18 | use matrix_sdk::ruma::events::room::MediaSource; |
| 19 | use matrix_sdk::ruma::events::room::message::Relation; | |
| 19 | 20 | use matrix_sdk::ruma::events::sticker::StickerEventContent; |
| 20 | use matrix_sdk::ruma::events::AnyMessageLikeEventContent; | |
| 21 | 21 | use matrix_sdk::send_queue::{LocalEcho, LocalEchoContent, RoomSendQueueUpdate, SendQueueUpdate}; |
| 22 | 22 | use ratatui_image::picker::Picker; |
| 23 | use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}; | |
| 24 | 23 | use tokio::sync::Semaphore; |
| 24 | use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender, unbounded_channel}; | |
| 25 | 25 | use tokio::task::JoinHandle; |
| 26 | 26 | use tracing::{error, warn}; |
| 27 | 27 | use url::Url; |
| 28 | 28 | |
| 29 | 29 | use matrix_sdk::{ |
| 30 | Client, | |
| 31 | ClientBuildError, | |
| 32 | Error as MatrixError, | |
| 33 | RoomDisplayName, | |
| 34 | RoomMemberships, | |
| 30 | 35 | authentication::matrix::MatrixSession, |
| 31 | 36 | config::{RequestConfig, SyncSettings}, |
| 32 | 37 | encryption::{ |
| 33 | verification::{SasVerification, Verification}, | |
| 34 | 38 | BackupDownloadStrategy, |
| 35 | 39 | EncryptionSettings, |
| 40 | verification::{SasVerification, Verification}, | |
| 36 | 41 | }, |
| 37 | 42 | event_handler::Ctx, |
| 38 | 43 | reqwest, |
| 39 | 44 | room::{Messages, MessagesOptions, Room as MatrixRoom, RoomMember}, |
| 40 | 45 | ruma::{ |
| 46 | EventId, | |
| 47 | OwnedEventId, | |
| 48 | OwnedRoomId, | |
| 49 | OwnedRoomOrAliasId, | |
| 50 | OwnedUserId, | |
| 51 | RoomId, | |
| 41 | 52 | api::client::{ |
| 42 | 53 | filter::{FilterDefinition, LazyLoadOptions, RoomEventFilter, RoomFilter}, |
| 43 | 54 | room::{ |
| 44 | create_room::v3::{CreationContent, Request as CreateRoomRequest}, | |
| 45 | 55 | Visibility, |
| 56 | create_room::v3::{CreationContent, Request as CreateRoomRequest}, | |
| 46 | 57 | }, |
| 47 | 58 | space::get_hierarchy::v1::Request as SpaceHierarchyRequest, |
| 48 | 59 | }, |
| 49 | 60 | assign, |
| 50 | 61 | events::{ |
| 62 | AnyMessageLikeEvent, | |
| 63 | AnySyncStateEvent, | |
| 64 | AnyTimelineEvent, | |
| 65 | InitialStateEvent, | |
| 66 | SyncEphemeralRoomEvent, | |
| 67 | SyncMessageLikeEvent, | |
| 68 | SyncStateEvent, | |
| 51 | 69 | key::verification::{ |
| 70 | VerificationMethod, | |
| 52 | 71 | done::{OriginalSyncKeyVerificationDoneEvent, ToDeviceKeyVerificationDoneEvent}, |
| 53 | 72 | key::{OriginalSyncKeyVerificationKeyEvent, ToDeviceKeyVerificationKeyEvent}, |
| 54 | 73 | request::ToDeviceKeyVerificationRequestEvent, |
| 55 | 74 | start::{OriginalSyncKeyVerificationStartEvent, ToDeviceKeyVerificationStartEvent}, |
| 56 | VerificationMethod, | |
| 57 | 75 | }, |
| 58 | 76 | presence::PresenceEvent, |
| 59 | 77 | reaction::ReactionEventContent, |
| @@ -67,28 +85,10 @@ use matrix_sdk::{ | ||
| 67 | 85 | }, |
| 68 | 86 | tag::Tags, |
| 69 | 87 | typing::SyncTypingEvent, |
| 70 | AnyMessageLikeEvent, | |
| 71 | AnySyncStateEvent, | |
| 72 | AnyTimelineEvent, | |
| 73 | InitialStateEvent, | |
| 74 | SyncEphemeralRoomEvent, | |
| 75 | SyncMessageLikeEvent, | |
| 76 | SyncStateEvent, | |
| 77 | 88 | }, |
| 78 | 89 | room::RoomType, |
| 79 | 90 | serde::Raw, |
| 80 | EventId, | |
| 81 | OwnedEventId, | |
| 82 | OwnedRoomId, | |
| 83 | OwnedRoomOrAliasId, | |
| 84 | OwnedUserId, | |
| 85 | RoomId, | |
| 86 | 91 | }, |
| 87 | Client, | |
| 88 | ClientBuildError, | |
| 89 | Error as MatrixError, | |
| 90 | RoomDisplayName, | |
| 91 | RoomMemberships, | |
| 92 | 92 | }; |
| 93 | 93 | |
| 94 | 94 | use modalkit::errors::UIError; |
| @@ -100,6 +100,7 @@ use crate::message::{Message, MessageEvent, MessageId, MessageKey}; | ||
| 100 | 100 | use crate::notifications::register_notifications; |
| 101 | 101 | use crate::preview::load_image; |
| 102 | 102 | use crate::{ |
| 103 | ApplicationSettings, | |
| 103 | 104 | base::{ |
| 104 | 105 | AsyncProgramStore, |
| 105 | 106 | ChatStore, |
| @@ -112,7 +113,6 @@ use crate::{ | ||
| 112 | 113 | RoomInfo, |
| 113 | 114 | VerifyAction, |
| 114 | 115 | }, |
| 115 | ApplicationSettings, | |
| 116 | 116 | }; |
| 117 | 117 | |
| 118 | 118 | const DEFAULT_ENCRYPTION_SETTINGS: EncryptionSettings = EncryptionSettings { |
| @@ -510,9 +510,10 @@ async fn send_receipts_forever(client: &Client, store: &AsyncProgramStore) { | ||
| 510 | 510 | }; |
| 511 | 511 | |
| 512 | 512 | if ReceiptThread::Main == thread || ReceiptThread::Unthreaded == thread { |
| 513 | if let Err(err) = room.set_unread_flag(false).await { | |
| 514 | tracing::warn!(?room_id, "Failed to clear unread flag: {err}"); | |
| 515 | } | |
| 513 | let _ = room | |
| 514 | .set_unread_flag(false) | |
| 515 | .await | |
| 516 | .inspect_err(|e| tracing::warn!(?room_id, "Failed to clear unread flag: {e}")); | |
| 516 | 517 | } |
| 517 | 518 | |
| 518 | 519 | match room |
| @@ -1148,16 +1149,14 @@ impl ClientWorker { | ||
| 1148 | 1149 | async move { |
| 1149 | 1150 | let room_id = room.room_id(); |
| 1150 | 1151 | |
| 1151 | if let Some(msg) = ev.as_original() { | |
| 1152 | if let MessageType::VerificationRequest(_) = msg.content.msgtype { | |
| 1153 | if let Some(request) = client | |
| 1154 | .encryption() | |
| 1155 | .get_verification_request(ev.sender(), ev.event_id()) | |
| 1156 | .await | |
| 1157 | { | |
| 1158 | request.accept().await.expect("Failed to accept request"); | |
| 1159 | } | |
| 1160 | } | |
| 1152 | if let Some(msg) = ev.as_original() && | |
| 1153 | let MessageType::VerificationRequest(_) = msg.content.msgtype && | |
| 1154 | let Some(request) = client | |
| 1155 | .encryption() | |
| 1156 | .get_verification_request(ev.sender(), ev.event_id()) | |
| 1157 | .await | |
| 1158 | { | |
| 1159 | request.accept().await.expect("Failed to accept request"); | |
| 1161 | 1160 | } |
| 1162 | 1161 | |
| 1163 | 1162 | let mut locked = store.lock().await; |