Skip to content

Commit

Permalink
Send MessageContentInternal c2c rather than MessageContentInitial (#4895
Browse files Browse the repository at this point in the history
)
  • Loading branch information
hpeebles authored Nov 30, 2023
1 parent 10ff54c commit b51cc3a
Show file tree
Hide file tree
Showing 23 changed files with 631 additions and 335 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.

23 changes: 12 additions & 11 deletions backend/bots/examples/group_prize_bot/impl/src/jobs/send_prizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,20 @@ async fn send_prize_message_to_group(
correlation_id: 0,
};

use group_canister::send_message_v2::Response;
match group_canister_c2c_client::send_message_v2(group, &c2c_args).await {
Ok(response) => match response {
group_canister::send_message_v2::Response::Success(_) => Ok(()),
group_canister::send_message_v2::Response::CallerNotInGroup => Err("Bot not in group".to_string()),
group_canister::send_message_v2::Response::UserSuspended => Err("Bot suspended".to_string()),
group_canister::send_message_v2::Response::ChatFrozen => Err("Group frozen".to_string()),
group_canister::send_message_v2::Response::MessageEmpty
| group_canister::send_message_v2::Response::RulesNotAccepted
| group_canister::send_message_v2::Response::InvalidPoll(_)
| group_canister::send_message_v2::Response::NotAuthorized
| group_canister::send_message_v2::Response::ThreadMessageNotFound
| group_canister::send_message_v2::Response::InvalidRequest(_)
| group_canister::send_message_v2::Response::TextTooLong(_) => unreachable!(),
Response::Success(_) => Ok(()),
Response::CallerNotInGroup => Err("Bot not in group".to_string()),
Response::UserSuspended => Err("Bot suspended".to_string()),
Response::ChatFrozen => Err("Group frozen".to_string()),
Response::MessageEmpty
| Response::RulesNotAccepted
| Response::InvalidPoll(_)
| Response::NotAuthorized
| Response::ThreadMessageNotFound
| Response::InvalidRequest(_)
| Response::TextTooLong(_) => unreachable!(),
},
// TODO: We should retry sending the message
Err(error) => Err(format!("{error:?}")),
Expand Down
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 `c2c_send_message` with improved API for c2c calls vs `send_message` ([#4895](https://github.com/open-chat-labs/open-chat/pull/4895))

### Changed

- Burn any CHAT going to the treasury ([#4891](https://github.com/open-chat-labs/open-chat/pull/4891))
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/community/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ edition = "2021"
[dependencies]
candid = { workspace = true }
candid_gen = { path = "../../../libraries/candid_gen" }
chat_events = { path = "../../../libraries/chat_events" }
serde = { workspace = true }
types = { path = "../../../libraries/types" }
20 changes: 20 additions & 0 deletions backend/canisters/community/api/src/updates/c2c_send_message.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use chat_events::MessageContentInternal;
use serde::{Deserialize, Serialize};
use types::{ChannelId, GroupReplyContext, MessageId, MessageIndex, User, Version};

#[derive(Serialize, Deserialize, Debug)]
pub struct Args {
pub channel_id: ChannelId,
pub thread_root_message_index: Option<MessageIndex>,
pub message_id: MessageId,
pub content: MessageContentInternal,
pub sender_name: String,
pub sender_display_name: Option<String>,
pub replies_to: Option<GroupReplyContext>,
pub mentioned: Vec<User>,
pub forwarding: bool,
pub community_rules_accepted: Option<Version>,
pub channel_rules_accepted: Option<Version>,
}

pub type Response = crate::send_message::Response;
1 change: 1 addition & 0 deletions backend/canisters/community/api/src/updates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod c2c_invite_users_to_channel;
pub mod c2c_join_channel;
pub mod c2c_join_community;
pub mod c2c_leave_community;
pub mod c2c_send_message;
pub mod c2c_set_user_suspended;
pub mod c2c_tip_message;
pub mod c2c_unfreeze_community;
Expand Down
5 changes: 3 additions & 2 deletions backend/canisters/community/c2c_client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use canister_client::generate_c2c_call;
use canister_client::{generate_c2c_call, generate_candid_c2c_call};
use community_canister::*;

// Queries
Expand All @@ -16,11 +16,12 @@ generate_c2c_call!(c2c_invite_users_to_channel);
generate_c2c_call!(c2c_join_channel);
generate_c2c_call!(c2c_join_community);
generate_c2c_call!(c2c_leave_community);
generate_c2c_call!(c2c_send_message);
generate_c2c_call!(c2c_set_user_suspended);
generate_c2c_call!(c2c_tip_message);
generate_c2c_call!(c2c_unfreeze_community);
generate_c2c_call!(c2c_update_proposals);
generate_c2c_call!(change_channel_role);
generate_c2c_call!(delete_channel);
generate_c2c_call!(delete_messages);
generate_c2c_call!(send_message);
generate_candid_c2c_call!(send_message);
9 changes: 0 additions & 9 deletions backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,6 @@ impl Data {
self.cached_chat_metrics = Timestamped::new(metrics.hydrate(), now);
}

pub fn check_rules(&self, member: &CommunityMemberInternal) -> bool {
!self.rules.enabled
|| member.is_bot
|| (member
.rules_accepted
.as_ref()
.map_or(false, |accepted| accepted.value >= self.rules.text.version))
}

pub fn record_instructions_count(&self, function_id: InstructionCountFunctionId, now: TimestampMillis) {
let wasm_version = WASM_VERSION.with_borrow(|v| **v);
let instructions_count = ic_cdk::api::instruction_counter();
Expand Down
Loading

0 comments on commit b51cc3a

Please sign in to comment.