Skip to content

Commit

Permalink
Merge pull request #2593 from acterglobal/ben-room-activities
Browse files Browse the repository at this point in the history
Room and Object  Activities
  • Loading branch information
gnunicorn authored Feb 14, 2025
2 parents 3cbbe02 + ee77dd7 commit 66fbdf1
Show file tree
Hide file tree
Showing 39 changed files with 1,692 additions and 1,500 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 20 additions & 8 deletions native/acter/api.rsh
Original file line number Diff line number Diff line change
Expand Up @@ -2202,8 +2202,27 @@ object MembershipChange {
fn reason() -> Option<string>;
}

object ActivityObject {
fn type_str() -> string;
fn object_id_str() -> string;
fn title() -> Option<string>;
fn emoji() -> string;
}

object Activity {
// generic

/// the event_id as a string
fn event_id_str() -> string;
/// the sender of this event as a string
fn sender_id_str() -> string;

/// the server receiving timestamp in milliseconds
fn origin_server_ts() -> u64;

/// the room_id of this event
fn room_id_str() -> string;

/// the type of this activity as a string
/// e.g. invited, invitationAccepted
fn type_str() -> string;
Expand Down Expand Up @@ -2800,20 +2819,13 @@ object NotificationRoom {
fn image() -> Future<Result<buffer<u8>>>;
}

object NotificationItemParent {
fn object_type_str() -> string;
fn object_id_str() -> string;
fn title() -> Option<string>;
fn emoji() -> string;
}

// converting a room_id+event_id into the notification item to show
// from push context.
object NotificationItem {
fn push_style() -> string;
fn title() -> string;
fn sender() -> NotificationSender;
fn parent() -> Option<NotificationItemParent>;
fn parent() -> Option<ActivityObject>;
fn parent_id_str() -> Option<string>;
fn room() -> NotificationRoom;
fn target_url() -> string;
Expand Down
6 changes: 3 additions & 3 deletions native/acter/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub use acter_core::{
},
models::{ActerModel, Tag, TextMessageContent},
};
pub use activities::{Activities, Activity, MembershipChange};
pub use activities::{Activities, Activity, ActivityObject, MembershipChange};
pub use attachments::{Attachment, AttachmentDraft, AttachmentsManager};
pub use auth::{
destroy_local_data, guest_client, login_new_client, login_with_token, register_with_token,
Expand Down Expand Up @@ -104,8 +104,8 @@ pub use news::{NewsEntry, NewsEntryDraft, NewsEntryUpdateBuilder, NewsSlide, New
pub use pins::{Pin as ActerPin, PinDraft, PinUpdateBuilder};
pub use profile::UserProfile;
pub use push::{
NotificationItem, NotificationItemParent, NotificationRoom, NotificationSender,
NotificationSettings, Pusher, SubscriptionStatus,
NotificationItem, NotificationRoom, NotificationSender, NotificationSettings, Pusher,
SubscriptionStatus,
};
pub use reactions::{Reaction, ReactionManager};
pub use read_receipts::ReadReceiptsManager;
Expand Down
45 changes: 32 additions & 13 deletions native/acter/src/api/activities.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::Deref;

pub use acter_core::activities::object::ActivityObject;
use acter_core::{
activities::Activity as CoreActivity,
models::{status::membership::MembershipChange as CoreMembershipChange, ActerModel},
Expand All @@ -12,6 +13,7 @@ use tokio_stream::wrappers::BroadcastStream;

use super::{Client, RUNTIME};

use acter_core::activities::ActivityContent;
#[derive(Clone, Debug)]
pub struct MembershipChange(CoreMembershipChange);

Expand All @@ -37,14 +39,29 @@ pub struct Activity {
}

impl Activity {
#[cfg(any(test, feature = "testing"))]
pub fn inner(&self) -> CoreActivity {
self.inner.clone()
pub fn content(&self) -> &ActivityContent {
self.inner.content()
}

pub fn membership_change(&self) -> Option<MembershipChange> {
self.inner.membership_change().map(MembershipChange)
}

pub fn sender_id_str(&self) -> String {
self.inner.event_meta().sender.to_string()
}

pub fn origin_server_ts(&self) -> u64 {
self.inner.event_meta().origin_server_ts.get().into()
}

pub fn room_id_str(&self) -> String {
self.inner.event_meta().room_id.to_string()
}

pub fn event_id_str(&self) -> String {
self.inner.event_meta().event_id.to_string()
}
}

impl Deref for Activity {
Expand All @@ -67,24 +84,26 @@ impl Activities {
RUNTIME
.spawn(async move {
anyhow::Ok(
me.client
.store()
.get_list(&me.index)
me.iter()
.await?
.filter_map(|a| {
// potential optimization: do the check without conversation and
// return the event id if feasible
let event_id = a.event_id().to_string();
CoreActivity::try_from(a).map(|_| event_id).ok()
})
.map(|e| e.event_meta().event_id.to_string())
.skip(offset as usize)
.take(limit as usize)
.collect(),
.collect()
.await,
)
})
.await?
}

pub async fn iter(&self) -> anyhow::Result<impl Stream<Item = CoreActivity> + '_> {
let store = self.client.store();
Ok(
futures::stream::iter(self.client.store().get_list(&self.index).await?)
.filter_map(|a| async { CoreActivity::for_acter_model(store, a).await.ok() }),
)
}

pub fn subscribe_stream(&self) -> impl Stream<Item = bool> {
BroadcastStream::new(self.subscribe()).map(|f| true)
}
Expand Down
2 changes: 1 addition & 1 deletion native/acter/src/api/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl OptionComposeDraft {
}

pub struct MediaSource {
inner: SdkMediaSource,
pub(crate) inner: SdkMediaSource,
}

impl MediaSource {
Expand Down
4 changes: 1 addition & 3 deletions native/acter/src/api/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ mod notification_item;
mod notification_settings;
mod pusher;

pub use notification_item::{
NotificationItem, NotificationItemParent, NotificationRoom, NotificationSender,
};
pub use notification_item::{NotificationItem, NotificationRoom, NotificationSender};
pub(crate) use notification_settings::{notification_mode_from_input, room_notification_mode_name};
pub use notification_settings::{NotificationSettings, SubscriptionStatus};
pub use pusher::Pusher;
Loading

0 comments on commit 66fbdf1

Please sign in to comment.