Commit 770dcd4b0c

770dcd4b0c71a44fd45adce415cc8963627c20be

parent: 77786698c4

Unregistered key

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

Support including other configs (#850)

Layout: unified · split

config.full.toml +10
@@ -7,6 +7,16 @@
7# If you want to start with something simple, use `config.example.toml` and add 7# If you want to start with something simple, use `config.example.toml` and add
8# things in one-by-one as you need them. 8# things in one-by-one as you need them.
9# ============================================================================== 9# ==============================================================================
10
11# Include other config files
12include = [
13 # load `~/.config/iamb/config.d/*.toml` in lexicographic order
14 "config.d",
15
16 # override all local settings with values from a global config
17 "/etc/iamb/config.toml"
18]
19
10default_profile = "default" 20default_profile = "default"
11 21
12# Specify a user profile to log in as. 22# Specify a user profile to log in as.
docs/iamb.5 +5
@@ -34,6 +34,11 @@ It's structure and fields are described below.
34.Sh CONFIGURATION 34.Sh CONFIGURATION
35These options are sections at the top-level of the file. 35These options are sections at the top-level of the file.
36.Bl -tag -width Ds 36.Bl -tag -width Ds
37.It Sy include
38A list of additional toml configs to include. Paths are either absolute or
39relative to the config directory and support shell variable expansion. Configs
40specified later take precedence. If the path is a directory all files ending in
41".toml" are loaded. Transitive includes are not supported.
37.It Sy profiles 42.It Sy profiles
38A map of profile names containing per-account information. 43A map of profile names containing per-account information.
39See 44See
src/base.rs +1 −1
@@ -2257,7 +2257,7 @@ impl RoomInfo {
2257 settings: &ApplicationSettings, 2257 settings: &ApplicationSettings,
2258 open_notifications: &mut HashMap<OwnedRoomId, Vec<NotificationHandle>>, 2258 open_notifications: &mut HashMap<OwnedRoomId, Vec<NotificationHandle>>,
2259 ) { 2259 ) {
2260 let user_id = &settings.profile.user_id; 2260 let user_id = &settings.user_id;
2261 2261
2262 let messages = match &thread { 2262 let messages = match &thread {
2263 ReceiptThread::Main => self.get_thread(None), 2263 ReceiptThread::Main => self.get_thread(None),
src/completions.rs +1 −1
@@ -561,7 +561,7 @@ fn complete_iamb_spaces(args: Vec<String>) -> Vec<String> {
561 561
562/// Tab completion for `:logout` 562/// Tab completion for `:logout`
563fn complete_iamb_logout(args: Vec<String>, store: &ChatStore) -> Vec<String> { 563fn complete_iamb_logout(args: Vec<String>, store: &ChatStore) -> Vec<String> {
564 let id = store.settings.profile.user_id.as_str(); 564 let id = store.settings.user_id.as_str();
565 match args.len() { 565 match args.len() {
566 1 if id.starts_with(&args[0]) => vec![id.to_string()], 566 1 if id.starts_with(&args[0]) => vec![id.to_string()],
567 _ => vec![], 567 _ => vec![],
src/config/mod.rs +183 −7
@@ -1,5 +1,6 @@
1//! # Logic for loading and validating application configuration 1//! # Logic for loading and validating application configuration
2use std::collections::HashSet; 2use std::collections::btree_map;
3use std::collections::{HashSet, hash_map};
3use std::env; 4use std::env;
4use std::fs::File; 5use std::fs::File;
5use std::io::{BufReader, BufWriter, Write as _}; 6use std::io::{BufReader, BufWriter, Write as _};
@@ -43,6 +44,16 @@ macro_rules! usage {
43 } 44 }
44} 45}
45 46
47macro_rules! merge_options {
48 ($a: expr, $b: expr) => {
49 match ($a, $b) {
50 (None, None) => None,
51 (Some(v), None) | (None, Some(v)) => Some(v),
52 (Some(a), Some(b)) => Some(a.merge(b)),
53 }
54 };
55}
56
46lazy_static! { 57lazy_static! {
47 pub static ref DEFAULT_VIA_SERVER: OwnedServerName = owned_server_name!("matrix.org"); 58 pub static ref DEFAULT_VIA_SERVER: OwnedServerName = owned_server_name!("matrix.org");
48} 59}
@@ -252,6 +263,73 @@ fn load_themes(
252 Ok(themes) 263 Ok(themes)
253} 264}
254 265
266/// This must be called before the alternate screen is entered
267fn load_config_includes(mut config: IambConfig, config_dir: &Path) -> IambConfig {
268 for include in std::mem::take(&mut config.include) {
269 let expanded = shellexpand::full(&include)
270 .unwrap_or_else(|err| panic!("unable to expand shell variables in include: {err}"));
271
272 let path = config_dir.join(&*expanded);
273
274 if path.is_dir() {
275 let dir = match path.read_dir() {
276 Ok(dir) => dir,
277 Err(e) => {
278 eprintln!("Unable to read config files in {path:?}: {e}");
279 continue;
280 },
281 };
282
283 // get paths in lexicographic order
284 let mut paths: Vec<_> = dir
285 .flat_map(|entry| {
286 match entry {
287 Ok(file) => Some(file),
288 Err(e) => {
289 eprintln!("Unable to read config file in {path:?}: {e}");
290 None
291 },
292 }
293 })
294 .collect();
295 paths.sort_unstable_by_key(|file| file.file_name());
296
297 for file in paths {
298 let path = file.path();
299 if path.extension().and_then(|e| e.to_str()) != Some("toml") {
300 continue;
301 }
302
303 match IambConfig::load_toml(&path) {
304 Ok(include) => {
305 if !include.include.is_empty() {
306 eprintln!("Ignoring nested includes in {path:?}");
307 }
308 config = include.merge(config);
309 },
310 Err(e) => {
311 eprintln!("Unable to load config file in {path:?}: {e}");
312 },
313 };
314 }
315 } else {
316 match IambConfig::load_toml(&path) {
317 Ok(include) => {
318 if !include.include.is_empty() {
319 eprintln!("Ignoring nested includes in {path:?}");
320 }
321 config = include.merge(config);
322 },
323 Err(e) => {
324 eprintln!("Unable to load config file in {path:?}: {e}");
325 },
326 };
327 }
328 }
329
330 config
331}
332
255struct IambVersion; 333struct IambVersion;
256 334
257impl From<IambVersion> for clap::builder::Str { 335impl From<IambVersion> for clap::builder::Str {
@@ -504,6 +582,27 @@ where
504 } 582 }
505} 583}
506 584
585fn merge_macros(profile: Option<Macros>, global: Option<Macros>) -> Option<Macros> {
586 match (global, profile) {
587 (Some(m), None) | (None, Some(m)) => Some(m),
588 (Some(mut global), Some(profile)) => {
589 for (mode, macros) in profile {
590 match global.entry(mode) {
591 hash_map::Entry::Vacant(entry) => {
592 entry.insert(macros);
593 },
594 hash_map::Entry::Occupied(mut entry) => {
595 entry.get_mut().extend(macros);
596 },
597 }
598 }
599
600 Some(global)
601 },
602 (None, None) => None,
603 }
604}
605
507#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, PartialEq)] 606#[derive(Copy, Clone, Debug, Default, Deserialize, Eq, PartialEq)]
508#[serde(rename_all = "kebab-case")] 607#[serde(rename_all = "kebab-case")]
509#[repr(u8)] 608#[repr(u8)]
@@ -1376,9 +1475,9 @@ pub enum Layout {
1376 Config { tabs: Vec<WindowLayout> }, 1475 Config { tabs: Vec<WindowLayout> },
1377} 1476}
1378 1477
1379#[derive(Clone, Deserialize)] 1478#[derive(Default, Clone, Deserialize)]
1380pub struct ProfileConfig { 1479pub struct ProfileConfig {
1381 pub user_id: OwnedUserId, 1480 pub user_id: Option<OwnedUserId>,
1382 pub password_file: Option<PathBuf>, 1481 pub password_file: Option<PathBuf>,
1383 pub url: Option<Url>, 1482 pub url: Option<Url>,
1384 pub settings: Option<Tunables>, 1483 pub settings: Option<Tunables>,
@@ -1389,8 +1488,38 @@ pub struct ProfileConfig {
1389 pub aliases: Option<Aliases>, 1488 pub aliases: Option<Aliases>,
1390} 1489}
1391 1490
1491impl ProfileConfig {
1492 fn merge(self, other: Self) -> Self {
1493 let user_id = self.user_id.or(other.user_id);
1494 let password_file = self.password_file.or(other.password_file);
1495 let url = self.url.or(other.url);
1496 let settings = merge_options!(self.settings, other.settings);
1497 let theme = merge_options!(self.theme, other.theme);
1498 let dirs = merge_options!(self.dirs, other.dirs);
1499 let layout = self.layout.or(other.layout);
1500 let macros = merge_macros(self.macros, other.macros);
1501 let aliases = merge_maps(self.aliases, other.aliases);
1502
1503 Self {
1504 user_id,
1505 password_file,
1506 url,
1507 settings,
1508 theme,
1509 dirs,
1510 layout,
1511 macros,
1512 aliases,
1513 }
1514 }
1515}
1516
1392#[derive(Clone, Deserialize)] 1517#[derive(Clone, Deserialize)]
1393pub struct IambConfig { 1518pub struct IambConfig {
1519 #[serde(default)]
1520 include: Vec<String>,
1521
1522 #[serde(default)]
1394 pub profiles: BTreeMap<String, ProfileConfig>, 1523 pub profiles: BTreeMap<String, ProfileConfig>,
1395 pub default_profile: Option<String>, 1524 pub default_profile: Option<String>,
1396 pub settings: Option<Tunables>, 1525 pub settings: Option<Tunables>,
@@ -1415,6 +1544,45 @@ impl IambConfig {
1415 1544
1416 Ok(config) 1545 Ok(config)
1417 } 1546 }
1547
1548 /// If a value is present in both configs, `self` is prefered.
1549 fn merge(self, other: Self) -> Self {
1550 // transitive includes are not supported
1551 let include = vec![];
1552
1553 let mut profiles = self.profiles;
1554 for (name, profile) in other.profiles {
1555 match profiles.entry(name) {
1556 btree_map::Entry::Vacant(entry) => {
1557 entry.insert(profile);
1558 },
1559 btree_map::Entry::Occupied(mut entry) => {
1560 let profile = std::mem::take(entry.get_mut()).merge(profile);
1561 entry.insert(profile);
1562 },
1563 }
1564 }
1565
1566 let default_profile = self.default_profile.or(other.default_profile);
1567 let settings = merge_options!(self.settings, other.settings);
1568 let dirs = merge_options!(self.dirs, other.dirs);
1569 let layout = self.layout.or(other.layout);
1570 let macros = merge_macros(self.macros, other.macros);
1571 let aliases = merge_maps(self.aliases, other.aliases);
1572 let theme = merge_options!(self.theme, other.theme);
1573
1574 Self {
1575 include,
1576 profiles,
1577 default_profile,
1578 settings,
1579 dirs,
1580 layout,
1581 macros,
1582 aliases,
1583 theme,
1584 }
1585 }
1418} 1586}
1419 1587
1420#[derive(Clone)] 1588#[derive(Clone)]
@@ -1427,6 +1595,7 @@ pub struct ApplicationSettings {
1427 pub sqlite_dir: PathBuf, 1595 pub sqlite_dir: PathBuf,
1428 pub sqlite_cache_dir: PathBuf, 1596 pub sqlite_cache_dir: PathBuf,
1429 pub profile_name: String, 1597 pub profile_name: String,
1598 pub user_id: OwnedUserId,
1430 pub profile: ProfileConfig, 1599 pub profile: ProfileConfig,
1431 pub theme: Arc<theme::ThemeValues>, 1600 pub theme: Arc<theme::ThemeValues>,
1432 pub themes: Arc<CompletionMap<String, theme::Theme>>, 1601 pub themes: Arc<CompletionMap<String, theme::Theme>>,
@@ -1476,6 +1645,8 @@ impl ApplicationSettings {
1476 ); 1645 );
1477 }; 1646 };
1478 1647
1648 let config = load_config_includes(config, &config_dir);
1649
1479 let IambConfig { 1650 let IambConfig {
1480 mut profiles, 1651 mut profiles,
1481 default_profile, 1652 default_profile,
@@ -1485,6 +1656,7 @@ impl ApplicationSettings {
1485 macros, 1656 macros,
1486 aliases, 1657 aliases,
1487 theme, 1658 theme,
1659 ..
1488 } = config; 1660 } = config;
1489 1661
1490 validate_profile_names(&profiles); 1662 validate_profile_names(&profiles);
@@ -1526,8 +1698,10 @@ impl ApplicationSettings {
1526 } 1698 }
1527 }; 1699 };
1528 1700
1701 let user_id = profile.user_id.clone().expect("Active profile does not have a user id");
1702
1529 let aliases = merge_maps(profile.aliases.take(), aliases).unwrap_or_default(); 1703 let aliases = merge_maps(profile.aliases.take(), aliases).unwrap_or_default();
1530 let macros = merge_maps(profile.macros.take(), macros).unwrap_or_default(); 1704 let macros = merge_macros(profile.macros.take(), macros).unwrap_or_default();
1531 let layout = profile.layout.take().or(layout).unwrap_or_default(); 1705 let layout = profile.layout.take().or(layout).unwrap_or_default();
1532 1706
1533 let tunables = global.unwrap_or_default(); 1707 let tunables = global.unwrap_or_default();
@@ -1600,6 +1774,7 @@ impl ApplicationSettings {
1600 sqlite_dir, 1774 sqlite_dir,
1601 sqlite_cache_dir, 1775 sqlite_cache_dir,
1602 profile_name, 1776 profile_name,
1777 user_id,
1603 profile, 1778 profile,
1604 themes, 1779 themes,
1605 theme, 1780 theme,
@@ -1656,7 +1831,7 @@ impl ApplicationSettings {
1656 let reader = BufReader::new(file); 1831 let reader = BufReader::new(file);
1657 let saved: SavedDevice = serde_json::from_reader(reader).ok()?; 1832 let saved: SavedDevice = serde_json::from_reader(reader).ok()?;
1658 1833
1659 if saved.is_user(&self.profile.user_id) { 1834 if saved.is_user(&self.user_id) {
1660 Some(saved) 1835 Some(saved)
1661 } else { 1836 } else {
1662 None 1837 None
@@ -1674,14 +1849,14 @@ impl ApplicationSettings {
1674 let saved = match client_id { 1849 let saved = match client_id {
1675 Some(client) => { 1850 Some(client) => {
1676 SavedDevice::OAuth { 1851 SavedDevice::OAuth {
1677 user_id: self.profile.user_id.clone(), 1852 user_id: self.user_id.clone(),
1678 device_id: device_id.to_owned(), 1853 device_id: device_id.to_owned(),
1679 client_id: client, 1854 client_id: client,
1680 } 1855 }
1681 }, 1856 },
1682 None => { 1857 None => {
1683 SavedDevice::MatrixAuth { 1858 SavedDevice::MatrixAuth {
1684 user_id: self.profile.user_id.clone(), 1859 user_id: self.user_id.clone(),
1685 device_id: device_id.to_owned(), 1860 device_id: device_id.to_owned(),
1686 } 1861 }
1687 }, 1862 },
@@ -2327,6 +2502,7 @@ time_format = "%"
2327 macros, 2502 macros,
2328 aliases, 2503 aliases,
2329 theme, 2504 theme,
2505 ..
2330 } = &config; 2506 } = &config;
2331 2507
2332 // There should be an example object for each top-level field. 2508 // There should be an example object for each top-level field.
src/main.rs +2 −2
@@ -878,7 +878,7 @@ impl Application {
878 }, 878 },
879 HomeserverAction::ProfileFieldShow(field) => { 879 HomeserverAction::ProfileFieldShow(field) => {
880 let client = &store.application.worker.client; 880 let client = &store.application.worker.client;
881 let user_id = store.application.settings.profile.user_id.clone(); 881 let user_id = store.application.settings.user_id.clone();
882 let account = client.account(); 882 let account = client.account();
883 let value = account 883 let value = account
884 .fetch_profile_field_of(user_id, field.clone()) 884 .fetch_profile_field_of(user_id, field.clone())
@@ -1102,7 +1102,7 @@ async fn login_normal(
1102 settings: &ApplicationSettings, 1102 settings: &ApplicationSettings,
1103 store: &AsyncProgramStore, 1103 store: &AsyncProgramStore,
1104) -> IambResult<()> { 1104) -> IambResult<()> {
1105 println!("* Logging in for {}...", settings.profile.user_id); 1105 println!("* Logging in for {}...", settings.user_id);
1106 login(worker, settings).await?; 1106 login(worker, settings).await?;
1107 println!("* Syncing..."); 1107 println!("* Syncing...");
1108 worker.spawn_sync()?; 1108 worker.spawn_sync()?;
src/message/mod.rs +4 −4
@@ -1145,7 +1145,7 @@ impl Message {
1145 let marker = info 1145 let marker = info
1146 .user_receipts 1146 .user_receipts
1147 .get(&self.receipt_thread(info)) 1147 .get(&self.receipt_thread(info))
1148 .and_then(|receipts| receipts.get(&settings.profile.user_id)); 1148 .and_then(|receipts| receipts.get(&settings.user_id));
1149 1149
1150 is_after_read_marker(prev, marker) 1150 is_after_read_marker(prev, marker)
1151 } 1151 }
@@ -1213,7 +1213,7 @@ impl Message {
1213 let unthreaded = info.read_event_users(ReceiptThread::Unthreaded, event_id); 1213 let unthreaded = info.read_event_users(ReceiptThread::Unthreaded, event_id);
1214 threaded 1214 threaded
1215 .chain(unthreaded) 1215 .chain(unthreaded)
1216 .filter(|user_id| **user_id != settings.profile.user_id) 1216 .filter(|user_id| **user_id != settings.user_id)
1217 .map(|user_id| user_id.to_owned()) 1217 .map(|user_id| user_id.to_owned())
1218 .collect() 1218 .collect()
1219 }) 1219 })
@@ -2072,7 +2072,7 @@ pub mod tests {
2072 2072
2073 let prev = mock_message1(); 2073 let prev = mock_message1();
2074 let msg = mock_message2(); 2074 let msg = mock_message2();
2075 let user_id = settings.profile.user_id.clone(); 2075 let user_id = settings.user_id.clone();
2076 2076
2077 // Without a marker, no trackbar is drawn. 2077 // Without a marker, no trackbar is drawn.
2078 let text = msg.show(Some(&prev), false, width, &info, &settings, &previews); 2078 let text = msg.show(Some(&prev), false, width, &info, &settings, &previews);
@@ -2098,7 +2098,7 @@ pub mod tests {
2098 fn test_show_trackbar_thread() { 2098 fn test_show_trackbar_thread() {
2099 let settings = mock_settings(); 2099 let settings = mock_settings();
2100 let mut info = mock_room(); 2100 let mut info = mock_room();
2101 let user_id = settings.profile.user_id.clone(); 2101 let user_id = settings.user_id.clone();
2102 2102
2103 let prev = mock_message1(); 2103 let prev = mock_message1();
2104 let msg = mock_message2(); 2104 let msg = mock_message2();
src/tests.rs +2 −1
@@ -228,8 +228,9 @@ pub fn mock_settings() -> ApplicationSettings {
228 sqlite_cache_dir: PathBuf::new(), 228 sqlite_cache_dir: PathBuf::new(),
229 229
230 profile_name: "test".into(), 230 profile_name: "test".into(),
231 user_id: user_id!("@user:example.com").to_owned(),
231 profile: ProfileConfig { 232 profile: ProfileConfig {
232 user_id: user_id!("@user:example.com").to_owned(), 233 user_id: Some(user_id!("@user:example.com").to_owned()),
233 password_file: None, 234 password_file: None,
234 url: None, 235 url: None,
235 settings: None, 236 settings: None,
src/util.rs +1 −1
@@ -226,7 +226,7 @@ pub fn setup_tty(settings: &ApplicationSettings) -> std::io::Result<()> {
226 } 226 }
227 227
228 if settings.tunables.terminal.enable_title { 228 if settings.tunables.terminal.enable_title {
229 let title = format!("iamb ({})", settings.profile.user_id.as_str()); 229 let title = format!("iamb ({})", settings.user_id.as_str());
230 crossterm::execute!(stdout(), SetTitle(title))?; 230 crossterm::execute!(stdout(), SetTitle(title))?;
231 } 231 }
232 232
src/windows/room/chat.rs +4 −4
@@ -230,7 +230,7 @@ impl ChatState {
230 .await 230 .await
231 }, 231 },
232 MessageAction::Edit => { 232 MessageAction::Edit => {
233 if msg.sender != settings.profile.user_id { 233 if msg.sender != settings.user_id {
234 let msg = "Cannot edit messages sent by someone else"; 234 let msg = "Cannot edit messages sent by someone else";
235 let err = UIError::Failure(msg.into()); 235 let err = UIError::Failure(msg.into());
236 236
@@ -817,7 +817,7 @@ pub async fn msg_react(
817 MessageEvent::UnstablePoll(ev) => ev.event_id().to_owned(), 817 MessageEvent::UnstablePoll(ev) => ev.event_id().to_owned(),
818 }; 818 };
819 819
820 if info.user_reactions_contains(&settings.profile.user_id, &event_id, &emoji) { 820 if info.user_reactions_contains(&settings.user_id, &event_id, &emoji) {
821 let msg = format!("You’ve already reacted to this message with {emoji}"); 821 let msg = format!("You’ve already reacted to this message with {emoji}");
822 let err = UIError::Failure(msg); 822 let err = UIError::Failure(msg);
823 823
@@ -947,7 +947,7 @@ pub async fn msg_unreact(
947 }; 947 };
948 948
949 let reactions = reactions.iter().filter_map(|(event_id, (reaction, user_id, _))| { 949 let reactions = reactions.iter().filter_map(|(event_id, (reaction, user_id, _))| {
950 if user_id != &settings.profile.user_id { 950 if user_id != &settings.user_id {
951 return None; 951 return None;
952 } 952 }
953 953
@@ -1000,7 +1000,7 @@ pub async fn msg_pin(
1000 .await 1000 .await
1001 .map_err(matrix_sdk::Error::from) 1001 .map_err(matrix_sdk::Error::from)
1002 .map_err(IambError::from)? 1002 .map_err(IambError::from)?
1003 .user_can_send_state(&settings.profile.user_id, StateEventType::RoomPinnedEvents); 1003 .user_can_send_state(&settings.user_id, StateEventType::RoomPinnedEvents);
1004 1004
1005 if !can_pin { 1005 if !can_pin {
1006 return Err(IambError::InsufficientPermission.into()); 1006 return Err(IambError::InsufficientPermission.into());
src/windows/room/message.rs +1 −3
@@ -17,9 +17,7 @@ fn contains_reaction(
17 .as_origin() 17 .as_origin()
18 .and_then(|event_id| info.reactions.get(event_id)) 18 .and_then(|event_id| info.reactions.get(event_id))
19 .is_some_and(|reacts| { 19 .is_some_and(|reacts| {
20 reacts 20 reacts.values().any(|(k, user, _)| user == &settings.user_id && k == key)
21 .values()
22 .any(|(k, user, _)| user == &settings.profile.user_id && k == key)
23 }) 21 })
24} 22}
25 23
src/windows/room/mod.rs +1 −1
@@ -599,7 +599,7 @@ pub async fn room_command(
599 "Cannot show a single alias; use `:room aliases show` instead.".into() 599 "Cannot show a single alias; use `:room aliases show` instead.".into()
600 }, 600 },
601 RoomField::UserName => { 601 RoomField::UserName => {
602 let user_id = &store.application.settings.profile.user_id; 602 let user_id = &store.application.settings.user_id;
603 let Some(member) = room.get_member(user_id).await.map_err(IambError::from)? 603 let Some(member) = room.get_member(user_id).await.map_err(IambError::from)?
604 else { 604 else {
605 let msg = "Cannot find membership data".into(); 605 let msg = "Cannot find membership data".into();
src/windows/room/scrollback.rs +2 −2
@@ -1851,7 +1851,7 @@ mod tests {
1851 let mut store = mock_store().await; 1851 let mut store = mock_store().await;
1852 store.application.settings.tunables.typing_notice_display = false; 1852 store.application.settings.tunables.typing_notice_display = false;
1853 1853
1854 let user_id = store.application.settings.profile.user_id.clone(); 1854 let user_id = store.application.settings.user_id.clone();
1855 store.application.get_room_info(TEST_ROOM1_ID.clone()).set_receipt( 1855 store.application.get_room_info(TEST_ROOM1_ID.clone()).set_receipt(
1856 ReceiptThread::Main, 1856 ReceiptThread::Main,
1857 user_id, 1857 user_id,
@@ -1900,7 +1900,7 @@ mod tests {
1900 // or not it is a private or public receipt that we send to the home server. 1900 // or not it is a private or public receipt that we send to the home server.
1901 for read_receipt_send in [true, false] { 1901 for read_receipt_send in [true, false] {
1902 let mut store = draw_focused_room(read_receipt_send).await; 1902 let mut store = draw_focused_room(read_receipt_send).await;
1903 let user_id = store.application.settings.profile.user_id.clone(); 1903 let user_id = store.application.settings.user_id.clone();
1904 let info = store.application.get_room_info(TEST_ROOM1_ID.clone()); 1904 let info = store.application.get_room_info(TEST_ROOM1_ID.clone());
1905 1905
1906 let receipt = info 1906 let receipt = info
src/windows/room/space.rs +2 −2
@@ -66,7 +66,7 @@ impl SpaceState {
66 .map_err(matrix_sdk::Error::from) 66 .map_err(matrix_sdk::Error::from)
67 .map_err(IambError::from)? 67 .map_err(IambError::from)?
68 .user_can_send_state( 68 .user_can_send_state(
69 &store.application.settings.profile.user_id, 69 &store.application.settings.user_id,
70 StateEventType::SpaceChild, 70 StateEventType::SpaceChild,
71 ) 71 )
72 { 72 {
@@ -117,7 +117,7 @@ impl SpaceState {
117 .map_err(matrix_sdk::Error::from) 117 .map_err(matrix_sdk::Error::from)
118 .map_err(IambError::from)? 118 .map_err(IambError::from)?
119 .user_can_send_state( 119 .user_can_send_state(
120 &store.application.settings.profile.user_id, 120 &store.application.settings.user_id,
121 StateEventType::SpaceChild, 121 StateEventType::SpaceChild,
122 ) 122 )
123 { 123 {
src/worker.rs +13 −14
@@ -510,10 +510,10 @@ fn insert_msgs_and_receipts(
510 // ignoring redaction events because we get them bundled with the redacted event 510 // ignoring redaction events because we get them bundled with the redacted event
511 }, 511 },
512 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollStart(ev)) => { 512 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollStart(ev)) => {
513 info.insert_poll_start(ev, &settings.profile.user_id); 513 info.insert_poll_start(ev, &settings.user_id);
514 }, 514 },
515 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::UnstablePollStart(ev)) => { 515 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::UnstablePollStart(ev)) => {
516 info.insert_unstable_poll_start(ev, &settings.profile.user_id); 516 info.insert_unstable_poll_start(ev, &settings.user_id);
517 }, 517 },
518 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollResponse(ev)) => { 518 AnyTimelineEvent::MessageLike(AnyMessageLikeEvent::PollResponse(ev)) => {
519 if let MessageLikeEvent::Original(ev) = ev { 519 if let MessageLikeEvent::Original(ev) = ev {
@@ -1330,8 +1330,7 @@ async fn create_client_inner(
1330 builder.homeserver_url(url.as_str()) 1330 builder.homeserver_url(url.as_str())
1331 } else { 1331 } else {
1332 // Try to discover the homeserver from the user ID. 1332 // Try to discover the homeserver from the user ID.
1333 let account = &settings.profile; 1333 builder.server_name(settings.user_id.server_name())
1334 builder.server_name(account.user_id.server_name())
1335 }; 1334 };
1336 1335
1337 builder.build().await 1336 builder.build().await
@@ -1341,7 +1340,7 @@ pub async fn create_client(settings: &ApplicationSettings) -> Client {
1341 let account = &settings.profile; 1340 let account = &settings.profile;
1342 let res = match create_client_inner(&account.url, settings).await { 1341 let res = match create_client_inner(&account.url, settings).await {
1343 Err(ClientBuildError::AutoDiscovery(_)) => { 1342 Err(ClientBuildError::AutoDiscovery(_)) => {
1344 let url = format!("https://{}/", account.user_id.server_name().as_str()); 1343 let url = format!("https://{}/", settings.user_id.server_name().as_str());
1345 let url = Url::parse(&url).unwrap(); 1344 let url = Url::parse(&url).unwrap();
1346 create_client_inner(&Some(url), settings).await 1345 create_client_inner(&Some(url), settings).await
1347 }, 1346 },
@@ -1675,7 +1674,7 @@ impl ClientWorker {
1675 .content 1674 .content
1676 .user_ids 1675 .user_ids
1677 .into_iter() 1676 .into_iter()
1678 .filter(|u| u != &locked.application.settings.profile.user_id) 1677 .filter(|u| u != &locked.application.settings.user_id)
1679 .collect(); 1678 .collect();
1680 1679
1681 locked.application.get_room_info(room_id).set_typing(users); 1680 locked.application.get_room_info(room_id).set_typing(users);
@@ -1869,7 +1868,7 @@ impl ClientWorker {
1869 let info = rooms.get_or_default(room_id.to_owned()); 1868 let info = rooms.get_or_default(room_id.to_owned());
1870 1869
1871 let full_ev = ev.into_full_event(room_id.to_owned()); 1870 let full_ev = ev.into_full_event(room_id.to_owned());
1872 info.insert_poll_start(full_ev, &settings.profile.user_id); 1871 info.insert_poll_start(full_ev, &settings.user_id);
1873 1872
1874 update_event_receipts(info, &room, event_id).await; 1873 update_event_receipts(info, &room, event_id).await;
1875 } 1874 }
@@ -1894,7 +1893,7 @@ impl ClientWorker {
1894 let info = rooms.get_or_default(room_id.to_owned()); 1893 let info = rooms.get_or_default(room_id.to_owned());
1895 1894
1896 let full_ev = ev.into_full_event(room_id.to_owned()); 1895 let full_ev = ev.into_full_event(room_id.to_owned());
1897 info.insert_unstable_poll_start(full_ev, &settings.profile.user_id); 1896 info.insert_unstable_poll_start(full_ev, &settings.user_id);
1898 1897
1899 update_event_receipts(info, &room, event_id).await; 1898 update_event_receipts(info, &room, event_id).await;
1900 } 1899 }
@@ -2189,7 +2188,7 @@ impl ClientWorker {
2189 LoginStyle::Password(password) => { 2188 LoginStyle::Password(password) => {
2190 let mut login = client 2189 let mut login = client
2191 .matrix_auth() 2190 .matrix_auth()
2192 .login_username(&self.settings.profile.user_id, &password) 2191 .login_username(&self.settings.user_id, &password)
2193 .initial_device_display_name(initial_devname().as_str()); 2192 .initial_device_display_name(initial_devname().as_str());
2194 if let Some(device) = self.settings.read_saved_device() { 2193 if let Some(device) = self.settings.read_saved_device() {
2195 login = login.device_id(device.device_id().as_str()); 2194 login = login.device_id(device.device_id().as_str());
@@ -2224,7 +2223,7 @@ impl ClientWorker {
2224 LoginStyle::OAuth => { 2223 LoginStyle::OAuth => {
2225 oauth_login( 2224 oauth_login(
2226 self.client.clone(), 2225 self.client.clone(),
2227 &self.settings.profile.user_id, 2226 &self.settings.user_id,
2228 self.settings.read_saved_device(), 2227 self.settings.read_saved_device(),
2229 ) 2228 )
2230 .await?; 2229 .await?;
@@ -2241,7 +2240,7 @@ impl ClientWorker {
2241 2240
2242 async fn logout(&mut self, user_id: String) -> IambResult<EditInfo> { 2241 async fn logout(&mut self, user_id: String) -> IambResult<EditInfo> {
2243 // Verify that the user is logging out of the correct profile. 2242 // Verify that the user is logging out of the correct profile.
2244 let curr = self.settings.profile.user_id.as_str(); 2243 let curr = self.settings.user_id.as_str();
2245 2244
2246 if user_id != curr { 2245 if user_id != curr {
2247 let msg = format!("Incorrect user ID (currently logged in as {curr})"); 2246 let msg = format!("Incorrect user ID (currently logged in as {curr})");
@@ -2406,12 +2405,12 @@ impl ClientWorker {
2406 }; 2405 };
2407 2406
2408 let msg = format!("* Successfully logged in with {}!", user); 2407 let msg = format!("* Successfully logged in with {}!", user);
2409 if user != self.settings.profile.user_id { 2408 if user != self.settings.user_id {
2410 // Trace warning if this happens 2409 // Trace warning if this happens
2411 tracing::warn!("logged in as a different user than expected"); 2410 tracing::warn!("logged in as a different user than expected");
2412 self.settings.profile.user_id = user.to_owned(); 2411 self.settings.user_id = user.to_owned();
2413 let store = self.store.as_ref().expect("initialised worker should have store"); 2412 let store = self.store.as_ref().expect("initialised worker should have store");
2414 store.lock().await.application.settings.profile.user_id = user.to_owned(); 2413 store.lock().await.application.settings.user_id = user.to_owned();
2415 } 2414 }
2416 Ok(Some(InfoMessage::from(msg))) 2415 Ok(Some(InfoMessage::from(msg)))
2417 } 2416 }