Skip to content

Commit

Permalink
fix: Use internal IDs for messages (closes #89)
Browse files Browse the repository at this point in the history
  • Loading branch information
nesium committed Aug 29, 2024
1 parent e60fe3d commit 6f648cf
Show file tree
Hide file tree
Showing 51 changed files with 1,739 additions and 847 deletions.
12 changes: 6 additions & 6 deletions bindings/prose-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::sync::Arc;
use parking_lot::{Mutex, RwLock};
use tracing::info;

use prose_core_client::dtos::{Availability, Emoji, MessageRemoteId, UserProfile};
use prose_core_client::dtos::{Availability, Emoji, MessageId, UserProfile};
use prose_core_client::infra::encryption::{EncryptionKeysRepository, SessionRepository};
use prose_core_client::infra::general::OsRngProvider;
use prose_core_client::{
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Client {
pub async fn load_latest_messages(
&self,
_from: JID,
_since: Option<MessageRemoteId>,
_since: Option<MessageId>,
_load_from_server: bool,
) -> Result<Vec<Message>, ClientError> {
todo!("Use Room API");
Expand All @@ -153,7 +153,7 @@ impl Client {
pub async fn load_messages_with_ids(
&self,
_conversation: JID,
_ids: Vec<MessageRemoteId>,
_ids: Vec<MessageId>,
) -> Result<Vec<Message>, ClientError> {
todo!("Use Room API");
// let messages = self
Expand All @@ -172,7 +172,7 @@ impl Client {
pub async fn update_message(
&self,
_conversation: JID,
_id: MessageRemoteId,
_id: MessageId,
_body: String,
) -> Result<(), ClientError> {
todo!("Use Room API");
Expand All @@ -185,7 +185,7 @@ impl Client {
pub async fn toggle_reaction_to_message(
&self,
_conversation: JID,
_id: MessageRemoteId,
_id: MessageId,
_emoji: Emoji,
) -> Result<(), ClientError> {
todo!("Use Room API");
Expand All @@ -198,7 +198,7 @@ impl Client {
pub async fn retract_message(
&self,
_conversation: JID,
_id: MessageRemoteId,
_id: MessageId,
) -> Result<(), ClientError> {
todo!("Use Room API");
// self.client
Expand Down
10 changes: 4 additions & 6 deletions bindings/prose-sdk-ffi/src/prose_sdk_ffi.udl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ typedef string PathBuf;
[Custom]
typedef string Url;
[Custom]
typedef string MessageRemoteId;
[Custom]
typedef string MessageServerId;
typedef string MessageId;
[Custom]
typedef string Emoji;
[Custom]
Expand Down Expand Up @@ -55,9 +53,9 @@ interface ClientEvent {
ConnectionStatusChanged(ConnectionEvent event);
ContactChanged(JID jid);
AvatarChanged(JID jid);
MessagesAppended(JID conversation, sequence<MessageRemoteId> message_ids);
MessagesUpdated(JID conversation, sequence<MessageRemoteId> message_ids);
MessagesDeleted(JID conversation, sequence<MessageRemoteId> message_ids);
MessagesAppended(JID conversation, sequence<MessageId> message_ids);
MessagesUpdated(JID conversation, sequence<MessageId> message_ids);
MessagesDeleted(JID conversation, sequence<MessageId> message_ids);
};

[Enum]
Expand Down
8 changes: 4 additions & 4 deletions bindings/prose-sdk-ffi/src/types/client_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// License: Mozilla Public License v2.0 (MPL v2.0)

use crate::uniffi_types::JID;
use prose_core_client::dtos::MessageRemoteId;
use prose_core_client::dtos::MessageId;
use prose_core_client::ConnectionEvent;

pub enum ClientEvent {
Expand All @@ -23,19 +23,19 @@ pub enum ClientEvent {
/// One or many messages were either received or sent.
MessagesAppended {
conversation: JID,
message_ids: Vec<MessageRemoteId>,
message_ids: Vec<MessageId>,
},

/// One or many messages were received that affected earlier messages (e.g. a reaction).
MessagesUpdated {
conversation: JID,
message_ids: Vec<MessageRemoteId>,
message_ids: Vec<MessageId>,
},

/// A message was deleted.
MessagesDeleted {
conversation: JID,
message_ids: Vec<MessageRemoteId>,
message_ids: Vec<MessageId>,
},
}

Expand Down
6 changes: 2 additions & 4 deletions bindings/prose-sdk-ffi/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use chrono::{DateTime as ChronoDateTime, Utc};

use prose_core_client::dtos::{Emoji, Message as ProseMessage, MessageRemoteId, MessageServerId};
use prose_core_client::dtos::{Emoji, Message as ProseMessage, MessageId};

use crate::types::JID;

Expand All @@ -19,8 +19,7 @@ pub struct Reaction {

#[derive(uniffi::Record)]
pub struct Message {
pub id: Option<MessageRemoteId>,
pub stanza_id: Option<MessageServerId>,
pub id: MessageId,
pub from: Option<JID>,
pub body: String,
pub timestamp: DateTime,
Expand All @@ -34,7 +33,6 @@ impl From<ProseMessage> for Message {
fn from(value: ProseMessage) -> Self {
Message {
id: value.id,
stanza_id: value.stanza_id,
from: value.from.id.to_user_id().map(|id| id.into_inner().into()),
body: todo!(),
timestamp: value.timestamp,
Expand Down
19 changes: 4 additions & 15 deletions bindings/prose-sdk-ffi/src/uniffi_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub use std::path::PathBuf;
pub use jid::{BareJid, Error as JidParseError, FullJid};

pub use prose_core_client::dtos::{
Address, Availability, Emoji, MessageRemoteId, MessageServerId, Url, UserProfile, UserStatus,
Address, Availability, Emoji, MessageId, MessageRemoteId, MessageServerId, Url, UserProfile,
UserStatus,
};
pub use prose_core_client::ConnectionEvent;
pub use prose_xmpp::ConnectionError;
Expand All @@ -20,19 +21,7 @@ pub use crate::{
account_bookmarks_client::AccountBookmarksClient, client::*, logger::*, ClientError,
};

impl UniffiCustomTypeConverter for MessageRemoteId {
type Builtin = String;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Ok(val.into())
}

fn from_custom(obj: Self) -> Self::Builtin {
obj.into_inner()
}
}

impl UniffiCustomTypeConverter for MessageServerId {
impl UniffiCustomTypeConverter for MessageId {
type Builtin = String;

fn into_custom(val: Self::Builtin) -> uniffi::Result<Self> {
Expand Down Expand Up @@ -102,7 +91,7 @@ pub mod uniffi_types {
client::Client,
types::{parse_jid, AccountBookmark, DateTime, Message, Reaction, JID},
Availability, ClientError, ConnectionError, Contact, Emoji, FullJid, JidParseError,
MessageRemoteId, MessageServerId, PathBuf, Url, UserProfile,
MessageId, PathBuf, Url, UserProfile,
};
}

Expand Down
10 changes: 9 additions & 1 deletion bindings/prose-sdk-js/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use tracing::warn;
use wasm_bindgen::prelude::*;

use prose_core_client::dtos::MessageRemoteId;
use prose_core_client::dtos::{MessageId, MessageRemoteId};
use prose_core_client::{ClientDelegate, ClientEvent, ClientRoomEventType, ConnectionEvent};
use prose_xmpp::ConnectionError;

Expand Down Expand Up @@ -223,6 +223,14 @@ impl JSValueConvertible for Vec<MessageRemoteId> {
}
}

impl JSValueConvertible for Vec<MessageId> {
fn into_js_array(self) -> Vec<JsValue> {
self.into_iter()
.map(|id| JsValue::from(id.into_inner()))
.collect()
}
}

impl ClientDelegate for Delegate {
fn handle_event(&self, client: prose_core_client::Client, event: ClientEvent) {
match self.handle_event_throwing(client, event) {
Expand Down
19 changes: 6 additions & 13 deletions bindings/prose-sdk-js/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ pub struct Body {

#[wasm_bindgen]
pub struct Message {
id: Option<String>,
stanza_id: Option<ArchiveID>,
id: String,
from: MessageSender,
body: Body,
timestamp: js_sys::Date,
Expand Down Expand Up @@ -96,8 +95,7 @@ impl From<dtos::Message> for Message {
.collect_into_js_array();

Self {
id: value.id.map(|id| id.to_string()),
stanza_id: value.stanza_id.map(ArchiveID::from),
id: value.id.to_string(),
from: value.from.into(),
body: Body {
raw: value.body.raw,
Expand Down Expand Up @@ -128,18 +126,13 @@ impl From<dtos::Message> for Message {
#[wasm_bindgen]
impl Message {
#[wasm_bindgen(getter)]
pub fn id(&self) -> Option<String> {
self.id.as_ref().map(|id| id.to_string())
pub fn id(&self) -> String {
self.id.to_string()
}

#[wasm_bindgen(setter)]
pub fn set_id(&mut self, id: Option<String>) {
self.id = id.clone().map(Into::into)
}

#[wasm_bindgen(getter, js_name = "archiveId")]
pub fn stanza_id(&self) -> Option<ArchiveID> {
self.stanza_id.clone()
pub fn set_id(&mut self, id: String) {
self.id = id.into()
}

#[wasm_bindgen(getter, js_name = "from")]
Expand Down
6 changes: 3 additions & 3 deletions bindings/prose-sdk-js/src/types/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing::debug;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::{JsError, JsValue};

use prose_core_client::dtos::{MessageRemoteId, RoomEnvelope, RoomState as SdkRoomState};
use prose_core_client::dtos::{MessageId, RoomEnvelope, RoomState as SdkRoomState};
use prose_core_client::services::{
DirectMessage, Generic, Group, PrivateChannel, PublicChannel, Room as SdkRoom,
};
Expand Down Expand Up @@ -337,9 +337,9 @@ macro_rules! base_room_impl {
&self,
message_ids: &StringArray,
) -> Result<MessagesArray> {
let message_ids: Vec<MessageRemoteId> = Vec::<String>::try_from(message_ids)?
let message_ids: Vec<MessageId> = Vec::<String>::try_from(message_ids)?
.into_iter()
.map(|id| MessageRemoteId::from(id))
.map(|id| MessageId::from(id))
.collect();

let messages = self
Expand Down
4 changes: 3 additions & 1 deletion crates/prose-core-client/src/app/deps/app_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::domain::general::services::RequestHandlingService;
use crate::domain::messaging::repos::{
DraftsRepository, MessagesRepository, OfflineMessagesRepository,
};
use crate::domain::messaging::services::MessageArchiveDomainService;
use crate::domain::messaging::services::{MessageArchiveDomainService, MessageIdProvider};
use crate::domain::messaging::services::{
MessageArchiveService, MessageMigrationDomainService, MessagingService,
};
Expand Down Expand Up @@ -68,6 +68,7 @@ pub type DynIDProvider = Arc<dyn IDProvider>;
pub type DynLocalRoomSettingsRepository = Arc<dyn LocalRoomSettingsRepository>;
pub type DynMessageArchiveDomainService = Arc<dyn MessageArchiveDomainService>;
pub type DynMessageArchiveService = Arc<dyn MessageArchiveService>;
pub type DynMessageIdProvider = Arc<dyn MessageIdProvider>;
pub type DynMessageMigrationDomainService = Arc<dyn MessageMigrationDomainService>;
pub type DynMessagesRepository = Arc<dyn MessagesRepository>;
pub type DynMessagingService = Arc<dyn MessagingService>;
Expand Down Expand Up @@ -107,6 +108,7 @@ pub struct AppDependencies {
pub drafts_repo: DynDraftsRepository,
pub encryption_domain_service: DynEncryptionDomainService,
pub id_provider: DynIDProvider,
pub message_id_provider: DynMessageIdProvider,
pub local_room_settings_repo: DynLocalRoomSettingsRepository,
pub message_archive_service: DynMessageArchiveService,
pub messages_repo: DynMessagesRepository,
Expand Down
6 changes: 3 additions & 3 deletions crates/prose-core-client/src/app/dtos/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

use chrono::{DateTime, Utc};

use crate::domain::messaging::models::MessageId;
use crate::domain::shared::models::ParticipantId;
use crate::dtos::{Attachment, Avatar, Body, Emoji, Mention, MessageRemoteId, MessageServerId};
use crate::dtos::{Attachment, Avatar, Body, Emoji, Mention};

#[derive(Debug, Clone, PartialEq)]
pub struct Message {
pub id: Option<MessageRemoteId>,
pub stanza_id: Option<MessageServerId>,
pub id: MessageId,
pub from: MessageSender,
pub body: Body,
pub timestamp: DateTime<Utc>,
Expand Down
2 changes: 1 addition & 1 deletion crates/prose-core-client/src/app/dtos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use crate::domain::{
general::models::SoftwareVersion,
messaging::models::{
Attachment, AttachmentType, Body, Emoji, EncryptedPayload, EncryptionKey, Mention,
MessageRemoteId, MessageServerId, Thumbnail,
MessageId, MessageRemoteId, MessageServerId, Thumbnail,
},
rooms::models::{Participant, PublicRoomInfo, RoomAffiliation, RoomState},
shared::models::{
Expand Down
Loading

0 comments on commit 6f648cf

Please sign in to comment.