Skip to content

Commit

Permalink
Fix disappearing messages timer
Browse files Browse the repository at this point in the history
Closes whisperfish#213.

Currently only tested in Note-to-Self.
  • Loading branch information
Schmiddiii committed Dec 13, 2023
1 parent 57eed51 commit 47e4978
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 3 additions & 1 deletion presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ async fn save_message<S: Store>(
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,
Expand All @@ -1112,6 +1112,8 @@ async fn save_message<S: Store>(
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:
Expand Down
30 changes: 29 additions & 1 deletion presage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 47e4978

Please sign in to comment.