do not send selfavatar on existing installation without resetting

This commit is contained in:
B. Petersen
2019-12-08 21:39:03 +01:00
committed by holger krekel
parent 7f723ef2bf
commit da421438cd
2 changed files with 22 additions and 4 deletions

View File

@@ -1598,6 +1598,16 @@ pub fn set_gossiped_timestamp(context: &Context, chat_id: u32, timestamp: i64) {
}
pub fn shall_attach_selfavatar(context: &Context, chat_id: u32) -> Result<bool, Error> {
// versions before 12/2019 already allowed to set selfavatar, however, it was never sent to others.
// to avoid sending out previously set selfavatars unexpectedly we added this additional check.
// it can be removed after some time.
if !context
.sql
.get_raw_config_bool(context, "attach_selfavatar")
{
return Ok(false);
}
let resend_every_days = 14;
let timestamp_some_days_ago = time() - resend_every_days * 24 * 60 * 60;
let needs_attach = context.sql.query_map(
@@ -2485,6 +2495,8 @@ mod tests {
let (contact_id, _) =
Contact::add_or_lookup(&t.ctx, "", "foo@bar.org", Origin::IncomingUnknownTo).unwrap();
add_contact_to_chat(&t.ctx, chat_id, contact_id);
assert!(!shall_attach_selfavatar(&t.ctx, chat_id).unwrap());
t.ctx.set_config(Config::Selfavatar, None).unwrap(); // setting to None also forces re-sending
assert!(shall_attach_selfavatar(&t.ctx, chat_id).unwrap());
assert!(set_selfavatar_timestamp(&t.ctx, chat_id, time()).is_ok());

View File

@@ -128,12 +128,18 @@ impl Context {
/// If `None` is passed as a value the value is cleared and set to the default if there is one.
pub fn set_config(&self, key: Config, value: Option<&str>) -> crate::sql::Result<()> {
match key {
Config::Selfavatar if value.is_some() => {
let blob = BlobObject::new_from_path(&self, value.unwrap())?;
let ret = self.sql.set_raw_config(self, key, Some(blob.as_name()));
Config::Selfavatar => {
self.sql
.execute("UPDATE contacts SET selfavatar_sent=0;", NO_PARAMS)?;
ret
self.sql
.set_raw_config_bool(self, "attach_selfavatar", true)?;
match value {
Some(value) => {
let blob = BlobObject::new_from_path(&self, value)?;
self.sql.set_raw_config(self, key, Some(blob.as_name()))
}
None => self.sql.set_raw_config(self, key, None),
}
}
Config::InboxWatch => {
let ret = self.sql.set_raw_config(self, key, value);