Skip to content

Commit 24483e6

Browse files
committed
test_leave_group fixed
1 parent ef86ecf commit 24483e6

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

Diff for: src/receive_imf.rs

+46-23
Original file line numberDiff line numberDiff line change
@@ -353,18 +353,38 @@ pub(crate) async fn receive_imf_inner(
353353
},
354354
)
355355
.await?;
356-
let past_ids = add_or_lookup_contacts_by_address_list(
357-
context,
358-
&mime_parser.past_members,
359-
if !mime_parser.incoming {
360-
Origin::OutgoingTo
361-
} else if incoming_origin.is_known() {
362-
Origin::IncomingTo
356+
357+
let chat_id: Option<ChatId> = if let Some(grpid) = mime_parser.get_chat_group_id() {
358+
if let Some((chat_id, _protected, _blocked)) =
359+
chat::get_chat_id_by_grpid(context, &grpid).await?
360+
{
361+
Some(chat_id)
363362
} else {
364-
Origin::IncomingUnknownTo
365-
},
366-
)
367-
.await?;
363+
None
364+
}
365+
} else {
366+
None
367+
};
368+
369+
let past_ids: Vec<Option<ContactId>> = if let Some(chat_id) = chat_id {
370+
lookup_pgp_contacts_by_address_list(context, &mime_parser.past_members, chat_id).await?
371+
} else {
372+
add_or_lookup_contacts_by_address_list(
373+
context,
374+
&mime_parser.past_members,
375+
if !mime_parser.incoming {
376+
Origin::OutgoingTo
377+
} else if incoming_origin.is_known() {
378+
Origin::IncomingTo
379+
} else {
380+
Origin::IncomingUnknownTo
381+
},
382+
)
383+
.await?
384+
.into_iter()
385+
.map(|contact_id| Some(contact_id))
386+
.collect()
387+
};
368388

369389
update_verified_keys(context, &mut mime_parser, from_id).await?;
370390

@@ -716,7 +736,7 @@ async fn add_parts(
716736
mime_parser: &mut MimeMessage,
717737
imf_raw: &[u8],
718738
to_ids: &[ContactId],
719-
past_ids: &[ContactId],
739+
past_ids: &[Option<ContactId>],
720740
rfc724_mid: &str,
721741
from_id: ContactId,
722742
seen: bool,
@@ -2136,7 +2156,7 @@ async fn create_group(
21362156
create_blocked: Blocked,
21372157
from_id: ContactId,
21382158
to_ids: &[ContactId],
2139-
past_ids: &[ContactId],
2159+
past_ids: &[Option<ContactId>],
21402160
verified_encryption: &VerifiedEncryption,
21412161
grpid: &str,
21422162
) -> Result<Option<(ChatId, Blocked)>> {
@@ -2271,7 +2291,7 @@ async fn update_chats_contacts_timestamps(
22712291
chat_id: ChatId,
22722292
ignored_id: Option<ContactId>,
22732293
to_ids: &[ContactId],
2274-
past_ids: &[ContactId],
2294+
past_ids: &[Option<ContactId>],
22752295
chat_group_member_timestamps: &[i64],
22762296
) -> Result<bool> {
22772297
let expected_timestamps_count = to_ids.len() + past_ids.len();
@@ -2364,7 +2384,7 @@ async fn apply_group_changes(
23642384
chat_id: ChatId,
23652385
from_id: ContactId,
23662386
to_ids: &[ContactId],
2367-
past_ids: &[ContactId],
2387+
past_ids: &[Option<ContactId>],
23682388
verified_encryption: &VerifiedEncryption,
23692389
) -> Result<GroupChangesInfo> {
23702390
if chat_id.is_special() {
@@ -3287,18 +3307,21 @@ async fn lookup_pgp_contacts_by_address_list(
32873307
for info in address_list {
32883308
let addr = &info.addr;
32893309

3290-
let contact_id = context.sql.query_row_optional(
3291-
"SELECT id FROM contacts
3310+
let contact_id = context
3311+
.sql
3312+
.query_row_optional(
3313+
"SELECT id FROM contacts
32923314
WHERE contacts.addr=?
32933315
AND EXISTS (SELECT 1 FROM chats_contacts
32943316
WHERE contact_id=contacts.id
32953317
AND chat_id=?)",
3296-
(addr, chat_id),
3297-
|row| {
3298-
let contact_id: ContactId = row.get(0)?;
3299-
Ok(contact_id)
3300-
},
3301-
).await?;
3318+
(addr, chat_id),
3319+
|row| {
3320+
let contact_id: ContactId = row.get(0)?;
3321+
Ok(contact_id)
3322+
},
3323+
)
3324+
.await?;
33023325
contact_ids.push(contact_id);
33033326
}
33043327
debug_assert_eq!(address_list.len(), contact_ids.len());

0 commit comments

Comments
 (0)