Skip to content

Commit 9940c59

Browse files
committed
refactor(sdk-swift): Use UserId instead of JID in AccountBookmarksClient and Contact
1 parent 6dd3658 commit 9940c59

File tree

7 files changed

+42
-102
lines changed

7 files changed

+42
-102
lines changed

bindings/prose-sdk-ffi/src/account_bookmarks_client.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright: 2023, Marc Bauer <[email protected]>
44
// License: Mozilla Public License v2.0 (MPL v2.0)
55

6-
use crate::{types::ClientResult, AccountBookmark, PathBuf, JID};
6+
use crate::{types::ClientResult, AccountBookmark, PathBuf, UserId};
77

88
#[derive(uniffi::Object)]
99
pub struct AccountBookmarksClient {
@@ -28,19 +28,19 @@ impl AccountBookmarksClient {
2828
.collect())
2929
}
3030

31-
pub fn add_bookmark(&self, jid: &JID, select_bookmark: bool) -> ClientResult<()> {
31+
pub fn add_bookmark(&self, user_id: UserId, select_bookmark: bool) -> ClientResult<()> {
3232
self.client
33-
.add_bookmark(&jid.clone().into(), select_bookmark)?;
33+
.add_bookmark(&(user_id.into()), select_bookmark)?;
3434
Ok(())
3535
}
3636

37-
pub fn remove_bookmark(&self, jid: &JID) -> ClientResult<()> {
38-
self.client.remove_bookmark(&jid.clone().into())?;
37+
pub fn remove_bookmark(&self, user_id: UserId) -> ClientResult<()> {
38+
self.client.remove_bookmark(&(user_id.into()))?;
3939
Ok(())
4040
}
4141

42-
pub fn select_bookmark(&self, jid: &JID) -> ClientResult<()> {
43-
self.client.select_bookmark(&jid.clone().into())?;
42+
pub fn select_bookmark(&self, user_id: UserId) -> ClientResult<()> {
43+
self.client.select_bookmark(&(user_id.into()))?;
4444
Ok(())
4545
}
4646

bindings/prose-sdk-ffi/src/types/account_bookmark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
// Copyright: 2023, Marc Bauer <[email protected]>
44
// License: Mozilla Public License v2.0 (MPL v2.0)
55

6-
use crate::types::JID;
6+
use crate::UserId;
77
use prose_core_client::AccountBookmark as ProseAccountBookmark;
88

99
#[derive(uniffi::Record)]
1010
pub struct AccountBookmark {
11-
pub jid: JID,
11+
pub user_id: UserId,
1212
pub is_selected: bool,
1313
}
1414

1515
impl From<ProseAccountBookmark> for AccountBookmark {
1616
fn from(value: ProseAccountBookmark) -> Self {
1717
AccountBookmark {
18-
jid: value.jid.into(),
18+
user_id: value.user_id.into(),
1919
is_selected: value.is_selected,
2020
}
2121
}
@@ -24,7 +24,7 @@ impl From<ProseAccountBookmark> for AccountBookmark {
2424
impl From<AccountBookmark> for ProseAccountBookmark {
2525
fn from(value: AccountBookmark) -> Self {
2626
ProseAccountBookmark {
27-
jid: value.jid.into(),
27+
user_id: value.user_id.into(),
2828
is_selected: value.is_selected,
2929
}
3030
}

bindings/prose-sdk-ffi/src/types/contact.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
// Copyright: 2023, Marc Bauer <[email protected]>
44
// License: Mozilla Public License v2.0 (MPL v2.0)
55

6-
use crate::types::JID;
6+
use crate::UserId;
77
use prose_core_client::dtos::{
88
Availability as CoreAvailability, Contact as CoreContact, Group as CoreGroup,
99
UserStatus as CoreUserStatus,
1010
};
1111

12-
#[derive(uniffi::Enum, Debug, PartialEq, Clone)]
12+
#[derive(uniffi::Enum)]
1313
pub enum Group {
1414
Team,
1515
Other,
1616
}
1717

18-
#[derive(uniffi::Enum, Debug, PartialEq, Clone)]
18+
#[derive(uniffi::Enum)]
1919
pub enum Availability {
2020
Available,
2121
Unavailable,
@@ -24,15 +24,15 @@ pub enum Availability {
2424
Invisible,
2525
}
2626

27-
#[derive(uniffi::Record, Debug, PartialEq, Clone)]
27+
#[derive(uniffi::Record)]
2828
pub struct UserStatus {
2929
pub emoji: String,
3030
pub status: Option<String>,
3131
}
3232

33-
#[derive(uniffi::Record, Debug, PartialEq, Clone)]
33+
#[derive(uniffi::Record)]
3434
pub struct Contact {
35-
pub jid: JID,
35+
pub id: UserId,
3636
pub name: String,
3737
pub availability: Availability,
3838
pub status: Option<UserStatus>,
@@ -42,7 +42,7 @@ pub struct Contact {
4242
impl From<CoreContact> for Contact {
4343
fn from(value: CoreContact) -> Self {
4444
Contact {
45-
jid: value.id.into_inner().into(),
45+
id: value.id.into(),
4646
name: value.name,
4747
availability: value.availability.into(),
4848
status: value.status.map(Into::into),

bindings/prose-sdk-ffi/src/types/jid.rs

Lines changed: 0 additions & 64 deletions
This file was deleted.

bindings/prose-sdk-ffi/src/types/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ pub use attachment::Attachment;
99
pub use avatar::Avatar;
1010
pub use client_event::ClientEvent;
1111
pub use contact::{Availability, Contact, Group, UserStatus};
12-
pub use errors::{ClientError, ClientResult, ConnectionError, JidParseError};
13-
pub use jid::{parse_jid, JID};
12+
pub use errors::{ClientError, ClientResult, ConnectionError};
1413
pub use message::{Message, Reaction};
1514
pub use message_result_set::MessageResultSet;
1615
pub use participant_info::{ParticipantBasicInfo, ParticipantInfo};
@@ -32,7 +31,6 @@ mod avatar;
3231
mod client_event;
3332
mod contact;
3433
mod errors;
35-
mod jid;
3634
mod message;
3735
mod message_result_set;
3836
mod participant_info;

bindings/prose-sdk-ffi/src/uniffi_api.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Copyright: 2023, Marc Bauer <[email protected]>
44
// License: Mozilla Public License v2.0 (MPL v2.0)
55

6-
pub use crate::types::{AccountBookmark, ClientError, ClientEvent, Contact, Group, Message, JID};
6+
pub use crate::types::{AccountBookmark, ClientError, ClientEvent, Contact, Group, Message};
77
pub use crate::{account_bookmarks_client::AccountBookmarksClient, client::*, logger::*};
88
use jid::BareJid as CoreBareJid;
99
use mime::Mime as CoreMime;
@@ -247,7 +247,7 @@ impl From<CorePathBuf> for PathBuf {
247247
pub mod uniffi_types {
248248
pub use crate::{
249249
client::Client,
250-
types::{parse_jid, AccountBookmark, Message, Reaction, UserProfile, JID},
250+
types::{AccountBookmark, Message, Reaction, UserProfile},
251251
AvatarId, ClientError, Contact, DateTimeFixed, Emoji, MessageId, MucId, ParticipantId,
252252
PathBuf, PresenceSubRequestId, RoomId, ServerId, UnicodeScalarIndex, Url, UserId,
253253
};

crates/prose-core-client/src/util/account_bookmarks_client.rs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,24 @@ use std::fs::File;
77
use std::io::{BufReader, BufWriter, Write};
88
use std::path::{Path, PathBuf};
99

10+
use crate::domain::shared::models::UserId;
1011
use anyhow::Result;
11-
use jid::BareJid;
1212
use serde::{Deserialize, Serialize};
1313
use tempfile::NamedTempFile;
1414

1515
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
1616
pub struct AccountBookmark {
17-
pub jid: BareJid,
17+
pub user_id: UserId,
1818
#[serde(rename = "selected")]
1919
pub is_selected: bool,
2020
}
2121

2222
impl AccountBookmark {
23-
pub fn new(jid: BareJid, is_selected: bool) -> Self {
24-
AccountBookmark { jid, is_selected }
23+
pub fn new(user_id: UserId, is_selected: bool) -> Self {
24+
AccountBookmark {
25+
user_id,
26+
is_selected,
27+
}
2528
}
2629
}
2730

@@ -52,27 +55,30 @@ impl AccountBookmarksClient {
5255
Ok(contents.accounts)
5356
}
5457

55-
pub fn add_bookmark(&self, jid: &BareJid, select_bookmark: bool) -> Result<()> {
58+
pub fn add_bookmark(&self, user_id: &UserId, select_bookmark: bool) -> Result<()> {
5659
let mut bookmarks = self.load_bookmarks()?;
5760

58-
if !bookmarks.iter().any(|bookmark| &bookmark.jid == jid) {
61+
if !bookmarks
62+
.iter()
63+
.any(|bookmark| &bookmark.user_id == user_id)
64+
{
5965
bookmarks.push(AccountBookmark {
60-
jid: jid.clone(),
66+
user_id: user_id.clone(),
6167
is_selected: false,
6268
});
6369
}
6470

6571
if select_bookmark || bookmarks.len() == 1 {
6672
for bookmark in bookmarks.iter_mut() {
67-
bookmark.is_selected = &bookmark.jid == jid;
73+
bookmark.is_selected = &bookmark.user_id == user_id;
6874
}
6975
}
7076
self.save_bookmarks(bookmarks)
7177
}
7278

73-
pub fn remove_bookmark(&self, jid: &BareJid) -> Result<()> {
79+
pub fn remove_bookmark(&self, user_id: &UserId) -> Result<()> {
7480
let mut bookmarks = self.load_bookmarks()?;
75-
bookmarks.retain(|bookmark| &bookmark.jid != jid);
81+
bookmarks.retain(|bookmark| &bookmark.user_id != user_id);
7682
if !bookmarks.iter().any(|bookmark| bookmark.is_selected) {
7783
if let Some(bookmark) = bookmarks.get_mut(0) {
7884
bookmark.is_selected = true;
@@ -81,10 +87,10 @@ impl AccountBookmarksClient {
8187
self.save_bookmarks(bookmarks)
8288
}
8389

84-
pub fn select_bookmark(&self, jid: &BareJid) -> Result<()> {
90+
pub fn select_bookmark(&self, user_id: &UserId) -> Result<()> {
8591
let mut bookmarks = self.load_bookmarks()?;
8692
for bookmark in bookmarks.iter_mut() {
87-
bookmark.is_selected = &bookmark.jid == jid;
93+
bookmark.is_selected = &bookmark.user_id == user_id;
8894
}
8995
self.save_bookmarks(bookmarks)?;
9096
Ok(())
@@ -127,9 +133,9 @@ mod tests {
127133

128134
println!("{:?}", path);
129135

130-
let a = BareJid::from_str("[email protected]").unwrap();
131-
let b = BareJid::from_str("[email protected]").unwrap();
132-
let c = BareJid::from_str("[email protected]").unwrap();
136+
let a = UserId::from_str("[email protected]")?;
137+
let b = UserId::from_str("[email protected]")?;
138+
let c = UserId::from_str("[email protected]")?;
133139

134140
let client = AccountBookmarksClient::new(path.clone());
135141
client.add_bookmark(&a, false)?;

0 commit comments

Comments
 (0)