diff --git a/presage/src/manager/registered.rs b/presage/src/manager/registered.rs index e3d7a54d4..eab3208af 100644 --- a/presage/src/manager/registered.rs +++ b/presage/src/manager/registered.rs @@ -1098,7 +1098,7 @@ async fn save_message( profile_key: profile_key.bytes.to_vec(), color: None, blocked: false, - expire_timer: 0, + expire_timer: data_message.expire_timer.unwrap_or_default(), inbox_position: 0, archived: false, avatar: None, @@ -1112,6 +1112,8 @@ async fn save_message( store.upsert_profile_key(&sender_uuid, profile_key)?; } + store.update_expire_timer(&thread, data_message.expire_timer.unwrap_or_default())?; + match data_message { DataMessage { delete: diff --git a/presage/src/store.rs b/presage/src/store.rs index cee012d1d..4f77c9a3d 100644 --- a/presage/src/store.rs +++ b/presage/src/store.rs @@ -4,7 +4,7 @@ use std::{fmt, ops::RangeBounds, time::SystemTime}; use libsignal_service::{ content::{ContentBody, Metadata}, - groups_v2::Group, + groups_v2::{Group, Timer}, models::Contact, prelude::{Content, ProfileKey, Uuid, UuidError}, proto::{ @@ -170,6 +170,34 @@ pub trait ContentsStore { } } + /// Update the expire timer from a [Thread], which corresponds to either [Contact::expire_timer] + /// or [Group::disappearing_messages_timer]. + fn update_expire_timer( + &mut self, + thread: &Thread, + timer: u32, + ) -> Result<(), Self::ContentsStoreError> { + log::trace!("update expire timer of {:?} to {}", thread, timer); + match thread { + Thread::Contact(uuid) => { + let contact = self.contact_by_id(uuid)?; + if let Some(mut contact) = contact { + contact.expire_timer = timer; + self.save_contact(&contact)?; + } + Ok(()) + } + Thread::Group(key) => { + let group = self.group(*key)?; + if let Some(mut g) = group { + g.disappearing_messages_timer = Some(Timer { duration: timer }); + self.save_group(*key, &g)?; + } + Ok(()) + } + } + } + // Contacts /// Clear all saved synchronized contact data