Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Narrow mobile contacts bindings

Manav Rathi354bbc5fa409
diff --git a/mobile/apps/locker/lib/services/frb_contacts_rust_api.dart b/mobile/apps/locker/lib/services/frb_contacts_rust_api.dart
index 7af8caf892..474ca8ed66 100644
--- a/mobile/apps/locker/lib/services/frb_contacts_rust_api.dart
+++ b/mobile/apps/locker/lib/services/frb_contacts_rust_api.dart
@@ -126,17 +126,6 @@ class _FrbContactsRustContext implements ContactsRustContext {
);
}
- @override
- Future<Uint8List> getAttachment(
- ContactAttachmentType attachmentType,
- String attachmentId,
- ) {
- return _inner.getAttachmentEncrypted(
- attachmentType: _toRustAttachmentType(attachmentType),
- attachmentId: attachmentId,
- );
- }
-
@override
Future<ContactRecord> deleteAttachment(
String contactId,
@@ -150,27 +139,10 @@ class _FrbContactsRustContext implements ContactsRustContext {
);
}
- @override
- Future<ContactRecord> setProfilePicture(
- String contactId,
- Uint8List profilePicture,
- ) async {
- return setAttachment(
- contactId,
- ContactAttachmentType.profilePicture,
- profilePicture,
- );
- }
-
@override
Future<Uint8List> getProfilePicture(String contactId) {
return _inner.getProfilePicture(contactId: contactId);
}
-
- @override
- Future<ContactRecord> deleteProfilePicture(String contactId) async {
- return deleteAttachment(contactId, ContactAttachmentType.profilePicture);
- }
}
rust.AttachmentType _toRustAttachmentType(
diff --git a/mobile/apps/photos/lib/services/frb_contacts_rust_api.dart b/mobile/apps/photos/lib/services/frb_contacts_rust_api.dart
index 5efe8e7a2b..b1d0affde7 100644
--- a/mobile/apps/photos/lib/services/frb_contacts_rust_api.dart
+++ b/mobile/apps/photos/lib/services/frb_contacts_rust_api.dart
@@ -126,17 +126,6 @@ class _FrbContactsRustContext implements ContactsRustContext {
);
}
- @override
- Future<Uint8List> getAttachment(
- ContactAttachmentType attachmentType,
- String attachmentId,
- ) {
- return _inner.getAttachmentEncrypted(
- attachmentType: _toRustAttachmentType(attachmentType),
- attachmentId: attachmentId,
- );
- }
-
@override
Future<ContactRecord> deleteAttachment(
String contactId,
@@ -150,27 +139,10 @@ class _FrbContactsRustContext implements ContactsRustContext {
);
}
- @override
- Future<ContactRecord> setProfilePicture(
- String contactId,
- Uint8List profilePicture,
- ) async {
- return setAttachment(
- contactId,
- ContactAttachmentType.profilePicture,
- profilePicture,
- );
- }
-
@override
Future<Uint8List> getProfilePicture(String contactId) {
return _inner.getProfilePicture(contactId: contactId);
}
-
- @override
- Future<ContactRecord> deleteProfilePicture(String contactId) async {
- return deleteAttachment(contactId, ContactAttachmentType.profilePicture);
- }
}
rust.AttachmentType _toRustAttachmentType(
diff --git a/mobile/packages/contacts/lib/src/rust/contacts_rust_api.dart b/mobile/packages/contacts/lib/src/rust/contacts_rust_api.dart
index a260c61dea..c5daf4a11f 100644
--- a/mobile/packages/contacts/lib/src/rust/contacts_rust_api.dart
+++ b/mobile/packages/contacts/lib/src/rust/contacts_rust_api.dart
@@ -74,24 +74,12 @@ abstract class ContactsRustContext {
Uint8List attachmentBytes,
);
- Future<Uint8List> getAttachment(
- ContactAttachmentType attachmentType,
- String attachmentId,
- );
-
Future<ContactRecord> deleteAttachment(
String contactId,
ContactAttachmentType attachmentType,
);
- Future<ContactRecord> setProfilePicture(
- String contactId,
- Uint8List profilePicture,
- );
-
Future<Uint8List> getProfilePicture(String contactId);
-
- Future<ContactRecord> deleteProfilePicture(String contactId);
}
abstract class ContactsRustApi {
diff --git a/mobile/packages/contacts/test/contacts_service_test.dart b/mobile/packages/contacts/test/contacts_service_test.dart
index db4efa2529..b82e3440a9 100644
--- a/mobile/packages/contacts/test/contacts_service_test.dart
+++ b/mobile/packages/contacts/test/contacts_service_test.dart
@@ -171,8 +171,6 @@ void main() {
await service.getProfilePicture(created.id),
Uint8List.fromList([1, 2, 3, 4]),
);
- expect(rustApi.ctx.getAttachmentCalls, 0);
-
final deletedPicture = await service.deleteProfilePicture(created.id);
expect(deletedPicture.profilePictureAttachmentId, isNull);
expect(
@@ -250,7 +248,6 @@ void main() {
await service.getProfilePicture('ct_1'),
Uint8List.fromList([7, 8, 9]),
);
- expect(rustApi.ctx.getAttachmentCalls, 0);
expect(rustApi.ctx.getProfilePictureCalls, 1);
expect(
await service.getProfilePicture('ct_1'),
@@ -419,7 +416,6 @@ class FakeContactsRustContext implements ContactsRustContext {
Future<List<ContactRecord>> Function(int sinceTime, int limit)? diffHandler;
final List<int> diffSinceTimes = [];
final List<int> diffLimits = [];
- int getAttachmentCalls = 0;
int getProfilePictureCalls = 0;
String nextAttachmentId = 'att_profile';
@@ -487,11 +483,6 @@ class FakeContactsRustContext implements ContactsRustContext {
return updated;
}
- @override
- Future<ContactRecord> deleteProfilePicture(String contactId) {
- return deleteAttachment(contactId, ContactAttachmentType.profilePicture);
- }
-
@override
Future<ContactRecord> getContact(String contactId) async =>
records[contactId]!;
@@ -519,15 +510,6 @@ class FakeContactsRustContext implements ContactsRustContext {
return first;
}
- @override
- Future<Uint8List> getAttachment(
- ContactAttachmentType attachmentType,
- String attachmentId,
- ) async {
- getAttachmentCalls += 1;
- return attachments[attachmentId]!;
- }
-
@override
Future<Uint8List> getProfilePicture(String contactId) {
getProfilePictureCalls += 1;
@@ -562,18 +544,6 @@ class FakeContactsRustContext implements ContactsRustContext {
return updated;
}
- @override
- Future<ContactRecord> setProfilePicture(
- String contactId,
- Uint8List profilePicture,
- ) {
- return setAttachment(
- contactId,
- ContactAttachmentType.profilePicture,
- profilePicture,
- );
- }
-
@override
Future<void> updateAuthToken(String authToken) async {}
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 82018edaa4..f823e08bb2 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -2644,7 +2644,6 @@ dependencies = [
name = "ente-photos-frb"
version = "0.0.0"
dependencies = [
- "ente-accounts",
"ente-cast",
"ente-contacts",
"ente-core",
diff --git a/rust/bindings/frb/locker/src/api/contacts.rs b/rust/bindings/frb/locker/src/api/contacts.rs
index cba55d7556..f675e3e206 100644
--- a/rust/bindings/frb/locker/src/api/contacts.rs
+++ b/rust/bindings/frb/locker/src/api/contacts.rs
@@ -492,17 +492,6 @@ impl ContactsCtx {
.map_err(Into::into)
}
- pub async fn get_attachment_encrypted(
- &self,
- attachment_type: AttachmentType,
- attachment_id: String,
- ) -> Result<Vec<u8>, ContactsError> {
- self.inner
- .get_attachment_encrypted(attachment_type.into(), &attachment_id)
- .await
- .map_err(Into::into)
- }
-
pub async fn delete_attachment(
&self,
contact_id: String,
@@ -515,15 +504,6 @@ impl ContactsCtx {
.map_err(Into::into)
}
- pub async fn set_profile_picture(
- &self,
- contact_id: String,
- profile_picture: Vec<u8>,
- ) -> Result<ContactRecord, ContactsError> {
- self.set_attachment(contact_id, AttachmentType::ProfilePicture, profile_picture)
- .await
- }
-
pub async fn get_profile_picture(&self, contact_id: String) -> Result<Vec<u8>, ContactsError> {
self.inner
.get_profile_picture(&contact_id)
@@ -531,14 +511,6 @@ impl ContactsCtx {
.map_err(Into::into)
}
- pub async fn delete_profile_picture(
- &self,
- contact_id: String,
- ) -> Result<ContactRecord, ContactsError> {
- self.delete_attachment(contact_id, AttachmentType::ProfilePicture)
- .await
- }
-
pub async fn legacy_kits(&self) -> Result<Vec<LegacyKit>, ContactsError> {
self.inner
.legacy_kits()
diff --git a/rust/bindings/frb/photos/Cargo.toml b/rust/bindings/frb/photos/Cargo.toml
index dc7ae58b3d..c8fca1e7f5 100644
--- a/rust/bindings/frb/photos/Cargo.toml
+++ b/rust/bindings/frb/photos/Cargo.toml
@@ -6,7 +6,6 @@ edition = "2024"
crate-type = ["cdylib", "staticlib"]
[dependencies]
-ente-accounts.workspace = true
ente-cast.workspace = true
ente-contacts.workspace = true
ente-core.workspace = true
diff --git a/rust/bindings/frb/photos/src/api/contacts.rs b/rust/bindings/frb/photos/src/api/contacts.rs
index cba55d7556..110aa89ebd 100644
--- a/rust/bindings/frb/photos/src/api/contacts.rs
+++ b/rust/bindings/frb/photos/src/api/contacts.rs
@@ -1,6 +1,5 @@
use std::sync::Arc;
-use ente_contacts::{LegacyKitOwnerRecoverySession, LegacyKitRecoveryInitiator};
use flutter_rust_bridge::frb;
#[frb]
@@ -61,43 +60,6 @@ impl From<WrappedRootContactKey> for ente_contacts::WrappedRootContactKey {
}
}
-#[frb]
-#[derive(Clone)]
-pub struct AccountKeyAttributes {
- pub kek_salt: String,
- pub encrypted_key: String,
- pub key_decryption_nonce: String,
- pub public_key: String,
- pub encrypted_secret_key: String,
- pub secret_key_decryption_nonce: String,
- pub mem_limit: u32,
- pub ops_limit: u32,
- pub master_key_encrypted_with_recovery_key: Option<String>,
- pub master_key_decryption_nonce: Option<String>,
- pub recovery_key_encrypted_with_master_key: Option<String>,
- pub recovery_key_decryption_nonce: Option<String>,
-}
-
-impl From<AccountKeyAttributes> for ente_accounts::auth::KeyAttributes {
- fn from(value: AccountKeyAttributes) -> Self {
- Self {
- kek_salt: value.kek_salt,
- kek_hash: None,
- encrypted_key: value.encrypted_key,
- key_decryption_nonce: value.key_decryption_nonce,
- public_key: value.public_key,
- encrypted_secret_key: value.encrypted_secret_key,
- secret_key_decryption_nonce: value.secret_key_decryption_nonce,
- mem_limit: value.mem_limit,
- ops_limit: value.ops_limit,
- master_key_encrypted_with_recovery_key: value.master_key_encrypted_with_recovery_key,
- master_key_decryption_nonce: value.master_key_decryption_nonce,
- recovery_key_encrypted_with_master_key: value.recovery_key_encrypted_with_master_key,
- recovery_key_decryption_nonce: value.recovery_key_decryption_nonce,
- }
- }
-}
-
#[frb]
#[derive(Clone)]
pub struct ContactData {
@@ -142,198 +104,6 @@ impl From<ente_contacts::ContactRecord> for ContactRecord {
}
}
-#[frb]
-#[derive(Clone, Copy)]
-pub enum LegacyKitVariant {
- TwoOfThree,
-}
-
-impl From<ente_contacts::LegacyKitVariant> for LegacyKitVariant {
- fn from(value: ente_contacts::LegacyKitVariant) -> Self {
- match value {
- ente_contacts::LegacyKitVariant::TwoOfThree => Self::TwoOfThree,
- }
- }
-}
-
-#[frb]
-#[derive(Clone, Copy)]
-pub enum LegacyKitRecoveryStatus {
- Waiting,
- Ready,
- Blocked,
- Cancelled,
- Recovered,
-}
-
-impl From<ente_contacts::LegacyKitRecoveryStatus> for LegacyKitRecoveryStatus {
- fn from(value: ente_contacts::LegacyKitRecoveryStatus) -> Self {
- match value {
- ente_contacts::LegacyKitRecoveryStatus::Waiting => Self::Waiting,
- ente_contacts::LegacyKitRecoveryStatus::Ready => Self::Ready,
- ente_contacts::LegacyKitRecoveryStatus::Blocked => Self::Blocked,
- ente_contacts::LegacyKitRecoveryStatus::Cancelled => Self::Cancelled,
- ente_contacts::LegacyKitRecoveryStatus::Recovered => Self::Recovered,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitRecoverySession {
- pub id: String,
- pub kit_id: String,
- pub status: LegacyKitRecoveryStatus,
- pub wait_till: i64,
- pub created_at: i64,
-}
-
-impl From<ente_contacts::LegacyKitRecoverySession> for LegacyKitRecoverySession {
- fn from(value: ente_contacts::LegacyKitRecoverySession) -> Self {
- Self {
- id: value.id,
- kit_id: value.kit_id,
- status: value.status.into(),
- wait_till: value.wait_till,
- created_at: value.created_at,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitRecoveryInitiatorHint {
- pub used_part_indexes: Vec<u8>,
- pub ip: String,
- pub user_agent: String,
-}
-
-impl From<LegacyKitRecoveryInitiator> for LegacyKitRecoveryInitiatorHint {
- fn from(value: LegacyKitRecoveryInitiator) -> Self {
- Self {
- used_part_indexes: value.used_part_indexes,
- ip: value.ip,
- user_agent: value.user_agent,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitOwnerRecoverySessionDetails {
- pub session: Option<LegacyKitRecoverySession>,
- pub initiators: Vec<LegacyKitRecoveryInitiatorHint>,
-}
-
-impl From<LegacyKitOwnerRecoverySession> for LegacyKitOwnerRecoverySessionDetails {
- fn from(value: LegacyKitOwnerRecoverySession) -> Self {
- Self {
- session: value.session.map(Into::into),
- initiators: value.initiators.into_iter().map(Into::into).collect(),
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitPart {
- pub index: u8,
- pub name: String,
-}
-
-impl From<ente_contacts::LegacyKitPart> for LegacyKitPart {
- fn from(value: ente_contacts::LegacyKitPart) -> Self {
- Self {
- index: value.index,
- name: value.name,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitMetadata {
- pub parts: Vec<LegacyKitPart>,
-}
-
-impl From<ente_contacts::LegacyKitMetadata> for LegacyKitMetadata {
- fn from(value: ente_contacts::LegacyKitMetadata) -> Self {
- Self {
- parts: value.parts.into_iter().map(Into::into).collect(),
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKit {
- pub id: String,
- pub variant: LegacyKitVariant,
- pub notice_period_in_hours: i32,
- pub legacy_url: String,
- pub metadata: LegacyKitMetadata,
- pub created_at: i64,
- pub updated_at: i64,
- pub active_recovery_session: Option<LegacyKitRecoverySession>,
-}
-
-impl From<ente_contacts::LegacyKit> for LegacyKit {
- fn from(value: ente_contacts::LegacyKit) -> Self {
- Self {
- id: value.id,
- variant: value.variant.into(),
- notice_period_in_hours: value.notice_period_in_hours,
- legacy_url: value.legacy_url,
- metadata: value.metadata.into(),
- created_at: value.created_at,
- updated_at: value.updated_at,
- active_recovery_session: value.active_recovery_session.map(Into::into),
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitShare {
- pub payload_version: u8,
- pub variant: LegacyKitVariant,
- pub kit_id: String,
- pub share_index: u8,
- pub share: String,
- pub checksum: String,
- pub part_name: String,
-}
-
-impl From<ente_contacts::LegacyKitShare> for LegacyKitShare {
- fn from(value: ente_contacts::LegacyKitShare) -> Self {
- Self {
- payload_version: value.payload_version,
- variant: value.variant.into(),
- kit_id: value.kit_id,
- share_index: value.share_index,
- share: value.share,
- checksum: value.checksum,
- part_name: value.part_name,
- }
- }
-}
-
-#[frb]
-#[derive(Clone)]
-pub struct LegacyKitCreateResult {
- pub kit: LegacyKit,
- pub shares: Vec<LegacyKitShare>,
-}
-
-impl From<ente_contacts::LegacyKitCreateResult> for LegacyKitCreateResult {
- fn from(value: ente_contacts::LegacyKitCreateResult) -> Self {
- Self {
- kit: value.kit.into(),
- shares: value.shares.into_iter().map(Into::into).collect(),
- }
- }
-}
-
#[frb]
#[derive(Clone)]
pub enum RootKeySource {
@@ -492,17 +262,6 @@ impl ContactsCtx {
.map_err(Into::into)
}
- pub async fn get_attachment_encrypted(
- &self,
- attachment_type: AttachmentType,
- attachment_id: String,
- ) -> Result<Vec<u8>, ContactsError> {
- self.inner
- .get_attachment_encrypted(attachment_type.into(), &attachment_id)
- .await
- .map_err(Into::into)
- }
-
pub async fn delete_attachment(
&self,
contact_id: String,
@@ -515,105 +274,10 @@ impl ContactsCtx {
.map_err(Into::into)
}
- pub async fn set_profile_picture(
- &self,
- contact_id: String,
- profile_picture: Vec<u8>,
- ) -> Result<ContactRecord, ContactsError> {
- self.set_attachment(contact_id, AttachmentType::ProfilePicture, profile_picture)
- .await
- }
-
pub async fn get_profile_picture(&self, contact_id: String) -> Result<Vec<u8>, ContactsError> {
self.inner
.get_profile_picture(&contact_id)
.await
.map_err(Into::into)
}
-
- pub async fn delete_profile_picture(
- &self,
- contact_id: String,
- ) -> Result<ContactRecord, ContactsError> {
- self.delete_attachment(contact_id, AttachmentType::ProfilePicture)
- .await
- }
-
- pub async fn legacy_kits(&self) -> Result<Vec<LegacyKit>, ContactsError> {
- self.inner
- .legacy_kits()
- .await
- .map(|kits| kits.into_iter().map(Into::into).collect())
- .map_err(Into::into)
- }
-
- pub async fn legacy_kit_create(
- &self,
- current_user_key_attrs: AccountKeyAttributes,
- part_names: Vec<String>,
- notice_period_in_hours: i32,
- ) -> Result<LegacyKitCreateResult, ContactsError> {
- let part_names: [String; 3] =
- part_names
- .try_into()
- .map_err(|_| ContactsError::InvalidInput {
- message: "legacy kit requires exactly three part names".into(),
- })?;
- self.inner
- .legacy_kit_create(
- &current_user_key_attrs.into(),
- part_names,
- notice_period_in_hours,
- )
- .await
- .map(Into::into)
- .map_err(Into::into)
- }
-
- pub async fn legacy_kit_download_shares(
- &self,
- kit_id: String,
- ) -> Result<Vec<LegacyKitShare>, ContactsError> {
- self.inner
- .legacy_kit_download_shares(&kit_id)
- .await
- .map(|shares| shares.into_iter().map(Into::into).collect())
- .map_err(Into::into)
- }
-
- pub async fn legacy_kit_recovery_session(
- &self,
- kit_id: String,
- ) -> Result<LegacyKitOwnerRecoverySessionDetails, ContactsError> {
- self.inner
- .legacy_kit_recovery_session(&kit_id)
- .await
- .map(Into::into)
- .map_err(Into::into)
- }
-
- pub async fn legacy_kit_update_recovery_notice(
- &self,
- kit_id: String,
- notice_period_in_hours: i32,
- ) -> Result<(), ContactsError> {
- self.inner
- .legacy_kit_update_recovery_notice(&kit_id, notice_period_in_hours)
- .await
- .map_err(Into::into)
- }
-
- pub async fn legacy_kit_block_recovery(&self, kit_id: String) -> Result<(), ContactsError> {
- self.inner
- .legacy_kit_block_recovery(&kit_id)
- .await
- .map_err(Into::into)
- }
-
- pub async fn legacy_kit_delete(&self, kit_id: String) -> Result<(), ContactsError> {
- self.inner
- .legacy_kit_delete(&kit_id)
- .await
- .map_err(Into::into)
- }
}