mirror of
https://github.com/chatmail/core.git
synced 2026-05-17 05:46:30 +03:00
refactor: replace HashSet with BTreeSet
This is needed to avoid golden tests being flaky because of info message order being different between runs.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//! # Chat module.
|
//! # Chat module.
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
use std::collections::{BTreeSet, HashMap};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
use std::marker::Sync;
|
use std::marker::Sync;
|
||||||
@@ -3774,7 +3774,7 @@ pub(crate) async fn update_chat_contacts_table(
|
|||||||
context: &Context,
|
context: &Context,
|
||||||
timestamp: i64,
|
timestamp: i64,
|
||||||
id: ChatId,
|
id: ChatId,
|
||||||
contacts: &HashSet<ContactId>,
|
contacts: &BTreeSet<ContactId>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
@@ -5033,7 +5033,7 @@ async fn set_contacts_by_addrs(context: &Context, id: ChatId, addrs: &[String])
|
|||||||
chat.typ == Chattype::OutBroadcast,
|
chat.typ == Chattype::OutBroadcast,
|
||||||
"{id} is not a broadcast list",
|
"{id} is not a broadcast list",
|
||||||
);
|
);
|
||||||
let mut contacts = HashSet::new();
|
let mut contacts = BTreeSet::new();
|
||||||
for addr in addrs {
|
for addr in addrs {
|
||||||
let contact_addr = ContactAddress::new(addr)?;
|
let contact_addr = ContactAddress::new(addr)?;
|
||||||
let contact = Contact::add_or_lookup(context, "", &contact_addr, Origin::Hidden)
|
let contact = Contact::add_or_lookup(context, "", &contact_addr, Origin::Hidden)
|
||||||
@@ -5041,7 +5041,7 @@ async fn set_contacts_by_addrs(context: &Context, id: ChatId, addrs: &[String])
|
|||||||
.0;
|
.0;
|
||||||
contacts.insert(contact);
|
contacts.insert(contact);
|
||||||
}
|
}
|
||||||
let contacts_old = HashSet::<ContactId>::from_iter(get_chat_contacts(context, id).await?);
|
let contacts_old = BTreeSet::<ContactId>::from_iter(get_chat_contacts(context, id).await?);
|
||||||
if contacts == contacts_old {
|
if contacts == contacts_old {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
//! # Messages and their identifiers.
|
//! # Messages and their identifiers.
|
||||||
|
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
@@ -1693,7 +1692,7 @@ pub(crate) async fn delete_msg_locally(context: &Context, msg: &Message) -> Resu
|
|||||||
pub(crate) async fn delete_msgs_locally_done(
|
pub(crate) async fn delete_msgs_locally_done(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
msg_ids: &[MsgId],
|
msg_ids: &[MsgId],
|
||||||
modified_chat_ids: HashSet<ChatId>,
|
modified_chat_ids: BTreeSet<ChatId>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for modified_chat_id in modified_chat_ids {
|
for modified_chat_id in modified_chat_ids {
|
||||||
context.emit_msgs_changed_without_msg_id(modified_chat_id);
|
context.emit_msgs_changed_without_msg_id(modified_chat_id);
|
||||||
@@ -1723,7 +1722,7 @@ pub async fn delete_msgs_ex(
|
|||||||
msg_ids: &[MsgId],
|
msg_ids: &[MsgId],
|
||||||
delete_for_all: bool,
|
delete_for_all: bool,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut modified_chat_ids = HashSet::new();
|
let mut modified_chat_ids = BTreeSet::new();
|
||||||
let mut deleted_rfc724_mid = Vec::new();
|
let mut deleted_rfc724_mid = Vec::new();
|
||||||
let mut res = Ok(());
|
let mut res = Ok(());
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! Internet Message Format reception pipeline.
|
//! Internet Message Format reception pipeline.
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::collections::{BTreeMap, BTreeSet, HashSet};
|
use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::sync::LazyLock;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
@@ -1927,7 +1927,7 @@ async fn add_parts(
|
|||||||
&& chat_id.get_ephemeral_timer(context).await? != ephemeral_timer
|
&& chat_id.get_ephemeral_timer(context).await? != ephemeral_timer
|
||||||
{
|
{
|
||||||
let chat_contacts =
|
let chat_contacts =
|
||||||
HashSet::<ContactId>::from_iter(chat::get_chat_contacts(context, chat_id).await?);
|
BTreeSet::<ContactId>::from_iter(chat::get_chat_contacts(context, chat_id).await?);
|
||||||
let is_from_in_chat =
|
let is_from_in_chat =
|
||||||
!chat_contacts.contains(&ContactId::SELF) || chat_contacts.contains(&from_id);
|
!chat_contacts.contains(&ContactId::SELF) || chat_contacts.contains(&from_id);
|
||||||
|
|
||||||
@@ -2462,7 +2462,7 @@ async fn handle_edit_delete(
|
|||||||
// See `message::delete_msgs_ex()`, unlike edit requests, DC doesn't send unencrypted
|
// See `message::delete_msgs_ex()`, unlike edit requests, DC doesn't send unencrypted
|
||||||
// deletion requests, so there's no need to support them.
|
// deletion requests, so there's no need to support them.
|
||||||
if part.param.get_bool(Param::GuaranteeE2ee).unwrap_or(false) {
|
if part.param.get_bool(Param::GuaranteeE2ee).unwrap_or(false) {
|
||||||
let mut modified_chat_ids = HashSet::new();
|
let mut modified_chat_ids = BTreeSet::new();
|
||||||
let mut msg_ids = Vec::new();
|
let mut msg_ids = Vec::new();
|
||||||
|
|
||||||
let rfc724_mid_vec: Vec<&str> = rfc724_mid_list.split_whitespace().collect();
|
let rfc724_mid_vec: Vec<&str> = rfc724_mid_list.split_whitespace().collect();
|
||||||
@@ -3094,7 +3094,7 @@ async fn apply_group_changes(
|
|||||||
let mut better_msg = None;
|
let mut better_msg = None;
|
||||||
let mut silent = false;
|
let mut silent = false;
|
||||||
let chat_contacts =
|
let chat_contacts =
|
||||||
HashSet::<ContactId>::from_iter(chat::get_chat_contacts(context, chat.id).await?);
|
BTreeSet::<ContactId>::from_iter(chat::get_chat_contacts(context, chat.id).await?);
|
||||||
let is_from_in_chat =
|
let is_from_in_chat =
|
||||||
!chat_contacts.contains(&ContactId::SELF) || chat_contacts.contains(&from_id);
|
!chat_contacts.contains(&ContactId::SELF) || chat_contacts.contains(&from_id);
|
||||||
|
|
||||||
@@ -3172,8 +3172,8 @@ async fn apply_group_changes(
|
|||||||
&& chat.member_list_is_stale(context).await?
|
&& chat.member_list_is_stale(context).await?
|
||||||
{
|
{
|
||||||
info!(context, "Member list is stale.");
|
info!(context, "Member list is stale.");
|
||||||
let mut new_members: HashSet<ContactId> =
|
let mut new_members: BTreeSet<ContactId> =
|
||||||
HashSet::from_iter(to_ids_flat.iter().copied());
|
BTreeSet::from_iter(to_ids_flat.iter().copied());
|
||||||
new_members.insert(ContactId::SELF);
|
new_members.insert(ContactId::SELF);
|
||||||
if !from_id.is_special() {
|
if !from_id.is_special() {
|
||||||
new_members.insert(from_id);
|
new_members.insert(from_id);
|
||||||
@@ -3217,7 +3217,7 @@ async fn apply_group_changes(
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
} else {
|
} else {
|
||||||
let mut new_members: HashSet<ContactId>;
|
let mut new_members: BTreeSet<ContactId>;
|
||||||
// True if a Delta Chat client has explicitly and really added our primary address to an
|
// True if a Delta Chat client has explicitly and really added our primary address to an
|
||||||
// already existing group.
|
// already existing group.
|
||||||
let self_added =
|
let self_added =
|
||||||
@@ -3228,7 +3228,7 @@ async fn apply_group_changes(
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
if self_added {
|
if self_added {
|
||||||
new_members = HashSet::from_iter(to_ids_flat.iter().copied());
|
new_members = BTreeSet::from_iter(to_ids_flat.iter().copied());
|
||||||
new_members.insert(ContactId::SELF);
|
new_members.insert(ContactId::SELF);
|
||||||
if !from_id.is_special() && from_is_key_contact != chat.grpid.is_empty() {
|
if !from_id.is_special() && from_is_key_contact != chat.grpid.is_empty() {
|
||||||
new_members.insert(from_id);
|
new_members.insert(from_id);
|
||||||
@@ -3279,7 +3279,7 @@ async fn apply_group_changes(
|
|||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_chat_contacts = HashSet::<ContactId>::from_iter(
|
let new_chat_contacts = BTreeSet::<ContactId>::from_iter(
|
||||||
chat::get_chat_contacts(context, chat.id)
|
chat::get_chat_contacts(context, chat.id)
|
||||||
.await?
|
.await?
|
||||||
.iter()
|
.iter()
|
||||||
@@ -3287,11 +3287,11 @@ async fn apply_group_changes(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// These are for adding info messages about implicit membership changes.
|
// These are for adding info messages about implicit membership changes.
|
||||||
let mut added_ids: HashSet<ContactId> = new_chat_contacts
|
let mut added_ids: BTreeSet<ContactId> = new_chat_contacts
|
||||||
.difference(&chat_contacts)
|
.difference(&chat_contacts)
|
||||||
.copied()
|
.copied()
|
||||||
.collect();
|
.collect();
|
||||||
let mut removed_ids: HashSet<ContactId> = chat_contacts
|
let mut removed_ids: BTreeSet<ContactId> = chat_contacts
|
||||||
.difference(&new_chat_contacts)
|
.difference(&new_chat_contacts)
|
||||||
.copied()
|
.copied()
|
||||||
.collect();
|
.collect();
|
||||||
@@ -3513,8 +3513,8 @@ async fn apply_chat_name_avatar_and_description_changes(
|
|||||||
#[expect(clippy::arithmetic_side_effects)]
|
#[expect(clippy::arithmetic_side_effects)]
|
||||||
async fn group_changes_msgs(
|
async fn group_changes_msgs(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
added_ids: &HashSet<ContactId>,
|
added_ids: &BTreeSet<ContactId>,
|
||||||
removed_ids: &HashSet<ContactId>,
|
removed_ids: &BTreeSet<ContactId>,
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
) -> Result<Vec<(String, SystemMessage, Option<ContactId>)>> {
|
) -> Result<Vec<(String, SystemMessage, Option<ContactId>)>> {
|
||||||
let mut group_changes_msgs: Vec<(String, SystemMessage, Option<ContactId>)> = Vec::new();
|
let mut group_changes_msgs: Vec<(String, SystemMessage, Option<ContactId>)> = Vec::new();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use crate::token::Namespace;
|
|||||||
use crate::tools::time;
|
use crate::tools::time;
|
||||||
use crate::transport::{ConfiguredLoginParamJson, sync_transports};
|
use crate::transport::{ConfiguredLoginParamJson, sync_transports};
|
||||||
use crate::{message, stock_str, token};
|
use crate::{message, stock_str, token};
|
||||||
use std::collections::HashSet;
|
use std::collections::BTreeSet;
|
||||||
|
|
||||||
/// Whether to send device sync messages. Aimed for usage in the internal API.
|
/// Whether to send device sync messages. Aimed for usage in the internal API.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@@ -383,7 +383,7 @@ impl Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn sync_message_deletion(&self, msgs: &Vec<String>) -> Result<()> {
|
async fn sync_message_deletion(&self, msgs: &Vec<String>) -> Result<()> {
|
||||||
let mut modified_chat_ids = HashSet::new();
|
let mut modified_chat_ids = BTreeSet::new();
|
||||||
let mut msg_ids = Vec::new();
|
let mut msg_ids = Vec::new();
|
||||||
for rfc724_mid in msgs {
|
for rfc724_mid in msgs {
|
||||||
if let Some(msg_id) = message::rfc724_mid_exists(self, rfc724_mid).await? {
|
if let Some(msg_id) = message::rfc724_mid_exists(self, rfc724_mid).await? {
|
||||||
|
|||||||
Reference in New Issue
Block a user