Skip to content

Commit

Permalink
Add MessagePack versions of all Community/Group/User endpoints (#6463)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Sep 26, 2024
1 parent 059f065 commit b202cd6
Show file tree
Hide file tree
Showing 264 changed files with 642 additions and 311 deletions.
4 changes: 4 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Add MessagePack versions of all endpoints ([#6463](https://github.com/open-chat-labs/open-chat/pull/6463))

### Changed

- Increase max stable memory read / write buffer size ([#6440](https://github.com/open-chat-labs/open-chat/pull/6440))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, CommunityCanisterChannelSummary};

#[ts_export(community, channel_summary)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
pub invite_code: Option<u64>,
}

#[ts_export(community, channel_summary)]
// Allow the large size difference because essentially all responses are the large variant anyway
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, CommunityCanisterChannelSummary, CommunityCanisterChannelSummaryUpdates, TimestampMillis};

#[ts_export(community, channel_summary_updates)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
Expand All @@ -10,6 +12,7 @@ pub struct Args {
}

// Allow the large size difference because essentially all responses are the large variant anyway
#[ts_export(community, channel_summary_updates)]
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, MessageContent, MessageId, MessageIndex};

#[ts_export(community, delete_message)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
pub thread_root_message_index: Option<MessageIndex>,
pub message_id: MessageId,
}

#[ts_export(community, delete_message)]
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Expand All @@ -21,6 +24,7 @@ pub enum Response {
MessageHardDeleted,
}

#[ts_export(community, delete_message)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub content: MessageContent,
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/community/api/src/queries/events.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, EventIndex, MessageIndex, TimestampMillis};

#[ts_export(community, events)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, EventIndex, MessageIndex, TimestampMillis};

#[ts_export(community, events_by_index)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/community/api/src/queries/events_window.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, MessageIndex, TimestampMillis};

#[ts_export(community, events_window)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::ChannelMatch;

#[ts_export(community, explore_channels)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub invite_code: Option<u64>,
Expand All @@ -10,6 +12,7 @@ pub struct Args {
pub page_size: u8,
}

#[ts_export(community, explore_channels)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(SuccessResult),
Expand All @@ -19,6 +22,7 @@ pub enum Response {
PrivateCommunity,
}

#[ts_export(community, explore_channels)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub matches: Vec<ChannelMatch>,
Expand Down
3 changes: 3 additions & 0 deletions backend/canisters/community/api/src/queries/invite_code.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::Empty;

pub type Args = Empty;

#[ts_export(community, invite_code)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(SuccessResult),
UserNotInCommunity,
NotAuthorized,
}

#[ts_export(community, invite_code)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub code: Option<u64>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{CanisterId, Empty};

pub type Args = Empty;

#[ts_export(community, local_user_index)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(CanisterId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, MessageIndex, MessagesResponse, TimestampMillis};

#[ts_export(community, messages_by_message_index)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
Expand All @@ -10,6 +12,7 @@ pub struct Args {
pub latest_known_update: Option<TimestampMillis>,
}

#[ts_export(community, messages_by_message_index)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(MessagesResponse),
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/community/api/src/queries/search_channel.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, MessageMatch, UserId};

#[ts_export(community, search_channel)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
Expand All @@ -10,6 +12,7 @@ pub struct Args {
pub users: Option<Vec<UserId>>,
}

#[ts_export(community, search_channel)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(SuccessResult),
Expand All @@ -22,6 +25,7 @@ pub enum Response {
UserNotInChannel,
}

#[ts_export(community, search_channel)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub matches: Vec<MessageMatch>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, EventIndex, GroupMember, MessageIndex, TimestampMillis, UserId, VersionedRules};

#[ts_export(community, selected_channel_initial)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
}

#[ts_export(community, selected_channel_initial)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(SuccessResult),
Expand All @@ -15,6 +18,7 @@ pub enum Response {
PrivateChannel,
}

#[ts_export(community, selected_channel_initial)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub timestamp: TimestampMillis,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, SelectedGroupUpdates, TimestampMillis};

#[ts_export(community, selected_channel_updates)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
pub updates_since: TimestampMillis,
}

#[ts_export(community, selected_channel_updates)]
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{CommunityMember, EventIndex, TimestampMillis, UserGroupDetails, UserId, VersionedRules};

#[ts_export(community, selected_initial)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub invite_code: Option<u64>,
}

#[ts_export(community, selected_initial)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(SuccessResult),
PrivateCommunity,
}

#[ts_export(community, selected_initial)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub timestamp: TimestampMillis,
Expand Down
15 changes: 4 additions & 11 deletions backend/canisters/community/api/src/queries/selected_updates_v2.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{CommunityMember, TimestampMillis, UserGroupDetails, UserId, VersionedRules};

#[ts_export(community, selected_updates)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub invite_code: Option<u64>,
pub updates_since: TimestampMillis,
}

#[ts_export(community, selected_updates)]
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Expand All @@ -16,6 +19,7 @@ pub enum Response {
PrivateCommunity,
}

#[ts_export(community, selected_updates)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub timestamp: TimestampMillis,
Expand All @@ -31,14 +35,3 @@ pub struct SuccessResult {
pub referrals_added: Vec<UserId>,
pub referrals_removed: Vec<UserId>,
}

impl SuccessResult {
pub fn has_updates(&self) -> bool {
!self.members_added_or_updated.is_empty()
|| !self.members_removed.is_empty()
|| !self.blocked_users_added.is_empty()
|| !self.blocked_users_removed.is_empty()
|| self.invited_users.is_some()
|| self.chat_rules.is_some()
}
}
3 changes: 3 additions & 0 deletions backend/canisters/community/api/src/queries/summary.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::CommunityCanisterCommunitySummary;

#[ts_export(community, summary)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub invite_code: Option<u64>,
}

#[ts_export(community, summary)]
// Allow the large size difference because essentially all responses are the large variant anyway
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{CommunityCanisterCommunitySummaryUpdates, TimestampMillis};

#[ts_export(community, summary_updates)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub invite_code: Option<u64>,
pub updates_since: TimestampMillis,
}

// Allow the large size difference because essentially all responses are the large variant anyway
#[ts_export(community, summary_updates)]
#[allow(clippy::large_enum_variant)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, MessageIndex, ThreadPreview, TimestampMillis};

#[ts_export(community, thread_previews)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
pub threads: Vec<MessageIndex>,
pub latest_client_thread_update: Option<TimestampMillis>,
}

#[ts_export(community, thread_previews)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(SuccessResult),
Expand All @@ -18,6 +21,7 @@ pub enum Response {
ReplicaNotUpToDate(TimestampMillis),
}

#[ts_export(community, thread_previews)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResult {
pub threads: Vec<ThreadPreview>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
use types::{ChannelId, MessageId, TimestampMillis, VideoCallParticipants};

#[ts_export(community, video_call_participants)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
pub message_id: MessageId,
pub updated_since: Option<TimestampMillis>,
}

#[ts_export(community, video_call_participants)]
#[derive(CandidType, Serialize, Deserialize, Debug)]
pub enum Response {
Success(VideoCallParticipants),
Expand Down
Loading

0 comments on commit b202cd6

Please sign in to comment.