Skip to content

Commit

Permalink
Merge branch 'master' into bot_name
Browse files Browse the repository at this point in the history
  • Loading branch information
julianjelfs authored Dec 12, 2024
2 parents d0ce776 + 83d9223 commit 6af31f0
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 353 deletions.
243 changes: 132 additions & 111 deletions Cargo.lock

Large diffs are not rendered by default.

31 changes: 13 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,35 +172,33 @@ aws-types = "1.1.5"
base64 = "0.22.1"
bitflags = { version = "2.4.1", features = ["serde"] }
candid = "0.10.10"
ciborium = "0.2.2"
clap = "4.5.4"
ct-codecs = "1.1.1"
data-encoding = "2.6.0"
dataurl = "0.1.2"
dirs = "5.0.1"
dotenv = "0.15.0"
event_store_canister = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.5.0" }
event_store_producer = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.5.0" }
event_store_producer_cdk_runtime = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.5.0" }
event_store_utils = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.5.0" }
event_store_canister = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.6.0" }
event_store_producer = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.6.0" }
event_store_producer_cdk_runtime = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.6.0" }
event_store_utils = { git = "https://github.com/open-chat-labs/event-store", rev = "v0.6.0" }
futures = "0.3.30"
getrandom = { version = "0.2.15", features = ["custom"] }
hex = "0.4.3"
hmac-sha256 = { version = "1.1.7", features = ["traits010"] }
ic-agent = "0.37.1"
ic-agent = "0.39.1"
ic-canister-sig-creation = "1.1.0"
ic-captcha = "1.0.0"
ic-cbor = "2.5.0"
ic-cdk = "0.16.0"
ic-cdk-macros = "0.16.0"
ic-cdk-timers = "0.10.0"
ic-cdk = "0.17.0"
ic-cdk-macros = "0.17.0"
ic-cdk-timers = "0.11.0"
ic-certificate-verification = "2.4.0"
ic-certification = "2.5.0"
ic-ledger-types = "0.13.0"
ic-ledger-types = "0.14.0"
ic_principal = "0.1.1"
ic-stable-structures = "0.6.7"
ic-transport-types = "0.37.1"
ic-utils = "0.37.0"
ic-transport-types = "0.39.1"
ic-utils = "0.39.0"
ic-verifiable-credentials = "1.0.1"
icrc-ledger-types = "0.1.5"
ic0 = "0.23.0"
Expand All @@ -220,12 +218,10 @@ pulldown-cmark = { version = "0.12.0", default-features = false, features = [
] }
quote = "1.0.36"
rand = "0.8.5"
rand_chacha = "0.3.1"
rand_core = "0.6.4"
range-set = "0.0.11"
regex-lite = "0.1.5"
rmp-serde = "1.3.0"
serde = "1.0.210"
serde = "1.0.216"
serde_bytes = "0.11.15"
serde_cbor = "0.11.2"
serde_json = "1.0.128"
Expand All @@ -241,7 +237,6 @@ test-strategy = "0.4.0"
time = "0.3.36"
tokio = "1.37.0"
tracing = "0.1.40"
tracing-attributes = "0.1.27"
tracing-subscriber = "0.3.18"
ts-rs = { version = "9.0.1", features = ["no-serde-warnings"] }
url = "2.5.2"
Expand All @@ -257,6 +252,6 @@ codegen-units = 1
debug = false

[patch.crates-io]
ic-cdk-macros = { git = "https://github.com/hpeebles/cdk-rs", rev = "f20bca1b4210b37effcb3c5d82adbb05c6647cbd" }
ic-cdk-macros = { git = "https://github.com/hpeebles/cdk-rs", rev = "19f04d7d996d77b1c2f938e4c7e1efd8e3f12910" }
rmp-serde = { git = "https://github.com/hpeebles/msgpack-rust", rev = "832a3f48e67eea56c869715ae6e1045583dd011b" }
ts-rs = { git = "https://github.com/hpeebles/ts-rs", rev = "c8f7385697df0764fca3b5d7b8e22b967fb16c10" }
2 changes: 1 addition & 1 deletion backend/canisters/community/impl/src/model/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum CommunityEventInternal {
UsersInvited(Box<UsersInvited>),
#[serde(rename = "mr", alias = "MembersRemoved")]
MembersRemoved(Box<CommunityMembersRemoved>),
#[serde(rename = "rc", alias = "RoleChanged")]
#[serde(rename = "rl", alias = "RoleChanged")]
RoleChanged(Box<CommunityRoleChanged>),
#[serde(rename = "ub", alias = "UsersBlocked")]
UsersBlocked(Box<CommunityUsersBlocked>),
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Notify CHIT updates via LocalUserIndex ([#7033](https://github.com/open-chat-labs/open-chat/pull/7033))
- Use `GroupedTimerJobQueue` to push user config to StorageIndex ([#7034](https://github.com/open-chat-labs/open-chat/pull/7034))

### Removed

- Remove some unused code ([#7050](https://github.com/open-chat-labs/open-chat/pull/7050))

### Fixed

- Fix to allow `register_bot` to be called in test mode ([#7015](https://github.com/open-chat-labs/open-chat/pull/7015))
Expand Down
18 changes: 0 additions & 18 deletions backend/canisters/user_index/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,6 @@ type ChitUserBalance = record {
balance : nat32;
};

type AddReferralCodesArgs = record {
referral_type : ReferralType;
codes : vec text;
expiry : opt TimestampMillis;
};

type ReferralType = variant {
BtcMiami;
User;
};

type AddReferralCodesResponse = variant {
Success;
};

type AwardExternalAchievementArgs = record {
achievement_id : nat32;
user_id : UserId;
Expand Down Expand Up @@ -314,9 +299,6 @@ service : {
register_bot : (RegisterBotArgs) -> (RegisterBotResponse);
register_external_achievement : (RegisterExternalAchievementArgs) -> (RegisterExternalAchievementResponse);

// Only callable by OC dev team dfx identity
add_referral_codes : (AddReferralCodesArgs) -> (AddReferralCodesResponse);

// Only callable by whitelisted canisters
award_external_achievement : (AwardExternalAchievementArgs) -> (AwardExternalAchievementResponse);
};
1 change: 0 additions & 1 deletion backend/canisters/user_index/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub enum LocalUserIndexEvent {
UserRegistered(Box<UserRegistered>),
UserJoinedGroup(Box<UserJoinedGroup>),
UserJoinedCommunityOrChannel(Box<UserJoinedCommunityOrChannel>),
JoinUserToGroup(Box<JoinUserToGroup>),
OpenChatBotMessage(Box<OpenChatBotMessage>),
OpenChatBotMessageV2(Box<OpenChatBotMessageV2>),
UserDeleted(Box<UserDeleted>),
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/user_index/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ fn main() {
generate_candid_method!(user_index, users, query);
generate_candid_method!(user_index, users_chit, query);

generate_candid_method!(user_index, add_referral_codes, update);
generate_candid_method!(user_index, award_external_achievement, update);
generate_candid_method!(user_index, register_external_achievement, update);
generate_candid_method!(user_index, register_bot, update);
Expand Down
15 changes: 0 additions & 15 deletions backend/canisters/user_index/api/src/updates/add_referral_codes.rs

This file was deleted.

1 change: 0 additions & 1 deletion backend/canisters/user_index/api/src/updates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod add_local_user_index_canister;
pub mod add_platform_moderator;
pub mod add_platform_operator;
pub mod add_referral_codes;
pub mod assign_platform_moderators_group;
pub mod award_external_achievement;
pub mod c2c_mark_user_canister_empty;
Expand Down
8 changes: 0 additions & 8 deletions backend/canisters/user_index/impl/src/guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ pub fn caller_is_governance_principal() -> Result<(), String> {
}
}

pub fn caller_is_dev_team_dfx_principal() -> Result<(), String> {
if read_state(|state| state.is_caller_dev_team_dfx_principal()) {
Ok(())
} else {
Err("Caller is not a governance principal".to_string())
}
}

pub fn caller_is_local_user_index_canister() -> Result<(), String> {
if read_state(|state| state.is_caller_local_user_index_canister()) {
Ok(())
Expand Down
7 changes: 1 addition & 6 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::timer_job_types::TimerJob;
use candid::Principal;
use canister_state_macros::canister_state;
use canister_timer_jobs::TimerJobs;
use constants::{DAY_IN_MS, DEV_TEAM_DFX_PRINCIPAL};
use constants::DAY_IN_MS;
use event_store_producer::{EventBuilder, EventStoreClient, EventStoreClientBuilder, EventStoreClientInfo};
use event_store_producer_cdk_runtime::CdkRuntime;
use fire_and_forget_handler::FireAndForgetHandler;
Expand Down Expand Up @@ -117,11 +117,6 @@ impl RuntimeState {
}
}

pub fn is_caller_dev_team_dfx_principal(&self) -> bool {
let caller = self.env.caller();
caller == DEV_TEAM_DFX_PRINCIPAL
}

pub fn is_caller_modclub(&self) -> bool {
let caller = self.env.caller();
caller == self.modclub_canister_id()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fn accept_if_valid(state: &RuntimeState) {
let is_user = state.data.users.get_by_principal(&caller).is_some();
is_user
}
"add_referral_codes" => state.is_caller_dev_team_dfx_principal(),
"suspend_user" | "unsuspend_user" => state.is_caller_platform_moderator(),
"set_user_upgrade_concurrency" | "set_diamond_membership_fees" => state.is_caller_platform_operator(),
"upload_wasm_chunk" => state.can_caller_upload_wasm_chunks(),
Expand Down
70 changes: 1 addition & 69 deletions backend/canisters/user_index/impl/src/timer_job_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{mutate_state, read_state};
use canister_timer_jobs::Job;
use constants::{MINUTE_IN_MS, SECOND_IN_MS};
use ic_ledger_types::Tokens;
use local_user_index_canister::{OpenChatBotMessage, UserIndexEvent, UserJoinedGroup};
use local_user_index_canister::{OpenChatBotMessage, UserIndexEvent};
use serde::{Deserialize, Serialize};
use types::{
ChatId, CommunityId, Cryptocurrency, DiamondMembershipFees, DiamondMembershipPlanDuration, MessageContent, Milliseconds,
Expand All @@ -19,7 +19,6 @@ pub enum TimerJob {
SetUserSuspendedInGroup(SetUserSuspendedInGroup),
SetUserSuspendedInCommunity(SetUserSuspendedInCommunity),
UnsuspendUser(UnsuspendUser),
JoinUserToGroup(JoinUserToGroup),
}

#[derive(Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -71,7 +70,6 @@ impl Job for TimerJob {
TimerJob::SetUserSuspendedInGroup(job) => job.execute(),
TimerJob::SetUserSuspendedInCommunity(job) => job.execute(),
TimerJob::UnsuspendUser(job) => job.execute(),
TimerJob::JoinUserToGroup(job) => job.execute(),
}
}
}
Expand Down Expand Up @@ -247,69 +245,3 @@ impl Job for UnsuspendUser {
}
}
}

impl Job for JoinUserToGroup {
fn execute(self) {
if let Some(args) = read_state(|state| {
#[allow(deprecated)]
state
.data
.users
.get_by_user_id(&self.user_id)
.map(|u| group_canister::c2c_join_group::Args {
user_id: self.user_id,
principal: u.principal,
invite_code: None,
correlation_id: 0,
is_platform_moderator: state.data.platform_moderators.contains(&self.user_id),
is_bot: u.user_type.is_bot(),
user_type: u.user_type,
diamond_membership_expires_at: state
.data
.users
.get_by_user_id(&self.user_id)
.and_then(|u| u.diamond_membership_details.expires_at()),
verified_credential_args: None,
unique_person_proof: None,
})
}) {
ic_cdk::spawn(join_group(self.group_id, args, self.attempt));
}

async fn join_group(group_id: ChatId, args: group_canister::c2c_join_group::Args, attempt: usize) {
use group_canister::c2c_join_group::*;

match group_canister_c2c_client::c2c_join_group(group_id.into(), &args).await {
Ok(Response::Success(s) | Response::AlreadyInGroupV2(s)) => mutate_state(|state| {
state.push_event_to_local_user_index(
args.user_id,
UserIndexEvent::UserJoinedGroup(UserJoinedGroup {
user_id: args.user_id,
chat_id: group_id,
local_user_index_canister_id: s.local_user_index_canister_id,
latest_message_index: s.latest_message.map(|m| m.event.message_index),
group_canister_timestamp: s.last_updated,
}),
)
}),
Ok(Response::InternalError(_)) | Err(_) => {
if attempt < 50 {
mutate_state(|state| {
let now = state.env.now();
state.data.timer_jobs.enqueue_job(
TimerJob::JoinUserToGroup(JoinUserToGroup {
user_id: args.user_id,
group_id,
attempt: attempt + 1,
}),
now + 10 * SECOND_IN_MS,
now,
);
})
}
}
_ => {}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::guards::caller_is_governance_principal;
use crate::timer_job_types::{JoinUserToGroup, TimerJob};
use crate::{mutate_state, read_state, RuntimeState};
use canister_api_macros::proposal;
use canister_tracing_macros::trace;
Expand Down Expand Up @@ -38,17 +37,4 @@ fn commit(user_id: UserId, state: &mut RuntimeState) {
}),
None,
);

if let Some(group_id) = state.data.platform_moderators_group {
let now = state.env.now();
state.data.timer_jobs.enqueue_job(
TimerJob::JoinUserToGroup(JoinUserToGroup {
user_id,
group_id,
attempt: 0,
}),
now,
now,
);
}
}

This file was deleted.

12 changes: 0 additions & 12 deletions backend/canisters/user_index/impl/src/updates/c2c_notify_events.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::guards::caller_is_local_user_index_canister;
use crate::timer_job_types::{JoinUserToGroup, TimerJob};
use crate::{mutate_state, RuntimeState, UserRegisteredEventPayload, ONE_MB};
use candid::Principal;
use canister_api_macros::update;
Expand Down Expand Up @@ -59,17 +58,6 @@ fn handle_event(event: LocalUserIndexEvent, caller: Principal, now: TimestampMil
}),
);
}
LocalUserIndexEvent::JoinUserToGroup(ev) => {
state.data.timer_jobs.enqueue_job(
TimerJob::JoinUserToGroup(JoinUserToGroup {
user_id: ev.user_id,
group_id: ev.chat_id,
attempt: 0,
}),
now,
now,
);
}
LocalUserIndexEvent::OpenChatBotMessage(ev) => {
state.push_event_to_local_user_index(
ev.user_id,
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/user_index/impl/src/updates/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod add_local_user_index_canister;
pub mod add_platform_moderator;
pub mod add_platform_operator;
pub mod add_referral_codes;
pub mod assign_platform_moderators_group;
pub mod award_external_achievement;
pub mod c2c_mark_user_canister_empty;
Expand Down
Loading

0 comments on commit 6af31f0

Please sign in to comment.