Commit 55ad2d3402
Unregistered key
Layout: unified · split
config.full.toml +5
| @@ -93,6 +93,11 @@ enable_title = true | ||
| 93 | 93 | [settings.users] |
| 94 | 94 | "@user:matrix.org" = { "name" = "John Doe", "color" = "magenta" } |
| 95 | 95 | |
| 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 | ||
| 96 | 101 | # Specify a specific tab and window layout to use every time iamb starts: |
| 97 | 102 | [layout] |
| 98 | 103 | style = "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 | ||
| 320 | 320 | .It Sy unread |
| 321 | 321 | Show if a non-muted, non-calmed room has unread messages or mentions. |
| 322 | 322 | .El |
| 323 | .It Sy rooms | |
| 324 | Overrides values for the specified room. | |
| 325 | See | |
| 326 | .Sx "ROOM OVERRIDES" | |
| 327 | for details on the format. | |
| 323 | 328 | .It Sy send_on_enter |
| 324 | 329 | If |
| 325 | 330 | .Sy true |
| @@ -1038,6 +1043,23 @@ state.color = "cyan" | ||
| 1038 | 1043 | tabs.title.modifiers = ["~bold", "italic"] |
| 1039 | 1044 | windows.title.modifiers = ["~bold", "italic"] |
| 1040 | 1045 | .Ed |
| 1046 | .Sh "ROOM OVERRIDES" | |
| 1047 | The | |
| 1048 | .Sy settings.rooms | |
| 1049 | subsections allows overriding how specific rooms are displayed. | |
| 1050 | Overrides are mapped onto Matrix Room IDs, Matrix Room Aliases, or User IDs for DMs. | |
| 1051 | They are typically written as inline tables containing the following keys: | |
| 1052 | .Bl -tag -width Ds | |
| 1053 | .It Sy name | |
| 1054 | Change 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 | |
| 1041 | 1063 | .Sh "USER OVERRIDES" |
| 1042 | 1064 | The |
| 1043 | 1065 | .Sy settings.users |
src/config/mod.rs +44
| @@ -568,6 +568,46 @@ pub struct UserDisplayTunables { | ||
| 568 | 568 | |
| 569 | 569 | pub type UserOverrides = HashMap<OwnedUserId, UserDisplayTunables>; |
| 570 | 570 | |
| 571 | #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash)] | |
| 572 | #[serde(untagged)] | |
| 573 | pub enum RoomOverrideKey { | |
| 574 | User(OwnedUserId), | |
| 575 | Room(OwnedRoomId), | |
| 576 | Alias(OwnedRoomAliasId), | |
| 577 | } | |
| 578 | ||
| 579 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] | |
| 580 | pub struct RoomOverrideTunables { | |
| 581 | pub name: Option<String>, | |
| 582 | } | |
| 583 | ||
| 584 | pub type RoomOverrides = HashMap<RoomOverrideKey, RoomOverrideTunables>; | |
| 585 | ||
| 586 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq)] | |
| 587 | pub struct RoomOverrideValues { | |
| 588 | pub rooms: HashMap<OwnedRoomId, RoomOverrideTunables>, | |
| 589 | pub aliases: HashMap<OwnedRoomAliasId, RoomOverrideTunables>, | |
| 590 | pub dms: HashMap<OwnedUserId, RoomOverrideTunables>, | |
| 591 | } | |
| 592 | ||
| 593 | impl 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 | ||
| 571 | 611 | fn merge_maps<M, K, V>(profile: Option<M>, global: Option<M>) -> Option<M> |
| 572 | 612 | where |
| 573 | 613 | M: Extend<(K, V)> + IntoIterator<Item = (K, V)>, |
| @@ -1093,6 +1133,7 @@ pub struct TunableValues { | ||
| 1093 | 1133 | pub typing_notice_send: bool, |
| 1094 | 1134 | pub typing_notice_display: bool, |
| 1095 | 1135 | pub users: UserOverrides, |
| 1136 | pub rooms: RoomOverrideValues, | |
| 1096 | 1137 | pub username_display: UserDisplayStyle, |
| 1097 | 1138 | pub message_user_color: bool, |
| 1098 | 1139 | pub default_register: Option<Register>, |
| @@ -1138,6 +1179,7 @@ pub struct Tunables { | ||
| 1138 | 1179 | |
| 1139 | 1180 | /// Subsection for overriding how specific Matrix users are rendered. |
| 1140 | 1181 | pub users: Option<UserOverrides>, |
| 1182 | pub rooms: Option<RoomOverrides>, | |
| 1141 | 1183 | |
| 1142 | 1184 | pub default_markup: Option<MarkupFormat>, |
| 1143 | 1185 | pub ignorecase: Option<bool>, |
| @@ -1193,6 +1235,7 @@ impl Tunables { | ||
| 1193 | 1235 | sort: SortOverrides::merge(self.sort, other.sort), |
| 1194 | 1236 | terminal: Terminal::merge(self.terminal, other.terminal), |
| 1195 | 1237 | users: merge_maps(self.users, other.users), |
| 1238 | rooms: merge_maps(self.rooms, other.rooms), | |
| 1196 | 1239 | |
| 1197 | 1240 | // Proxy configuration sub-field do *not* get merged, so that a |
| 1198 | 1241 | // per-profile override won't inherit auth or headers from the |
| @@ -1259,6 +1302,7 @@ impl Tunables { | ||
| 1259 | 1302 | sort: self.sort.values(), |
| 1260 | 1303 | terminal: self.terminal.values(), |
| 1261 | 1304 | users: self.users.unwrap_or_default(), |
| 1305 | rooms: self.rooms.unwrap_or_default().into(), | |
| 1262 | 1306 | |
| 1263 | 1307 | default_markup: self.default_markup.unwrap_or_default(), |
| 1264 | 1308 | 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 { | ||
| 186 | 186 | theme: "default".into(), |
| 187 | 187 | typing_notice_send: true, |
| 188 | 188 | typing_notice_display: true, |
| 189 | rooms: Default::default(), | |
| 189 | 190 | users: vec![(TEST_USER5.clone(), UserDisplayTunables { |
| 190 | 191 | color: Some(Color::Black), |
| 191 | 192 | 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 | ||
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | 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)); | |
| 787 | 787 | |
| 788 | 788 | if room.is_direct().await.unwrap_or_default() { |
| 789 | 789 | dms.push(room); |
| @@ -795,14 +795,36 @@ async fn refresh_rooms(client: &Client, store: &AsyncProgramStore, first_sync: b | ||
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | let mut locked = store.lock().await; |
| 798 | ||
| 798 | 799 | locked.application.sync_info.spaces = spaces; |
| 799 | 800 | locked.application.sync_info.rooms = rooms; |
| 800 | 801 | locked.application.sync_info.dms = dms; |
| 801 | 802 | |
| 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 | ||
| 803 | 815 | locked.application.set_room_info(room_id, name, tags, aliases, flags); |
| 804 | 816 | } |
| 805 | 817 | |
| 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 | ||
| 806 | 828 | for (room_id, pinned_events) in pinned { |
| 807 | 829 | locked.application.get_room_info(room_id).pinned_events = pinned_events; |
| 808 | 830 | } |