Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror Contact struct in new backwards-compat model package #281

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion presage-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ use mime_guess::mime::APPLICATION_OCTET_STREAM;
use notify_rust::Notification;
use presage::libsignal_service::configuration::SignalServers;
use presage::libsignal_service::content::Reaction;
use presage::libsignal_service::models::Contact;
use presage::libsignal_service::pre_keys::PreKeysStore;
use presage::libsignal_service::prelude::phonenumber::PhoneNumber;
use presage::libsignal_service::prelude::ProfileKey;
@@ -26,6 +25,7 @@ use presage::libsignal_service::sender::AttachmentSpec;
use presage::libsignal_service::zkgroup::GroupMasterKeyBytes;
use presage::libsignal_service::ServiceAddress;
use presage::manager::ReceivingMode;
use presage::model::contacts::Contact;
use presage::model::groups::Group;
use presage::proto::receipt_message;
use presage::proto::EditMessage;
3 changes: 1 addition & 2 deletions presage-store-sled/src/content.rs
Original file line number Diff line number Diff line change
@@ -6,12 +6,11 @@ use std::{
use presage::{
libsignal_service::{
content::Content,
models::Contact,
prelude::Uuid,
zkgroup::{profiles::ProfileKey, GroupMasterKeyBytes},
Profile,
},
model::groups::Group,
model::{contacts::Contact, groups::Group},
store::{ContentExt, ContentsStore, StickerPack, Thread},
AvatarBytes,
};
1 change: 1 addition & 0 deletions presage/Cargo.toml
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ tracing = "0.1"
url = "2.5"
serde_with = "3.11.0"
derivative = "2.2.0"
bytes = { version = "1.7.2", features = ["serde"] }

[dev-dependencies]
quickcheck = "1.0.3"
4 changes: 2 additions & 2 deletions presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ use libsignal_service::configuration::{ServiceConfiguration, SignalServers, Sign
use libsignal_service::content::{Content, ContentBody, DataMessageFlags, Metadata};
use libsignal_service::groups_v2::{decrypt_group, GroupsManager, InMemoryCredentialsCache};
use libsignal_service::messagepipe::{Incoming, MessagePipe, ServiceCredentials};
use libsignal_service::models::Contact;
use libsignal_service::prelude::phonenumber::PhoneNumber;
use libsignal_service::prelude::{MessageSenderError, ProtobufMessage, Uuid};
use libsignal_service::profile_cipher::ProfileCipher;
@@ -43,6 +42,7 @@ use tokio::sync::Mutex;
use tracing::{debug, error, info, trace, warn};
use url::Url;

use crate::model::contacts::Contact;
use crate::serde::serde_profile_key;
use crate::store::{ContentsStore, Sticker, StickerPack, StickerPackManifest, Store, Thread};
use crate::{model::groups::Group, AvatarBytes, Error, Manager};
@@ -665,7 +665,7 @@ impl<S: Store> Manager<S, Registered> {
info!("saving contacts");
for contact in contacts.filter_map(Result::ok) {
if let Err(error) =
state.store.save_contact(&contact)
state.store.save_contact(&contact.into())
{
warn!(%error, "failed to save contacts");
break;
50 changes: 50 additions & 0 deletions presage/src/model/contacts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use bytes::Bytes;
use libsignal_service::{
models::Attachment,
prelude::{phonenumber::PhoneNumber, Uuid},
proto::Verified,
};
use serde::{Deserialize, Serialize};

const fn default_expire_timer_version() -> u32 {
2
}

/// Mirror of the protobuf ContactDetails message
/// but with stronger types (e.g. `ServiceAddress` instead of optional uuid and string phone numbers)
/// and some helper functions
#[derive(Debug, Serialize, Deserialize)]
pub struct Contact {
pub uuid: Uuid,
pub phone_number: Option<PhoneNumber>,
pub name: String,
pub color: Option<String>,
#[serde(skip)]
pub verified: Verified,
pub profile_key: Vec<u8>,
pub expire_timer: u32,
#[serde(default = "default_expire_timer_version")]
pub expire_timer_version: u32,
pub inbox_position: u32,
pub archived: bool,
#[serde(skip)]
pub avatar: Option<Attachment<Bytes>>,
}

impl From<libsignal_service::models::Contact> for Contact {
fn from(c: libsignal_service::models::Contact) -> Self {
Self {
uuid: c.uuid,
phone_number: c.phone_number,
name: c.name,
color: c.color,
verified: c.verified,
profile_key: c.profile_key,
expire_timer: c.expire_timer,
expire_timer_version: c.expire_timer_version,
inbox_position: c.inbox_position,
archived: c.archived,
avatar: c.avatar,
}
}
}
1 change: 1 addition & 0 deletions presage/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};

pub mod contacts;
pub mod groups;

#[derive(Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
7 changes: 5 additions & 2 deletions presage/src/store.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,6 @@ use std::{fmt, ops::RangeBounds, time::SystemTime};
use libsignal_service::{
content::{ContentBody, Metadata},
groups_v2::Timer,
models::Contact,
pre_keys::PreKeysStore,
prelude::{Content, ProfileKey, Uuid, UuidError},
proto::{
@@ -20,7 +19,11 @@ use libsignal_service::{
use serde::{Deserialize, Serialize};
use tracing::{error, trace};

use crate::{manager::RegistrationData, model::groups::Group, AvatarBytes};
use crate::{
manager::RegistrationData,
model::{contacts::Contact, groups::Group},
AvatarBytes,
};

/// An error trait implemented by store error types
pub trait StoreError: std::error::Error + Sync + Send {}