Commit e5f91f7e4c

e5f91f7e4c3a38fde98c03b4bf7ff0134eb86abc

parent: 0821b25e58

Unregistered key

vaw <git@nlih.de> · 2026-07-25 21:51 UTC
committer: <noreply@github.com>

Support placing encryption indicator in room title instead of prompt (#581)

Co-authored-by: Ulyssa <git@ulyssa.dev>

Layout: unified · split

config.example.toml +4
@@ -21,6 +21,10 @@ typing_notice_send = true
21user_gutter_width = 30 21user_gutter_width = 30
22username_display = "username" 22username_display = "username"
23 23
24[settings.encryption]
25indicator = "only-encrypted"
26location = "title|prompt"
27
24[settings.image_preview] 28[settings.image_preview]
25protocol.type = "sixel" 29protocol.type = "sixel"
26size = { "width" = 66, "height" = 10 } 30size = { "width" = 66, "height" = 10 }
docs/iamb.5 +31
@@ -126,6 +126,11 @@ These options are configured as an object under the
126key and can be overridden as described in 126key and can be overridden as described in
127.Sx PROFILES . 127.Sx PROFILES .
128.Bl -tag -width Ds 128.Bl -tag -width Ds
129.It Sy encryption
130Configuration subsection for specific settings related to room encryption.
131See
132.Sx ENCRYPTION
133for more details.
129.It Sy external_edit_file_suffix 134.It Sy external_edit_file_suffix
130Suffix to append to temporary file names when using the :editor command. Defaults to .md. 135Suffix to append to temporary file names when using the :editor command. Defaults to .md.
131.It Sy default_room 136.It Sy default_room
@@ -258,6 +263,32 @@ reaction_shortcode_display = true
258[settings] 263[settings]
259request_timeout = 120 264request_timeout = 120
260.Ed 265.Ed
266.Sh ENCRYPTION
267The
268.Sy settings.encryption
269subsection allows controlling how encrypted rooms are presented.
270.Pp
271The available fields in this subsection are:
272.Bl -tag -width Ds
273.It Sy indicator
274Defines when an encryption status indicator is shown.
275Possible values are:
276.Dq Sy enabled
277(default, always indicate status),
278.Dq Sy disabled
279(never indicate status),
280.Dq Sy only-unencrypted ,
281and
282.Dq Sy only-encrypted .
283.It Sy indicator_location
284Defines where the encryption status indicator is shown when relevant.
285Possible values are:
286.Dq Sy title ,
287and
288.Dq Sy prompt
289(the default).
290Both can be used via
291.Dq Sy title|prompt .
261.Sh MOUSE 292.Sh MOUSE
262The 293The
263.Sy settings.mouse 294.Sy settings.mouse
src/config.rs +235
@@ -13,6 +13,7 @@ use std::process;
13use clap::Parser; 13use clap::Parser;
14use matrix_sdk::authentication::matrix::MatrixSession; 14use matrix_sdk::authentication::matrix::MatrixSession;
15use matrix_sdk::ruma::{OwnedDeviceId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UserId}; 15use matrix_sdk::ruma::{OwnedDeviceId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UserId};
16use matrix_sdk::EncryptionState;
16use ratatui::style::{Color, Modifier as StyleModifier, Style}; 17use ratatui::style::{Color, Modifier as StyleModifier, Style};
17use ratatui::text::Span; 18use ratatui::text::Span;
18use ratatui_image::picker::ProtocolType; 19use ratatui_image::picker::ProtocolType;
@@ -53,6 +54,7 @@ const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 5] = [
53 SortColumn(SortFieldRoom::Name, SortOrder::Ascending), 54 SortColumn(SortFieldRoom::Name, SortOrder::Ascending),
54]; 55];
55 56
57const DEFAULT_ENC_INDICATOR_LOC: EncryptionIndicatorLocation = EncryptionIndicatorLocation::PROMPT;
56const DEFAULT_REQ_TIMEOUT: u64 = 120; 58const DEFAULT_REQ_TIMEOUT: u64 = 120;
57 59
58const COLORS: [Color; 13] = [ 60const COLORS: [Color; 13] = [
@@ -315,6 +317,13 @@ pub struct UserDisplayTunables {
315 317
316pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>; 318pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>;
317 319
320fn merge_encryption(profile: Encryption, global: Encryption) -> Encryption {
321 Encryption {
322 indicator: profile.indicator.or(global.indicator),
323 indicator_location: profile.indicator_location.or(global.indicator_location),
324 }
325}
326
318fn merge_sorts(profile: SortOverrides, global: SortOverrides) -> SortOverrides { 327fn merge_sorts(profile: SortOverrides, global: SortOverrides) -> SortOverrides {
319 SortOverrides { 328 SortOverrides {
320 chats: profile.chats.or(global.chats), 329 chats: profile.chats.or(global.chats),
@@ -345,6 +354,69 @@ where
345 } 354 }
346} 355}
347 356
357#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, PartialEq)]
358#[serde(rename_all = "kebab-case")]
359#[repr(u8)]
360pub enum EncryptionIndicator {
361 /// Always indicate the room's encryption status.
362 #[default]
363 Enabled,
364 /// Never indicate the room's encryption status.
365 Disabled,
366 /// Only indicate the room's encryption status when it is encrypted.
367 OnlyEncrypted,
368 /// Only indicate the room's encryption status when it is unencrypted.
369 OnlyUnencrypted,
370}
371
372bitflags::bitflags! {
373 /// Available options for where to show the encryption status indicator.
374 #[derive(Clone, Debug, Eq, PartialEq)]
375 pub struct EncryptionIndicatorLocation: u8 {
376 const NONE = 0b00000000;
377 const TITLE = 0b00000001;
378 const PROMPT = 0b00000010;
379 }
380}
381
382pub struct EncryptionIndicatorLocationVisitor;
383
384impl Visitor<'_> for EncryptionIndicatorLocationVisitor {
385 type Value = EncryptionIndicatorLocation;
386
387 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
388 formatter.write_str("a valid encryption indicator location (e.g. \"title\" or \"prompt\")")
389 }
390
391 fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
392 where
393 E: SerdeError,
394 {
395 let mut location = EncryptionIndicatorLocation::NONE;
396
397 for value in value.split('|') {
398 match value.to_ascii_lowercase().as_str() {
399 "title" => location |= EncryptionIndicatorLocation::TITLE,
400 "prompt" => location |= EncryptionIndicatorLocation::PROMPT,
401 _ => {
402 return Err(E::custom("could not parse into an encryption indicator location"))
403 },
404 };
405 }
406
407 Ok(location)
408 }
409}
410
411impl<'de> Deserialize<'de> for EncryptionIndicatorLocation {
412 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
413 where
414 D: Deserializer<'de>,
415 {
416 deserializer.deserialize_str(EncryptionIndicatorLocationVisitor)
417 }
418}
419
348#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] 420#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
349#[serde(rename_all = "lowercase")] 421#[serde(rename_all = "lowercase")]
350pub enum UserDisplayStyle { 422pub enum UserDisplayStyle {
@@ -430,6 +502,69 @@ impl<'de> Deserialize<'de> for NotifyVia {
430 } 502 }
431} 503}
432 504
505#[derive(Clone, Debug, Default, Deserialize)]
506pub struct Encryption {
507 indicator: Option<EncryptionIndicator>,
508 indicator_location: Option<EncryptionIndicatorLocation>,
509}
510
511impl Encryption {
512 pub fn values(self) -> EncryptionValues {
513 EncryptionValues {
514 indicator: self.indicator.unwrap_or_default(),
515 indicator_location: self.indicator_location.unwrap_or(DEFAULT_ENC_INDICATOR_LOC),
516 }
517 }
518}
519
520#[derive(Clone, Debug)]
521pub struct EncryptionValues {
522 pub indicator: EncryptionIndicator,
523 pub indicator_location: EncryptionIndicatorLocation,
524}
525
526impl EncryptionValues {
527 pub fn get_indicator(
528 &self,
529 location: EncryptionIndicatorLocation,
530 state: EncryptionState,
531 ) -> Option<Span<'static>> {
532 if !self.indicator_location.contains(location) {
533 return None;
534 }
535
536 let indicator = match (self.indicator, state) {
537 (EncryptionIndicator::Disabled, _) |
538 (EncryptionIndicator::OnlyUnencrypted, EncryptionState::Encrypted) |
539 (EncryptionIndicator::OnlyEncrypted, EncryptionState::NotEncrypted) => {
540 // User doesn't want to see anything:
541 return None;
542 },
543 (
544 EncryptionIndicator::Enabled | EncryptionIndicator::OnlyEncrypted,
545 EncryptionState::Encrypted,
546 ) => {
547 // Green lock:
548 Span::styled("\u{1F512}\u{FE0E} ", Style::new().fg(Color::LightGreen))
549 },
550 (
551 EncryptionIndicator::Enabled | EncryptionIndicator::OnlyUnencrypted,
552 EncryptionState::NotEncrypted,
553 ) => {
554 // Red unlocked lock:
555 Span::styled("\u{1F513}\u{FE0E} ", Style::new().fg(Color::Red))
556 },
557
558 (_, EncryptionState::Unknown) => {
559 // Yellow question mark:
560 Span::styled("? ", Style::new().fg(Color::Yellow))
561 },
562 };
563
564 Some(indicator)
565 }
566}
567
433#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] 568#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
434pub struct Mouse { 569pub struct Mouse {
435 #[serde(default)] 570 #[serde(default)]
@@ -519,6 +654,7 @@ impl SortOverrides {
519 654
520#[derive(Clone)] 655#[derive(Clone)]
521pub struct TunableValues { 656pub struct TunableValues {
657 pub encryption: EncryptionValues,
522 pub log_level: String, 658 pub log_level: String,
523 pub max_log_files: usize, 659 pub max_log_files: usize,
524 pub message_shortcode_display: bool, 660 pub message_shortcode_display: bool,
@@ -548,6 +684,8 @@ pub struct TunableValues {
548 684
549#[derive(Clone, Default, Deserialize)] 685#[derive(Clone, Default, Deserialize)]
550pub struct Tunables { 686pub struct Tunables {
687 #[serde(default)]
688 pub encryption: Encryption,
551 pub log_level: Option<String>, 689 pub log_level: Option<String>,
552 pub max_log_files: Option<usize>, 690 pub max_log_files: Option<usize>,
553 pub message_shortcode_display: Option<bool>, 691 pub message_shortcode_display: Option<bool>,
@@ -579,6 +717,7 @@ pub struct Tunables {
579impl Tunables { 717impl Tunables {
580 fn merge(self, other: Self) -> Self { 718 fn merge(self, other: Self) -> Self {
581 Tunables { 719 Tunables {
720 encryption: merge_encryption(self.encryption, other.encryption),
582 log_level: self.log_level.or(other.log_level), 721 log_level: self.log_level.or(other.log_level),
583 max_log_files: self.max_log_files.or(other.max_log_files), 722 max_log_files: self.max_log_files.or(other.max_log_files),
584 message_shortcode_display: self 723 message_shortcode_display: self
@@ -616,6 +755,7 @@ impl Tunables {
616 fn values(self) -> TunableValues { 755 fn values(self) -> TunableValues {
617 TunableValues { 756 TunableValues {
618 log_level: self.log_level.unwrap_or_else(|| "warn".to_string()), 757 log_level: self.log_level.unwrap_or_else(|| "warn".to_string()),
758 encryption: self.encryption.values(),
619 max_log_files: self.max_log_files.unwrap_or(7), 759 max_log_files: self.max_log_files.unwrap_or(7),
620 message_shortcode_display: self.message_shortcode_display.unwrap_or(false), 760 message_shortcode_display: self.message_shortcode_display.unwrap_or(false),
621 normal_after_send: self.normal_after_send.unwrap_or(false), 761 normal_after_send: self.normal_after_send.unwrap_or(false),
@@ -1337,4 +1477,99 @@ mod tests {
1337 assert!(layout.is_some()); 1477 assert!(layout.is_some());
1338 assert!(macros.is_some()); 1478 assert!(macros.is_some());
1339 } 1479 }
1480
1481 #[test]
1482 fn test_encryption_indicator_enabled() {
1483 use EncryptionState::*;
1484
1485 let enc = EncryptionValues {
1486 indicator: EncryptionIndicator::Enabled,
1487 indicator_location: EncryptionIndicatorLocation::TITLE,
1488 };
1489
1490 // Always shows in the title:
1491 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_some());
1492 assert!(enc
1493 .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted)
1494 .is_some());
1495 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some());
1496
1497 // Doesn't show in the prompt:
1498 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none());
1499 assert!(enc
1500 .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted)
1501 .is_none());
1502 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none());
1503 }
1504
1505 #[test]
1506 fn test_encryption_indicator_disabled() {
1507 use EncryptionState::*;
1508
1509 let enc = EncryptionValues {
1510 indicator: EncryptionIndicator::Disabled,
1511 indicator_location: EncryptionIndicatorLocation::TITLE,
1512 };
1513
1514 // Never shows in the title or the prompt:
1515 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none());
1516 assert!(enc
1517 .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted)
1518 .is_none());
1519 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none());
1520 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none());
1521 assert!(enc
1522 .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted)
1523 .is_none());
1524 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_none());
1525 }
1526
1527 #[test]
1528 fn test_encryption_indicator_only_encrypted() {
1529 use EncryptionState::*;
1530
1531 let enc = EncryptionValues {
1532 indicator: EncryptionIndicator::OnlyEncrypted,
1533 indicator_location: EncryptionIndicatorLocation::PROMPT,
1534 };
1535
1536 // Shows in the prompt when encrypted or unknown:
1537 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_some());
1538 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some());
1539
1540 // But is hidden when unencrypted:
1541 assert!(enc
1542 .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted)
1543 .is_none());
1544
1545 // Doesn't show in the title:
1546 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none());
1547 assert!(enc
1548 .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted)
1549 .is_none());
1550 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_none());
1551 }
1552 #[test]
1553 fn test_encryption_indicator_only_unencrypted() {
1554 use EncryptionState::*;
1555
1556 let enc = EncryptionValues {
1557 indicator: EncryptionIndicator::OnlyUnencrypted,
1558 indicator_location: EncryptionIndicatorLocation::all(),
1559 };
1560
1561 // Shows in both the prompt and title when unencrypted or unknown:
1562 assert!(enc
1563 .get_indicator(EncryptionIndicatorLocation::TITLE, NotEncrypted)
1564 .is_some());
1565 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Unknown).is_some());
1566 assert!(enc
1567 .get_indicator(EncryptionIndicatorLocation::PROMPT, NotEncrypted)
1568 .is_some());
1569 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Unknown).is_some());
1570
1571 // But is hidden when encrypted:
1572 assert!(enc.get_indicator(EncryptionIndicatorLocation::TITLE, Encrypted).is_none());
1573 assert!(enc.get_indicator(EncryptionIndicatorLocation::PROMPT, Encrypted).is_none());
1574 }
1340} 1575}
src/tests.rs +2
@@ -26,6 +26,7 @@ use crate::{
26 user_style_from_color, 26 user_style_from_color,
27 ApplicationSettings, 27 ApplicationSettings,
28 DirectoryValues, 28 DirectoryValues,
29 Encryption,
29 Notifications, 30 Notifications,
30 NotifyVia, 31 NotifyVia,
31 ProfileConfig, 32 ProfileConfig,
@@ -170,6 +171,7 @@ pub fn mock_dirs() -> DirectoryValues {
170pub fn mock_tunables() -> TunableValues { 171pub fn mock_tunables() -> TunableValues {
171 TunableValues { 172 TunableValues {
172 default_room: None, 173 default_room: None,
174 encryption: Encryption::default().values(),
173 log_level: "warn".into(), 175 log_level: "warn".into(),
174 max_log_files: 7, 176 max_log_files: 7,
175 message_shortcode_display: false, 177 message_shortcode_display: false,
src/windows/room/chat.rs +7 −10
@@ -7,9 +7,7 @@ use std::path::{Path, PathBuf};
7 7
8use edit::edit_with_builder as external_edit; 8use edit::edit_with_builder as external_edit;
9use edit::Builder; 9use edit::Builder;
10use matrix_sdk::EncryptionState;
11use modalkit::editing::store::RegisterError; 10use modalkit::editing::store::RegisterError;
12use ratatui::style::{Color, Style};
13use std::process::Command; 11use std::process::Command;
14use tokio; 12use tokio;
15use url::Url; 13use url::Url;
@@ -88,6 +86,7 @@ use crate::base::{
88 SendAction, 86 SendAction,
89}; 87};
90 88
89use crate::config::EncryptionIndicatorLocation;
91use crate::message::{ 90use crate::message::{
92 text_to_message, 91 text_to_message,
93 Message, 92 Message,
@@ -996,15 +995,13 @@ impl StatefulWidget for Chat<'_> {
996 Paragraph::new(desc_spans).render(descarea, buf); 995 Paragraph::new(desc_spans).render(descarea, buf);
997 } 996 }
998 997
999 let prompt = match (self.focused, state.room().encryption_state()) { 998 let encryption_settings = &self.store.application.settings.tunables.encryption;
999 let encryption_indicator = encryption_settings
1000 .get_indicator(EncryptionIndicatorLocation::PROMPT, state.room().encryption_state());
1001 let prompt = match (self.focused, encryption_indicator) {
1000 (false, _) => Span::raw(" "), 1002 (false, _) => Span::raw(" "),
1001 (_, EncryptionState::Encrypted) => { 1003 (true, Some(i)) => i,
1002 Span::styled("\u{1F512}\u{FE0E} ", Style::new().fg(Color::LightGreen)) 1004 (true, None) => Span::raw("> "),
1003 },
1004 (_, EncryptionState::NotEncrypted) => {
1005 Span::styled("\u{1F513}\u{FE0E} ", Style::new().fg(Color::Red))
1006 },
1007 (_, EncryptionState::Unknown) => Span::styled("> ", Style::new().fg(Color::Red)),
1008 }; 1005 };
1009 1006
1010 let tbox = TextBox::new().prompt(prompt); 1007 let tbox = TextBox::new().prompt(prompt);
src/windows/room/mod.rs +13 −1
@@ -65,6 +65,7 @@ use crate::base::{
65 65
66use self::chat::ChatState; 66use self::chat::ChatState;
67use self::space::{Space, SpaceState}; 67use self::space::{Space, SpaceState};
68use crate::config::EncryptionIndicatorLocation;
68 69
69use std::convert::TryFrom; 70use std::convert::TryFrom;
70 71
@@ -639,6 +640,8 @@ impl RoomState {
639 } 640 }
640 641
641 pub fn get_title(&self, store: &mut ProgramStore) -> Line<'_> { 642 pub fn get_title(&self, store: &mut ProgramStore) -> Line<'_> {
643 let room = store.application.worker.client.get_room(self.id());
644
642 let title = store.application.get_room_title(self.id()); 645 let title = store.application.get_room_title(self.id());
643 let style = Style::default().add_modifier(StyleModifier::BOLD); 646 let style = Style::default().add_modifier(StyleModifier::BOLD);
644 let mut spans = vec![]; 647 let mut spans = vec![];
@@ -651,13 +654,22 @@ impl RoomState {
651 654
652 spans.push(Span::styled(title, style)); 655 spans.push(Span::styled(title, style));
653 656
657 if let Some(room) = room {
658 let encryption_settings = &store.application.settings.tunables.encryption;
659 let encryption_indicator = encryption_settings
660 .get_indicator(EncryptionIndicatorLocation::TITLE, room.encryption_state());
661 spans.extend(encryption_indicator);
662 }
663
654 match self.room().topic() { 664 match self.room().topic() {
655 Some(desc) if !desc.is_empty() => { 665 Some(desc) if !desc.is_empty() => {
656 spans.push(" (".into()); 666 spans.push(" (".into());
657 spans.push(desc.into()); 667 spans.push(desc.into());
658 spans.push(")".into()); 668 spans.push(")".into());
659 }, 669 },
660 _ => {}, 670 _ => {
671 spans.push(" ".into());
672 },
661 } 673 }
662 674
663 Line::from(spans) 675 Line::from(spans)