Skip to content

Commit

Permalink
Set timestamp for every DataMessage
Browse files Browse the repository at this point in the history
The previous attempt #290 was missing nested data messages as well as group messages.
  • Loading branch information
hrdl-github committed Nov 13, 2024
1 parent 426b156 commit e6b9f46
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,9 +869,10 @@ impl<S: Store> Manager<S, Registered> {
.profile_key
.get_or_insert(self.state.data.profile_key().get_bytes().to_vec());
message.required_protocol_version = Some(0);
message.timestamp = Some(timestamp);
}

ensure_data_message_timestamp(&mut content_body, timestamp);

sender
.send_message(
&recipient,
Expand Down Expand Up @@ -936,6 +937,7 @@ impl<S: Store> Manager<S, Registered> {
let thread = Thread::Group(master_key_bytes);

self.restore_thread_timer(&thread, &mut content_body).await;
ensure_data_message_timestamp(&mut content_body, timestamp);

let mut sender = self.new_message_sender().await?;

Expand Down Expand Up @@ -1304,6 +1306,32 @@ impl<S: Store> Manager<S, Registered> {
}
}

/// Set the timestamp in any DataMessage so it matches its envelope's
fn ensure_data_message_timestamp(content_body: &mut ContentBody, timestamp: u64) {
match content_body {
ContentBody::DataMessage(message) => {
message.timestamp = Some(timestamp);
}
ContentBody::EditMessage(EditMessage {
data_message: Some(data_message),
..
}) => {
data_message.timestamp = Some(timestamp);
}
ContentBody::SynchronizeMessage(SyncMessage {
sent:
Some(sync_message::Sent {
message: Some(data_message),
..
}),
..
}) => {
data_message.timestamp = Some(timestamp);
}
_ => (),
}
}

/// The mode receiving messages stream
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum ReceivingMode {
Expand Down

0 comments on commit e6b9f46

Please sign in to comment.