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
2121user_gutter_width = 30
2222username_display = "username"
2323
24[settings.encryption]
25indicator = "only-encrypted"
26location = "title|prompt"
27
2428[settings.image_preview]
2529protocol.type = "sixel"
2630size = { "width" = 66, "height" = 10 }
docs/iamb.5 +31
@@ -126,6 +126,11 @@ These options are configured as an object under the
126126key and can be overridden as described in
127127.Sx PROFILES .
128128.Bl -tag -width Ds
129.It Sy encryption
130Configuration subsection for specific settings related to room encryption.
131See
132.Sx ENCRYPTION
133for more details.
129134.It Sy external_edit_file_suffix
130135Suffix to append to temporary file names when using the :editor command. Defaults to .md.
131136.It Sy default_room
@@ -258,6 +263,32 @@ reaction_shortcode_display = true
258263[settings]
259264request_timeout = 120
260265.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 .
261292.Sh MOUSE
262293The
263294.Sy settings.mouse
src/config.rs +235
@@ -13,6 +13,7 @@ use std::process;
1313use clap::Parser;
1414use matrix_sdk::authentication::matrix::MatrixSession;
1515use matrix_sdk::ruma::{OwnedDeviceId, OwnedRoomAliasId, OwnedRoomId, OwnedUserId, UserId};
16use matrix_sdk::EncryptionState;
1617use ratatui::style::{Color, Modifier as StyleModifier, Style};
1718use ratatui::text::Span;
1819use ratatui_image::picker::ProtocolType;
@@ -53,6 +54,7 @@ const DEFAULT_ROOM_SORT: [SortColumn<SortFieldRoom>; 5] = [
5354 SortColumn(SortFieldRoom::Name, SortOrder::Ascending),
5455];
5556
57const DEFAULT_ENC_INDICATOR_LOC: EncryptionIndicatorLocation = EncryptionIndicatorLocation::PROMPT;
5658const DEFAULT_REQ_TIMEOUT: u64 = 120;
5759
5860const COLORS: [Color; 13] = [
@@ -315,6 +317,13 @@ pub struct UserDisplayTunables {
315317
316318pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>;
317319
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
318327fn merge_sorts(profile: SortOverrides, global: SortOverrides) -> SortOverrides {
319328 SortOverrides {
320329 chats: profile.chats.or(global.chats),
@@ -345,6 +354,69 @@ where
345354 }
346355}
347356
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
348420#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
349421#[serde(rename_all = "lowercase")]
350422pub enum UserDisplayStyle {
@@ -430,6 +502,69 @@ impl<'de> Deserialize<'de> for NotifyVia {
430502 }
431503}
432504
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
433568#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
434569pub struct Mouse {
435570 #[serde(default)]
@@ -519,6 +654,7 @@ impl SortOverrides {
519654
520655#[derive(Clone)]
521656pub struct TunableValues {
657 pub encryption: EncryptionValues,
522658 pub log_level: String,
523659 pub max_log_files: usize,
524660 pub message_shortcode_display: bool,
@@ -548,6 +684,8 @@ pub struct TunableValues {
548684
549685#[derive(Clone, Default, Deserialize)]
550686pub struct Tunables {
687 #[serde(default)]
688 pub encryption: Encryption,
551689 pub log_level: Option<String>,
552690 pub max_log_files: Option<usize>,
553691 pub message_shortcode_display: Option<bool>,
@@ -579,6 +717,7 @@ pub struct Tunables {
579717impl Tunables {
580718 fn merge(self, other: Self) -> Self {
581719 Tunables {
720 encryption: merge_encryption(self.encryption, other.encryption),
582721 log_level: self.log_level.or(other.log_level),
583722 max_log_files: self.max_log_files.or(other.max_log_files),
584723 message_shortcode_display: self
@@ -616,6 +755,7 @@ impl Tunables {
616755 fn values(self) -> TunableValues {
617756 TunableValues {
618757 log_level: self.log_level.unwrap_or_else(|| "warn".to_string()),
758 encryption: self.encryption.values(),
619759 max_log_files: self.max_log_files.unwrap_or(7),
620760 message_shortcode_display: self.message_shortcode_display.unwrap_or(false),
621761 normal_after_send: self.normal_after_send.unwrap_or(false),
@@ -1337,4 +1477,99 @@ mod tests {
13371477 assert!(layout.is_some());
13381478 assert!(macros.is_some());
13391479 }
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 }
13401575}
src/tests.rs +2
@@ -26,6 +26,7 @@ use crate::{
2626 user_style_from_color,
2727 ApplicationSettings,
2828 DirectoryValues,
29 Encryption,
2930 Notifications,
3031 NotifyVia,
3132 ProfileConfig,
@@ -170,6 +171,7 @@ pub fn mock_dirs() -> DirectoryValues {
170171pub fn mock_tunables() -> TunableValues {
171172 TunableValues {
172173 default_room: None,
174 encryption: Encryption::default().values(),
173175 log_level: "warn".into(),
174176 max_log_files: 7,
175177 message_shortcode_display: false,
src/windows/room/chat.rs +7 −10
@@ -7,9 +7,7 @@ use std::path::{Path, PathBuf};
77
88use edit::edit_with_builder as external_edit;
99use edit::Builder;
10use matrix_sdk::EncryptionState;
1110use modalkit::editing::store::RegisterError;
12use ratatui::style::{Color, Style};
1311use std::process::Command;
1412use tokio;
1513use url::Url;
@@ -88,6 +86,7 @@ use crate::base::{
8886 SendAction,
8987};
9088
89use crate::config::EncryptionIndicatorLocation;
9190use crate::message::{
9291 text_to_message,
9392 Message,
@@ -996,15 +995,13 @@ impl StatefulWidget for Chat<'_> {
996995 Paragraph::new(desc_spans).render(descarea, buf);
997996 }
998997
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) {
10001002 (false, _) => Span::raw(" "),
1001 (_, EncryptionState::Encrypted) => {
1002 Span::styled("\u{1F512}\u{FE0E} ", Style::new().fg(Color::LightGreen))
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)),
1003 (true, Some(i)) => i,
1004 (true, None) => Span::raw("> "),
10081005 };
10091006
10101007 let tbox = TextBox::new().prompt(prompt);
src/windows/room/mod.rs +13 −1
@@ -65,6 +65,7 @@ use crate::base::{
6565
6666use self::chat::ChatState;
6767use self::space::{Space, SpaceState};
68use crate::config::EncryptionIndicatorLocation;
6869
6970use std::convert::TryFrom;
7071
@@ -639,6 +640,8 @@ impl RoomState {
639640 }
640641
641642 pub fn get_title(&self, store: &mut ProgramStore) -> Line<'_> {
643 let room = store.application.worker.client.get_room(self.id());
644
642645 let title = store.application.get_room_title(self.id());
643646 let style = Style::default().add_modifier(StyleModifier::BOLD);
644647 let mut spans = vec![];
@@ -651,13 +654,22 @@ impl RoomState {
651654
652655 spans.push(Span::styled(title, style));
653656
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
654664 match self.room().topic() {
655665 Some(desc) if !desc.is_empty() => {
656666 spans.push(" (".into());
657667 spans.push(desc.into());
658668 spans.push(")".into());
659669 },
660 _ => {},
670 _ => {
671 spans.push(" ".into());
672 },
661673 }
662674
663675 Line::from(spans)