Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/chat-store/src/store/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub(super) fn apply_event(
// No bytes, no representation.
proto_codec: crate::storage_proto::CODEC_RAW,
status: wa::web_message_info::Status::DELIVERY_ACK as i32,
history_status: None,
starred: false,
overwrite: false,
},
Expand Down
1 change: 1 addition & 0 deletions crates/chat-store/src/store/history_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ pub(super) fn apply_history_message(
.status
.map(|s| s as i32)
.unwrap_or(wa::web_message_info::Status::PENDING as i32),
history_status: wmi.status.map(|status| status as i32),
starred: wmi.starred.unwrap_or(false),
// History is the stale copy: live rows win.
overwrite: false,
Expand Down
1 change: 1 addition & 0 deletions crates/chat-store/src/store/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ pub(super) fn apply_inbound(
} else {
wa::web_message_info::Status::DELIVERY_ACK as i32
},
history_status: None,
starred: false,
overwrite: true,
},
Expand Down
26 changes: 26 additions & 0 deletions crates/chat-store/src/store/message_rows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub(super) struct NewMessage<'a> {
/// [`crate::storage_proto`] representation of `proto` (raw vs zlib).
pub(super) proto_codec: i32,
pub(super) status: i32,
/// Explicit WebMessageInfo status, never a placeholder insertion default.
pub(super) history_status: Option<i32>,
pub(super) starred: bool,
/// Live redeliveries refresh content in place (PDO recovery replaces an
/// `undecryptable` placeholder); history-sync copies never clobber live rows.
Expand Down Expand Up @@ -61,6 +63,30 @@ pub(super) fn insert_message(
&sender,
changes,
)? {
// History content may be stale while its delivery evidence is newer.
// Resolve sender/account identity first and keep terminal failures intact.
if new.from_me
&& let Some(status) = new.history_status
&& (waproto::whatsapp::web_message_info::Status::SERVER_ACK as i32
..=waproto::whatsapp::web_message_info::Status::PLAYED as i32)
.contains(&status)
{
let advanced = diesel::update(
dsl::messages
.filter(dsl::id.eq(existing.id))
.filter(dsl::from_me.eq(true))
.filter(dsl::revoked.eq(false))
.filter(
dsl::status.ne(waproto::whatsapp::web_message_info::Status::ERROR as i32),
)
.filter(dsl::status.lt(status)),
)
.set(dsl::status.eq(status))
.execute(conn)?;
if advanced > 0 {
changes.message_chats.insert(new.chat_jid.to_owned());
}
}
// A revoke that arrived first had no original position. Recover only
// its kind/time, never the content, after sender-scoped resolution.
let old_ts: i64 = dsl::messages
Expand Down
1 change: 1 addition & 0 deletions crates/chat-store/src/store/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ fn apply_writer_msg(
proto: Some(&proto_bytes),
proto_codec,
status: wa::web_message_info::Status::PENDING as i32,
history_status: None,
starred: false,
overwrite: true,
},
Expand Down
Loading
Loading