Skip to content

Commit

Permalink
feat: Sync Config::Displayname across devices (#4893)
Browse files Browse the repository at this point in the history
We already synchronise status/footer when we see a self-sent message with a Chat-Version
header. Would be nice to do the same for display name.

But let's do it the same way as for `Config::{MdnsEnabled,ShowEmails}`. Otherwise, if we sync the
display name using the "From" header, smth like `Param::StatusTimestamp` is needed then to reject
outdated display names. Also this timestamp needs to be updated when `Config::Displayname` is set
locally. Also this wouldn't work if system time isn't synchronised on devices. Also using multiple
approaches to sync different config values would lead to more code and bugs while having almost no
value -- using "From" only saves some bytes and allows to sync some things w/o the synchronisation
itself to be enabled. But the latter also can be a downside -- if it's usual synchonisation, you can
(potentially) disable it and share the same email account across people in some organisation
allowing them to have different display names. With using "From" for synchronisation such a
capability definitely requires a new config option.
  • Loading branch information
iequidoo committed Nov 24, 2023
1 parent ce6ed83 commit 11dbd48
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
26 changes: 20 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ impl Config {
/// This must be checked on both sides so that if there are different client versions, the
/// synchronisation of a particular option is done or not done both ways.
pub(crate) fn is_synced(&self) -> bool {
matches!(self, Self::MdnsEnabled | Self::ShowEmails)
matches!(
self,
Self::Displayname | Self::MdnsEnabled | Self::ShowEmails
)
}
}

Expand Down Expand Up @@ -482,8 +485,9 @@ impl Context {
&self,
sync: sync::Sync,
key: Config,
value: Option<&str>,
mut value: Option<&str>,
) -> Result<()> {
let better_value;
match key {
Config::Selfavatar => {
self.sql
Expand All @@ -510,10 +514,11 @@ impl Context {
ret?
}
Config::Displayname => {
let value = value.map(improve_single_line_input);
self.sql
.set_raw_config(key.as_ref(), value.as_deref())
.await?;
if let Some(v) = value {
better_value = improve_single_line_input(v);
value = Some(&better_value);
}
self.sql.set_raw_config(key.as_ref(), value).await?;
}
Config::Socks5Enabled
| Config::BccSelf
Expand Down Expand Up @@ -911,6 +916,15 @@ mod tests {
sync(&alice0, &alice1).await?;
assert!(alice1.get_config_bool(Config::MdnsEnabled).await?);

alice0
.set_config(Config::Displayname, Some("Alice Sync"))
.await?;
sync(&alice0, &alice1).await?;
assert_eq!(
alice1.get_config(Config::Displayname).await?,
Some("Alice Sync".to_string())
);

Ok(())
}
}
10 changes: 4 additions & 6 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ pub(crate) async fn receive_imf_inner(
///
/// Also returns whether it is blocked or not and its origin.
///
/// * `prevent_rename`: passed through to `add_or_lookup_contacts_by_address_list()`
/// * `prevent_rename`: if true, the display_name of this contact will not be changed. Useful for
/// mailing lists: In some mailing lists, many users write from the same address but with different
/// display names. We don't want the display name to change every time the user gets a new email from
/// a mailing list.
///
/// Returns `None` if From field does not contain a valid contact address.
pub async fn from_field_to_contact_id(
Expand Down Expand Up @@ -2582,11 +2585,6 @@ pub(crate) async fn get_prefetch_parent_message(
/// Looks up contact IDs from the database given the list of recipients.
///
/// Returns vector of IDs guaranteed to be unique.
///
/// * param `prevent_rename`: if true, the display_name of this contact will not be changed. Useful for
/// mailing lists: In some mailing lists, many users write from the same address but with different
/// display names. We don't want the display name to change every time the user gets a new email from
/// a mailing list.
async fn add_or_lookup_contacts_by_address_list(
context: &Context,
address_list: &[SingleInfo],
Expand Down

0 comments on commit 11dbd48

Please sign in to comment.