Skip to content

Commit d912d59

Browse files
committed
chat::chat_tests::test_past_members fixed
1 parent 85e7d45 commit d912d59

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

src/mimefactory.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ impl MimeFactory {
257257
LEFT JOIN contacts c ON cc.contact_id=c.id
258258
LEFT JOIN public_keys k ON k.fingerprint=c.fingerprint
259259
WHERE cc.chat_id=?
260-
AND cc.add_timestamp >= cc.remove_timestamp
261260
AND (cc.contact_id>9 OR (cc.contact_id=1 AND ?))",
262261
(msg.chat_id, chat.typ == Chattype::Group),
263262
|row| {
@@ -300,6 +299,15 @@ impl MimeFactory {
300299
}
301300
}
302301
recipient_ids.insert(id);
302+
303+
if let Some(public_key) = public_key_opt {
304+
keys.push((addr.clone(), public_key))
305+
} else if id != ContactId::SELF {
306+
missing_key_addresses.insert(addr.clone());
307+
if is_encrypted {
308+
warn!(context, "Missing key for {addr}");
309+
}
310+
}
303311
} else if remove_timestamp.saturating_add(60 * 24 * 3600) > now {
304312
// Row is a tombstone,
305313
// member is not actually part of the group.
@@ -324,15 +332,6 @@ impl MimeFactory {
324332
}
325333
}
326334
}
327-
328-
if let Some(public_key) = public_key_opt {
329-
keys.push((addr.clone(), public_key))
330-
} else if id != ContactId::SELF {
331-
missing_key_addresses.insert(addr.clone());
332-
if is_encrypted {
333-
warn!(context, "Missing key for {addr}");
334-
}
335-
}
336335
}
337336

338337
debug_assert!(member_timestamps.len() >= to.len());

src/receive_imf.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,7 @@ pub(crate) async fn receive_imf_inner(
335335
&mime_parser.recipients,
336336
&mime_parser.gossiped_keys,
337337
&[], // TODO use To fingerprints
338-
if !mime_parser.incoming {
339-
Origin::OutgoingTo
340-
} else if incoming_origin.is_known() {
341-
Origin::IncomingTo
342-
} else {
343-
Origin::IncomingUnknownTo
344-
},
338+
Origin::Hidden
345339
)
346340
.await?;
347341

@@ -354,8 +348,14 @@ pub(crate) async fn receive_imf_inner(
354348
lookup_pgp_contacts_by_address_list(context, &mime_parser.past_members, &past_members_fingerprints, chat_id)
355349
.await?;
356350
} else {
357-
// TODO: lookup by fingerprints if they are available.
358-
past_ids = vec![None; mime_parser.past_members.len()];
351+
past_ids = add_or_lookup_pgp_contacts_by_address_list(
352+
context,
353+
&mime_parser.past_members,
354+
&mime_parser.gossiped_keys,
355+
&past_members_fingerprints,
356+
Origin::Hidden
357+
)
358+
.await?;
359359
}
360360
} else {
361361
if pgp_to_ids.len() == 1
@@ -3176,17 +3176,22 @@ async fn add_or_lookup_pgp_contacts_by_address_list(
31763176
origin: Origin,
31773177
) -> Result<Vec<Option<ContactId>>> {
31783178
let mut contact_ids = Vec::new();
3179+
let mut fingerprint_iter = fingerprints.iter();
31793180
for info in address_list {
31803181
let addr = &info.addr;
31813182
if !may_be_valid_addr(addr) {
31823183
contact_ids.push(None);
31833184
continue;
31843185
}
3185-
let Some(key) = gossiped_keys.get(addr) else {
3186+
let fingerprint: String = if let Some(fp) = fingerprint_iter.next() {
3187+
// Iterator has not ran out of fingerprints yet.
3188+
fp.hex()
3189+
} else if let Some(key) = gossiped_keys.get(addr) {
3190+
key.dc_fingerprint().hex()
3191+
} else {
31863192
contact_ids.push(None);
31873193
continue;
31883194
};
3189-
let fingerprint = key.dc_fingerprint().hex();
31903195
let display_name = info.display_name.as_deref();
31913196
if let Ok(addr) = ContactAddress::new(addr) {
31923197
let (contact_id, _) = Contact::add_or_lookup_ex(
@@ -3279,6 +3284,8 @@ async fn lookup_pgp_contacts_by_address_list(
32793284
fingerprints: &[Fingerprint],
32803285
chat_id: ChatId,
32813286
) -> Result<Vec<Option<ContactId>>> {
3287+
// TODO: create a contact with a given fingerprint
3288+
// if fingerprint is available.
32823289
let mut contact_ids = Vec::new();
32833290
for info in address_list {
32843291
let addr = &info.addr;

0 commit comments

Comments
 (0)