Commit 55ad2d3402

55ad2d3402026e9824dc4fcdd3dce2added05575

parent: 770dcd4b0c

Unregistered key

vaw <git@nlih.de> · 2026-11-04 04:11 UTC
committer: <noreply@github.com>

Allow overriding room names in the config (#846)

Layout: unified · split

config.full.toml +5
@@ -93,6 +93,11 @@ enable_title = true
9393[settings.users]
9494"@user:matrix.org" = { "name" = "John Doe", "color" = "magenta" }
9595
96# Settings to override room names
97[settings.rooms]
98"#room:matrix.org".name = "Some different room name"
99"@user:matrix.org".name = "My dm with John"
100
96101# Specify a specific tab and window layout to use every time iamb starts:
97102[layout]
98103style = "config"
docs/iamb.5 +22
@@ -320,6 +320,11 @@ Show if this is a regular room, a DM or a space when the current window shows mu
320320.It Sy unread
321321Show if a non-muted, non-calmed room has unread messages or mentions.
322322.El
323.It Sy rooms
324Overrides values for the specified room.
325See
326.Sx "ROOM OVERRIDES"
327for details on the format.
323328.It Sy send_on_enter
324329If
325330.Sy true
@@ -1038,6 +1043,23 @@ state.color = "cyan"
10381043tabs.title.modifiers = ["~bold", "italic"]
10391044windows.title.modifiers = ["~bold", "italic"]
10401045.Ed
1046.Sh "ROOM OVERRIDES"
1047The
1048.Sy settings.rooms
1049subsections allows overriding how specific rooms are displayed.
1050Overrides are mapped onto Matrix Room IDs, Matrix Room Aliases, or User IDs for DMs.
1051They are typically written as inline tables containing the following keys:
1052.Bl -tag -width Ds
1053.It Sy name
1054Change the display name of the room.
1055.El
1056.Ss Example 1: Override how the iamb rooms appear in the room list
1057.Bd -literal -offset indent
1058[settings.rooms]
1059"#iamb-users:0x.badd.cafe".name = "iamb user discussion"
1060"!EpWjxfRMnoLQPCKZei:0x.badd.cafe".name = "iamb developers"
1061"@ada:example.com".name = "My DM with Ada Lovelace"
1062.Ed
10411063.Sh "USER OVERRIDES"
10421064The
10431065.Sy settings.users
src/config/mod.rs +44
@@ -568,6 +568,46 @@ pub struct UserDisplayTunables {
568568
569569pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>;
570570
571#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash)]
572#[serde(untagged)]
573pub enum RoomOverrideKey {
574 User(OwnedUserId),
575 Room(OwnedRoomId),
576 Alias(OwnedRoomAliasId),
577}
578
579#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
580pub struct RoomOverrideTunables {
581 pub name: Option<String>,
582}
583
584pub type RoomOverrides = HashMap<RoomOverrideKey, RoomOverrideTunables>;
585
586#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)]
587pub struct RoomOverrideValues {
588 pub rooms: HashMap<OwnedRoomId, RoomOverrideTunables>,
589 pub aliases: HashMap<OwnedRoomAliasId, RoomOverrideTunables>,
590 pub dms: HashMap<OwnedUserId, RoomOverrideTunables>,
591}
592
593impl From<RoomOverrides> for RoomOverrideValues {
594 fn from(value: RoomOverrides) -> Self {
595 let mut rooms = HashMap::new();
596 let mut aliases = HashMap::new();
597 let mut dms = HashMap::new();
598
599 for (key, value) in value {
600 match key {
601 RoomOverrideKey::User(user_id) => dms.insert(user_id, value),
602 RoomOverrideKey::Room(room_id) => rooms.insert(room_id, value),
603 RoomOverrideKey::Alias(alias_id) => aliases.insert(alias_id, value),
604 };
605 }
606
607 Self { rooms, aliases, dms }
608 }
609}
610
571611fn merge_maps<M, K, V>(profile: Option<M>, global: Option<M>) -> Option<M>
572612where
573613 M: Extend<(K, V)> + IntoIterator<Item = (K, V)>,
@@ -1093,6 +1133,7 @@ pub struct TunableValues {
10931133 pub typing_notice_send: bool,
10941134 pub typing_notice_display: bool,
10951135 pub users: UserOverrides,
1136 pub rooms: RoomOverrideValues,
10961137 pub username_display: UserDisplayStyle,
10971138 pub message_user_color: bool,
10981139 pub default_register: Option<Register>,
@@ -1138,6 +1179,7 @@ pub struct Tunables {
11381179
11391180 /// Subsection for overriding how specific Matrix users are rendered.
11401181 pub users: Option<UserOverrides>,
1182 pub rooms: Option<RoomOverrides>,
11411183
11421184 pub default_markup: Option<MarkupFormat>,
11431185 pub ignorecase: Option<bool>,
@@ -1193,6 +1235,7 @@ impl Tunables {
11931235 sort: SortOverrides::merge(self.sort, other.sort),
11941236 terminal: Terminal::merge(self.terminal, other.terminal),
11951237 users: merge_maps(self.users, other.users),
1238 rooms: merge_maps(self.rooms, other.rooms),
11961239
11971240 // Proxy configuration sub-field do *not* get merged, so that a
11981241 // per-profile override won't inherit auth or headers from the
@@ -1259,6 +1302,7 @@ impl Tunables {
12591302 sort: self.sort.values(),
12601303 terminal: self.terminal.values(),
12611304 users: self.users.unwrap_or_default(),
1305 rooms: self.rooms.unwrap_or_default().into(),
12621306
12631307 default_markup: self.default_markup.unwrap_or_default(),
12641308 log_level: self.log_level.unwrap_or_else(|| DEFAULT_LOG_LEVEL.to_owned()),
src/tests.rs +1
@@ -186,6 +186,7 @@ pub fn mock_tunables() -> TunableValues {
186186 theme: "default".into(),
187187 typing_notice_send: true,
188188 typing_notice_display: true,
189 rooms: Default::default(),
189190 users: vec![(TEST_USER5.clone(), UserDisplayTunables {
190191 color: Some(Color::Black),
191192 name: Some("USER 5".into()),
src/worker.rs +24 −2
@@ -783,7 +783,7 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: b
783783 }
784784
785785 pinned.push((room.room_id().to_owned(), room.pinned_event_ids().unwrap_or_default()));
786 names_and_tags.push((room.room_id().to_owned(), name, tags, aliases, flags));
786 names_and_tags.push((room.clone(), name, tags, aliases, flags));
787787
788788 if room.is_direct().await.unwrap_or_default() {
789789 dms.push(room);
@@ -795,14 +795,36 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: b
795795 }
796796
797797 let mut locked = store.lock().await;
798
798799 locked.application.sync_info.spaces = spaces;
799800 locked.application.sync_info.rooms = rooms;
800801 locked.application.sync_info.dms = dms;
801802
802 for (room_id, name, tags, aliases, flags) in names_and_tags {
803 for (room, mut name, tags, aliases, flags) in names_and_tags {
804 let room_id = room.room_id().to_owned();
805
806 let rooms = &locked.application.settings.tunables.rooms;
807 let room_override = rooms
808 .rooms
809 .get(&room_id)
810 .or_else(|| aliases.iter().find_map(|alias| rooms.aliases.get(alias)));
811 if let Some(name_override) = room_override.and_then(|v| v.name.as_ref()) {
812 name.clone_from(name_override);
813 }
814
803815 locked.application.set_room_info(room_id, name, tags, aliases, flags);
804816 }
805817
818 let ChatStore { rooms, settings, .. } = &mut locked.application;
819 for (user_id, room_override) in settings.tunables.rooms.dms.iter() {
820 if let Some(name) = &room_override.name &&
821 let Some(room) = client.get_dm_room(user_id) &&
822 let Some(info) = rooms.get_mut(room.room_id())
823 {
824 info.name = Some(name.to_owned());
825 }
826 }
827
806828 for (room_id, pinned_events) in pinned {
807829 locked.application.get_room_info(room_id).pinned_events = pinned_events;
808830 }