Skip to content

Commit e2616c7

Browse files
committed
pass timestamp to add_to_chat_contacts_table
1 parent f862aec commit e2616c7

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

src/chat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3481,7 +3481,7 @@ pub async fn create_group_chat(
34813481

34823482
let chat_id = ChatId::new(u32::try_from(row_id)?);
34833483
if !is_contact_in_chat(context, chat_id, ContactId::SELF).await? {
3484-
add_to_chat_contacts_table(context, chat_id, &[ContactId::SELF]).await?;
3484+
add_to_chat_contacts_table(context, time(), chat_id, &[ContactId::SELF]).await?;
34853485
}
34863486

34873487
context.emit_msgs_changed_without_ids();
@@ -3626,10 +3626,10 @@ pub(crate) async fn update_chat_contacts_table(
36263626
/// Adds contacts to the `chats_contacts` table.
36273627
pub(crate) async fn add_to_chat_contacts_table(
36283628
context: &Context,
3629+
timestamp: i64,
36293630
chat_id: ChatId,
36303631
contact_ids: &[ContactId],
36313632
) -> Result<()> {
3632-
let now = time();
36333633
context
36343634
.sql
36353635
.transaction(move |transaction| {
@@ -3638,7 +3638,7 @@ pub(crate) async fn add_to_chat_contacts_table(
36383638
"INSERT INTO chats_contacts (chat_id, contact_id, add_timestamp) VALUES(?1, ?2, ?3)
36393639
ON CONFLICT (chat_id, contact_id)
36403640
DO UPDATE SET add_timestamp=MAX(remove_timestamp, ?3)",
3641-
(chat_id, contact_id, now),
3641+
(chat_id, contact_id, timestamp),
36423642
)?;
36433643
}
36443644
Ok(())
@@ -3752,7 +3752,7 @@ pub(crate) async fn add_contact_to_chat_ex(
37523752
if is_contact_in_chat(context, chat_id, contact_id).await? {
37533753
return Ok(false);
37543754
}
3755-
add_to_chat_contacts_table(context, chat_id, &[contact_id]).await?;
3755+
add_to_chat_contacts_table(context, time(), chat_id, &[contact_id]).await?;
37563756
}
37573757
if chat.typ == Chattype::Group && chat.is_promoted() {
37583758
msg.viewtype = Viewtype::Text;

src/receive_imf.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -2118,7 +2118,13 @@ async fn create_group(
21182118
}
21192119
members.extend(to_ids);
21202120

2121-
chat::add_to_chat_contacts_table(context, new_chat_id, &members).await?;
2121+
chat::add_to_chat_contacts_table(
2122+
context,
2123+
mime_parser.timestamp_sent,
2124+
new_chat_id,
2125+
&members,
2126+
)
2127+
.await?;
21222128
}
21232129

21242130
context.emit_event(EventType::ChatModified(new_chat_id));
@@ -2527,7 +2533,13 @@ async fn create_or_lookup_mailinglist(
25272533
)
25282534
})?;
25292535

2530-
chat::add_to_chat_contacts_table(context, chat_id, &[ContactId::SELF]).await?;
2536+
chat::add_to_chat_contacts_table(
2537+
context,
2538+
mime_parser.timestamp_sent,
2539+
chat_id,
2540+
&[ContactId::SELF],
2541+
)
2542+
.await?;
25312543
Ok(Some((chat_id, blocked)))
25322544
} else {
25332545
info!(context, "Creating list forbidden by caller.");
@@ -2723,7 +2735,13 @@ async fn create_adhoc_group(
27232735
context,
27242736
"Created ad-hoc group id={new_chat_id}, name={grpname:?}."
27252737
);
2726-
chat::add_to_chat_contacts_table(context, new_chat_id, &member_ids).await?;
2738+
chat::add_to_chat_contacts_table(
2739+
context,
2740+
mime_parser.timestamp_sent,
2741+
new_chat_id,
2742+
&member_ids,
2743+
)
2744+
.await?;
27272745

27282746
context.emit_event(EventType::ChatModified(new_chat_id));
27292747
chatlist_events::emit_chatlist_changed(context);

src/receive_imf/tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3334,6 +3334,7 @@ async fn test_outgoing_private_reply_multidevice() -> Result<()> {
33343334
let group_id = chat::create_group_chat(&bob, ProtectionStatus::Unprotected, "Group").await?;
33353335
chat::add_to_chat_contacts_table(
33363336
&bob,
3337+
time(),
33373338
group_id,
33383339
&[
33393340
bob.add_or_lookup_contact(&alice1).await.id,
@@ -3547,6 +3548,7 @@ async fn test_no_private_reply_to_blocked_account() -> Result<()> {
35473548
let group_id = chat::create_group_chat(&bob, ProtectionStatus::Unprotected, "Group").await?;
35483549
chat::add_to_chat_contacts_table(
35493550
&bob,
3551+
time(),
35503552
group_id,
35513553
&[bob.add_or_lookup_contact(&alice).await.id],
35523554
)
@@ -4229,6 +4231,7 @@ async fn test_delayed_removal_is_ignored() -> Result<()> {
42294231
// create chat with three members
42304232
add_to_chat_contacts_table(
42314233
&alice,
4234+
time(),
42324235
chat_id,
42334236
&[
42344237
Contact::create(&alice, "bob", "[email protected]").await?,

src/securejoin/bob.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ pub(super) async fn start_protocol(context: &Context, invite: QrInvite) -> Resul
5959
// only become usable once the protocol is finished.
6060
let group_chat_id = state.joining_chat_id(context).await?;
6161
if !is_contact_in_chat(context, group_chat_id, invite.contact_id()).await? {
62-
chat::add_to_chat_contacts_table(context, group_chat_id, &[invite.contact_id()])
63-
.await?;
62+
chat::add_to_chat_contacts_table(
63+
context,
64+
time(),
65+
group_chat_id,
66+
&[invite.contact_id()],
67+
)
68+
.await?;
6469
}
6570
let msg = stock_str::secure_join_started(context, invite.contact_id()).await;
6671
chat::add_info_msg(context, group_chat_id, &msg, time()).await?;

src/test_utils.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use crate::pgp::KeyPair;
4141
use crate::receive_imf::receive_imf;
4242
use crate::securejoin::{get_securejoin_qr, join_securejoin};
4343
use crate::stock_str::StockStrings;
44+
use crate::tools::time;
4445

4546
#[allow(non_upper_case_globals)]
4647
pub const AVATAR_900x900_BYTES: &[u8] = include_bytes!("../test-data/image/avatar900x900.png");
@@ -880,7 +881,7 @@ impl TestContext {
880881
let contact = self.add_or_lookup_contact(member).await;
881882
to_add.push(contact.id);
882883
}
883-
add_to_chat_contacts_table(self, chat_id, &to_add)
884+
add_to_chat_contacts_table(self, time(), chat_id, &to_add)
884885
.await
885886
.unwrap();
886887

0 commit comments

Comments
 (0)