Skip to content
Draft
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
333 changes: 147 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/chat-store/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ impl ChatStore {
let device_id = self.device_id();
let is_group = jid.is_group();
let jid = jid.to_string();
let now_ms = wacore::time::now_utc().timestamp_millis();
let now_ms = wacore::time::now_millis();
let rows: Vec<(Option<i64>, bool, Option<String>)> = self
.db()
.read(move |conn| {
Expand Down Expand Up @@ -2366,7 +2366,7 @@ impl ChatStore {
) -> Result<()> {
use schema::media_refs::dsl;
let device_id = self.device_id();
let now_ms = wacore::time::now_utc().timestamp_millis();
let now_ms = wacore::time::now_millis();
self.db()
.run(move |conn| {
diesel::insert_into(dsl::media_refs)
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/src/store/ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ pub(super) fn apply_server_ack(
let server_timestamp_ms = ack
.timestamp
.filter(|_| ack.error.is_none())
.map(|timestamp| timestamp.timestamp_millis());
.map(wacore::Timestamp::as_millis);
let timestamp_updated = if let Some(timestamp_ms) = server_timestamp_ms {
diesel::update(
message_row(device_id, &chat, &ack.id)
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/src/store/avatar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub(super) fn upsert(
) -> QueryResult<()> {
use schema::avatar_descriptors::dsl;
let jid = jid.to_string();
let now_ms = wacore::time::now_utc().timestamp_millis();
let now_ms = wacore::time::now_millis();
let seq = i64::try_from(seq).unwrap_or(i64::MAX);
if !picture_id.is_empty() && seq <= order_floor(conn, device_id)? {
let present = dsl::avatar_descriptors
Expand Down
10 changes: 5 additions & 5 deletions crates/chat-store/src/store/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(super) fn apply_event(
if let AckApplied::Deferrable(chat) =
apply_server_ack_with_operations(conn, device_id, ack, cs, deferred)?
{
deferred.defer(ack, chat, wacore::time::now_utc().timestamp_millis());
deferred.defer(ack, chat, wacore::time::now_millis());
}
Ok(())
}
Expand All @@ -64,7 +64,7 @@ pub(super) fn apply_event(
msg_id: &undec.info.id,
sender_jid: &sender,
from_me: undec.info.source.is_from_me,
timestamp_ms: undec.info.timestamp.timestamp_millis(),
timestamp_ms: undec.info.timestamp.as_millis(),
kind,
text: None,
proto: None,
Expand All @@ -86,7 +86,7 @@ pub(super) fn apply_event(
&chat,
ChatBump {
msg_id: &undec.info.id,
ts_ms: undec.info.timestamp.timestamp_millis(),
ts_ms: undec.info.timestamp.as_millis(),
preview: None,
kind: Some(kind),
unread_delta: i32::from(!undec.info.source.is_from_me),
Expand Down Expand Up @@ -172,7 +172,7 @@ pub(super) fn apply_event(
.action
.pinned
.unwrap_or(false)
.then(|| update.timestamp.timestamp_millis());
.then(|| update.timestamp.as_millis());
let chat = crate::lid::route_chat_key(conn, device_id, &update.jid.to_string(), cs)?;
crate::store::chat_rows::ensure_preference_chat(conn, device_id, &chat)?;
// Only when it is news, the same rule the subject change already
Expand Down Expand Up @@ -293,7 +293,7 @@ pub(super) fn apply_event(
// stale replay resurrects a badge this read cleared.
let watermark = newest
.flatten()
.unwrap_or_else(|| update.timestamp.timestamp_millis());
.unwrap_or_else(|| update.timestamp.as_millis());
advance_read_state(conn, device_id, &chat, watermark, &[])?
}
};
Expand Down
4 changes: 2 additions & 2 deletions crates/chat-store/src/store/group_membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(super) fn apply(
msg_id: &id,
sender_jid: &chat,
from_me: false,
timestamp_ms: update.timestamp.timestamp_millis(),
timestamp_ms: update.timestamp.as_millis(),
kind: "group_membership",
text: None,
proto: None,
Expand Down Expand Up @@ -68,7 +68,7 @@ pub(super) fn apply(
&chat,
ChatBump {
msg_id: &id,
ts_ms: update.timestamp.timestamp_millis(),
ts_ms: update.timestamp.as_millis(),
preview: Some(&preview),
kind: Some("group_membership"),
unread_delta: 0,
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/src/store/history_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn apply_history_conversation(
// cover is durable for every row, so an oversized snapshot seeds
// nothing at all and leaves the stored count (and later merges,
// which keep a stored zero over an unset marker) alone.
let now_ms = wacore::time::now_utc().timestamp_millis();
let now_ms = wacore::time::now_millis();
let frontier_ms = last_ts_ms.max(synced_max_ms).min(now_ms);
// Appending past the retained-id cap would evict older explicitly
// covered ids — possibly for rows not yet materialized — so only
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/src/store/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) fn apply_inbound(
let info = &inbound.info;
let chat = route_chat(conn, device_id, info.source.chat.to_string(), cs)?;
let sender = info.source.sender.to_string();
let ts_ms = info.timestamp.timestamp_millis();
let ts_ms = info.timestamp.as_millis();

// Live push names ride on every message; keep contacts warm from them.
if !info.push_name.is_empty() && !info.source.is_from_me {
Expand Down
4 changes: 2 additions & 2 deletions crates/chat-store/src/store/message_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ pub(crate) fn reconcile_startup(
/// the history-sync seed) makes that zero durable across later repairs.
/// Runs exactly on the dirty startups that precede a full repair.
fn backfill_legacy_read_state(conn: &mut SqliteConnection, device_id: i32) -> QueryResult<()> {
let now_ms = wacore::time::now_utc().timestamp_millis();
let now_ms = wacore::time::now_millis();
// Chats the scalar sweep cannot fully cover: rows timestamped ahead of
// the capped frontier need explicit ids or the repair below recounts
// them. Selected up front, while the sweep predicate still identifies
Expand Down Expand Up @@ -804,7 +804,7 @@ fn refresh_chat_after_merge(
.select(diesel::dsl::max(schema::messages::timestamp_ms))
.first(conn)?;
if let Some(max_ts) = max_ts.filter(|&ts| ts > 0) {
let baseline = max_ts.min(wacore::time::now_utc().timestamp_millis());
let baseline = max_ts.min(wacore::time::now_millis());
// Past more coverable ids than the retained list holds, a
// committed scalar without its ids would leave the next
// merge recounting the uncovered rows — so an overflowing
Expand Down
6 changes: 5 additions & 1 deletion crates/chat-store/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,11 @@ impl ChatStore {
.maybe_participant_jid(participant)
.message_id(target_id.to_owned())
.from_me(from_me)
.timestamp(timestamp)
.timestamp(
wacore::Timestamp::from_millis(timestamp.timestamp_millis()).ok_or_else(|| {
StoreError::Validation("delete timestamp is outside the SDK range".into())
})?,
)
.action(Box::new({
let mut constructed: wa::sync_action_value::DeleteMessageForMeAction =
Default::default();
Expand Down
6 changes: 3 additions & 3 deletions crates/chat-store/src/store/offline_receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(super) fn retain(
timestamp: i64,
) -> QueryResult<()> {
use diesel::query_dsl::methods::FilterDsl;
let now = wacore::time::now_utc().timestamp_millis();
let now = wacore::time::now_millis();
diesel::insert_into(pending::table)
.values((
pending::device_id.eq(device),
Expand All @@ -56,7 +56,7 @@ pub(super) fn retain(

/// Enforce retention once per batch, after matching available outgoing rows.
pub(super) fn prune(conn: &mut SqliteConnection, device: i32) -> QueryResult<()> {
let now = wacore::time::now_utc().timestamp_millis();
let now = wacore::time::now_millis();
diesel::sql_query(
"DELETE FROM offline_receipts WHERE device_id = ? AND \
(received_at_ms < ? OR rowid IN (SELECT rowid FROM offline_receipts \
Expand Down Expand Up @@ -91,7 +91,7 @@ pub(super) fn apply(
pending::received_at_ms,
))
.load::<(String, String, String, i32, i64, i64)>(conn)?;
let cutoff = wacore::time::now_utc().timestamp_millis() - RETENTION_MS;
let cutoff = wacore::time::now_millis() - RETENTION_MS;
for (wire_chat, id, user, status, timestamp, received) in rows {
let owner = messages::table
.filter(messages::device_id.eq(device))
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/src/store/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(super) fn apply_receipt(
// pipeline and the receipt echo need the full JID, so a companion device
// acking a DM arrives as `user:48@lid`. Rows are keyed bare.
let chat = receipt.source.chat.to_non_ad_string();
let ts_ms = receipt.timestamp.timestamp_millis();
let ts_ms = receipt.timestamp.as_millis();
let message_ids: Vec<String> = receipt
.message_ids
.iter()
Expand Down
4 changes: 2 additions & 2 deletions crates/chat-store/src/store/shared_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ pub(super) fn apply(
if let Some(context) = base.context_info()
&& context.expiration.is_some_and(|duration| {
duration > 0
&& ts.saturating_add(i64::from(duration)) <= wacore::time::now_utc().timestamp()
&& ts.saturating_add(i64::from(duration)) <= wacore::time::now_utc().as_secs()
})
{
continue;
Expand Down Expand Up @@ -339,7 +339,7 @@ pub(super) fn attempted(
bundle: &PendingHistoryBundle,
) -> QueryResult<()> {
diesel::sql_query("UPDATE shared_group_history SET attempted_ms = ? WHERE device_id = ? AND chat_jid = ? AND msg_id = ? AND sender_jid = ?")
.bind::<BigInt,_>(wacore::time::now_utc().timestamp_millis())
.bind::<BigInt,_>(wacore::time::now_millis())
.bind::<Integer,_>(device).bind::<Text,_>(&bundle.chat_jid).bind::<Text,_>(&bundle.msg_id).bind::<Text,_>(&bundle.sender_jid).execute(conn)?;
Ok(())
}
Expand Down
10 changes: 4 additions & 6 deletions crates/chat-store/src/store/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ fn apply_writer_msg(
device_id,
&chat.to_string(),
operation_id,
wacore::time::now_utc().timestamp_millis(),
wacore::time::now_millis(),
),
WriterMsg::InboundDurability { event, .. } => {
apply_event(conn, device_id, event, cs, deferred)
Expand Down Expand Up @@ -498,11 +498,9 @@ fn apply_writer_msg(
// The row this send's ack was waiting for now exists. Applying
// it here also corrects the optimistic timestamp we just wrote
// to the server's, before anything renders the row.
while let Some(ack) = deferred.take_matching(
msg_id,
&chat_str,
wacore::time::now_utc().timestamp_millis(),
) {
while let Some(ack) =
deferred.take_matching(msg_id, &chat_str, wacore::time::now_millis())
{
if let AckApplied::Deferrable(_) =
apply_server_ack_with_operations(conn, device_id, &ack, cs, deferred)?
{
Expand Down
14 changes: 9 additions & 5 deletions crates/chat-store/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub fn jid(s: &str) -> Jid {
/// The tests date everything from 1_700_000_000 and step by seconds, so this
/// is the one spelling of `Utc.timestamp_opt(secs, 0).unwrap()` — which was
/// written out at every one of a hundred and thirty-seven sites.
pub fn sdk_timestamp(time: DateTime<Utc>) -> wacore::Timestamp {
wacore::Timestamp::from_millis(time.timestamp_millis()).unwrap()
}

pub fn ts(secs: i64) -> DateTime<Utc> {
DateTime::from_timestamp(secs, 0).expect("a representable test instant")
}
Expand All @@ -93,7 +97,7 @@ pub fn incoming_info(chat: &str, sender: &str, id: &str, ts_secs: i64) -> Messag
..Default::default()
},
id: id.to_string().into(),
timestamp: ts(ts_secs),
timestamp: sdk_timestamp(ts(ts_secs)),
..Default::default()
}
}
Expand Down Expand Up @@ -180,7 +184,7 @@ fn built_receipt(
..Default::default()
})
.message_ids(ids.iter().map(|id| (*id).into()).collect())
.timestamp(at)
.timestamp(sdk_timestamp(at))
.r#type(ty)
.offline(offline)
.build(),
Expand Down Expand Up @@ -236,7 +240,7 @@ fn built_ack(id: &str, chat: Option<Jid>, at: Option<DateTime<Utc>>, code: Optio
.id(id.to_string())
.class("message".to_string())
.maybe_from(chat)
.maybe_timestamp(at)
.maybe_timestamp(at.map(sdk_timestamp))
.maybe_error(code.map(str::to_string))
.build(),
)
Expand Down Expand Up @@ -276,7 +280,7 @@ pub fn delete_for_me(chat: Jid, id: &str, from_me: bool, at: DateTime<Utc>) -> E
.chat_jid(chat)
.message_id(id.to_string())
.from_me(from_me)
.timestamp(at)
.timestamp(sdk_timestamp(at))
.action(Box::new(
wa::sync_action_value::DeleteMessageForMeAction::default(),
))
Expand All @@ -300,7 +304,7 @@ pub fn mark_read_event(chat: &str, read: bool, ts_secs: i64) -> Event {
Event::MarkChatAsReadUpdate(
wacore::types::events::MarkChatAsReadUpdate::builder()
.jid(jid(chat))
.timestamp(ts(ts_secs))
.timestamp(sdk_timestamp(ts(ts_secs)))
.action(Box::new({
let mut constructed: wa::sync_action_value::MarkChatAsReadAction =
Default::default();
Expand Down
4 changes: 2 additions & 2 deletions crates/chat-store/tests/contact_removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn contact_update(jid: &str, full_name: &str, first_name: &str) -> Event {
Event::ContactUpdate(
ContactUpdate::builder()
.jid(jid.parse().expect("test JID"))
.timestamp(ts(1_700_000_100))
.timestamp(sdk_timestamp(ts(1_700_000_100)))
.action(Box::new({
let mut constructed: wa::sync_action_value::ContactAction = Default::default();
constructed.full_name = Some(full_name.to_owned());
Expand All @@ -24,7 +24,7 @@ fn contact_removed(jid: &str) -> Event {
Event::ContactRemoved(
ContactRemoved::builder()
.jid(jid.parse().expect("test JID"))
.timestamp(ts(1_700_000_200))
.timestamp(sdk_timestamp(ts(1_700_000_200)))
.from_full_sync(false)
.build(),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/tests/group_membership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn notice(id: &str, index: u32) -> Event {
.notification_id(id.to_owned())
.action_index(index)
.participant(jid(PEER))
.timestamp(ts(1_700_000_000))
.timestamp(sdk_timestamp(ts(1_700_000_000)))
.is_lid_addressing_mode(true)
.action(Box::new(
GroupNotificationAction::add()
Expand Down
8 changes: 4 additions & 4 deletions crates/chat-store/tests/history_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn history_prefills_live_row_without_overwriting_appstate() {
Event::MuteUpdate(
wacore::types::events::MuteUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_100))
.timestamp(sdk_timestamp(ts(1_700_000_100)))
.action(Box::new({
let mut constructed: wa::sync_action_value::MuteAction = Default::default();
constructed.muted = Some(false);
Expand All @@ -86,7 +86,7 @@ async fn history_prefills_live_row_without_overwriting_appstate() {
Event::ArchiveUpdate(
wacore::types::events::ArchiveUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_100))
.timestamp(sdk_timestamp(ts(1_700_000_100)))
.action(Box::new({
let mut constructed: wa::sync_action_value::ArchiveChatAction =
Default::default();
Expand Down Expand Up @@ -137,15 +137,15 @@ async fn missing_preference_options_do_not_unmute_or_unarchive() {
Event::MuteUpdate(
wacore::types::events::MuteUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_100))
.timestamp(sdk_timestamp(ts(1_700_000_100)))
.action(Box::new(wa::sync_action_value::MuteAction::default()))
.from_full_sync(false)
.build(),
),
Event::ArchiveUpdate(
wacore::types::events::ArchiveUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_100))
.timestamp(sdk_timestamp(ts(1_700_000_100)))
.action(Box::new(wa::sync_action_value::ArchiveChatAction::default()))
.from_full_sync(false)
.build(),
Expand Down
6 changes: 3 additions & 3 deletions crates/chat-store/tests/lid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async fn alias_reconcile_keeps_explicit_unmute_and_unarchive_over_history() {
Event::MuteUpdate(
wacore::types::events::MuteUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_001))
.timestamp(sdk_timestamp(ts(1_700_000_001)))
.action(Box::new({
let mut constructed: wa::sync_action_value::MuteAction = Default::default();
constructed.muted = Some(false);
Expand All @@ -38,7 +38,7 @@ async fn alias_reconcile_keeps_explicit_unmute_and_unarchive_over_history() {
Event::ArchiveUpdate(
wacore::types::events::ArchiveUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_001))
.timestamp(sdk_timestamp(ts(1_700_000_001)))
.action(Box::new({
let mut constructed: wa::sync_action_value::ArchiveChatAction =
Default::default();
Expand Down Expand Up @@ -332,7 +332,7 @@ async fn reconcile_merges_split_pair() {
Event::PinUpdate(
wacore::types::events::PinUpdate::builder()
.jid(jid(PEER))
.timestamp(ts(1_700_000_050))
.timestamp(sdk_timestamp(ts(1_700_000_050)))
.action(Box::new({
let mut constructed: wa::sync_action_value::PinAction = Default::default();
constructed.pinned = Some(true);
Expand Down
2 changes: 1 addition & 1 deletion crates/chat-store/tests/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async fn delete_for_me_targets_only_the_named_group_sender() {
.maybe_participant_jid(Some(jid(PEER)))
.message_id("DELETE-REUSED".into())
.from_me(false)
.timestamp(ts(1_700_000_002))
.timestamp(sdk_timestamp(ts(1_700_000_002)))
.action(Box::new(
wa::sync_action_value::DeleteMessageForMeAction::default(),
))
Expand Down
Loading
Loading