Skip to content

Commit

Permalink
backup: Sort group invitees when serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
jrose-signal committed Aug 16, 2024
1 parent 52912c7 commit f1b93b5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rust/message-backup/src/backup/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(crate) mod chat_style;
mod gift_badge;
use gift_badge::*;

mod group;
pub(crate) mod group;
use group::*;

mod link;
Expand Down
14 changes: 8 additions & 6 deletions rust/message-backup/src/backup/chat/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use libsignal_protocol::{Aci, Pni, ServiceId};
use macro_rules_attribute::macro_rules_derive;
use protobuf::{EnumOrUnknown, Message};

use crate::backup::serialize::UnorderedList;
use crate::backup::time::Duration;
use crate::backup::{serialize, uuid_bytes_to_aci};
use crate::proto::backup::{
Expand Down Expand Up @@ -190,7 +191,7 @@ pub enum GroupChatUpdate {
GroupInvitationRevokedUpdate {
#[serde(serialize_with = "serialize::optional_service_id_as_string")]
updaterAci: Option<Aci>,
invitees: Vec<Invitee>,
invitees: UnorderedList<Invitee>,
},
GroupJoinRequestUpdate {
#[serde(serialize_with = "serialize::service_id_as_string")]
Expand Down Expand Up @@ -365,7 +366,7 @@ impl ValidateFrom<EnumOrUnknown<proto::GroupV2AccessLevel>> for AccessLevel {
}
}

impl ValidateFrom<Vec<proto::group_invitation_revoked_update::Invitee>> for Vec<Invitee> {
impl ValidateFrom<Vec<proto::group_invitation_revoked_update::Invitee>> for UnorderedList<Invitee> {
fn validate_from(
invitees: Vec<proto::group_invitation_revoked_update::Invitee>,
) -> Result<Self, GroupUpdateFieldError> {
Expand Down Expand Up @@ -514,7 +515,7 @@ mod test {
]
}

fn validated_invitees() -> Vec<Invitee> {
fn validated_invitees() -> UnorderedList<Invitee> {
vec![
Invitee {
inviter: None,
Expand All @@ -527,6 +528,7 @@ mod test {
invitee_aci: None,
},
]
.into()
}

fn invitee_invalid_aci() -> Vec<group_invitation_revoked_update::Invitee> {
Expand Down Expand Up @@ -556,11 +558,11 @@ mod test {
#[test_case(ACI.service_id_binary(), Ok(ServiceId::Aci(ACI)))]
#[test_case(vec![], Err::<ServiceId, _>(InvalidServiceId))]
#[test_case(valid_invitees(), Ok(validated_invitees()))]
#[test_case(vec![], Ok(vec![]))]
#[test_case(invitee_invalid_aci(), Err::<Vec<Invitee>,_>(InvalidInvitee(InviteeError::InviteeAci)))]
#[test_case(vec![], Ok(UnorderedList::from(vec![])))]
#[test_case(invitee_invalid_aci(), Err::<UnorderedList<Invitee>,_>(InvalidInvitee(InviteeError::InviteeAci)))]
#[test_case(
invitee_pni_service_id_binary(),
Err::<Vec<Invitee>, _>(InvalidInvitee(InviteeError::InviteePni))
Err::<UnorderedList<Invitee>, _>(InvalidInvitee(InviteeError::InviteePni))
)]
#[test_case(
EnumOrUnknown::default(),
Expand Down
11 changes: 11 additions & 0 deletions rust/message-backup/src/backup/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use uuid::Uuid;

use crate::backup::account_data::AccountData;
use crate::backup::call::AdHocCall;
use crate::backup::chat::group::Invitee;
use crate::backup::chat::text::{TextEffect, TextRange};
use crate::backup::chat::{ChatData, OutgoingSend};
use crate::backup::frame::RecipientId;
Expand Down Expand Up @@ -250,6 +251,16 @@ impl SerializeOrder for OutgoingSend {
}
}

impl SerializeOrder for Invitee {
fn serialize_cmp(&self, other: &Self) -> std::cmp::Ordering {
(self.invitee_aci, self.invitee_pni, self.inviter).cmp(&(
other.invitee_aci,
other.invitee_pni,
other.inviter,
))
}
}

impl serde::Serialize for proto::contact_attachment::Name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down

0 comments on commit f1b93b5

Please sign in to comment.