Skip to content

Commit

Permalink
Merge branch 'master' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Nov 15, 2024
2 parents a8be5ca + ee82796 commit 0634c76
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ async fn send_prize_message_to_group(
end_date,
caption: None,
diamond_only: false,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
});

let c2c_args = group_canister::send_message_v2::Args {
Expand Down
5 changes: 5 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Add new prize message criteria ([#6831](https://github.com/open-chat-labs/open-chat/pull/6831))

### Changed

- Store events in `HybridMap` which caches latest events on the heap ([#6762](https://github.com/open-chat-labs/open-chat/pull/6762))
- Reduce size of metrics in memory ([#6765](https://github.com/open-chat-labs/open-chat/pull/6765))
- Run cycles check (+ other background tasks) when executing timer jobs ([#6815](https://github.com/open-chat-labs/open-chat/pull/6815))
- Add cycles balance check to more timer jobs ([#6822](https://github.com/open-chat-labs/open-chat/pull/6822))
- Add the `BotCommand` access token type ([#6830](https://github.com/open-chat-labs/open-chat/pull/6830))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn c2c_can_issue_access_token_for_channel_impl(args: Args, state: &RuntimeState)
AccessTokenType::StartVideoCallV2(vc) => {
can_start_video_call(member, state.data.is_public, vc.call_type, &channel.chat)
}
AccessTokenType::JoinVideoCall | AccessTokenType::MarkVideoCallAsEnded => true,
AccessTokenType::JoinVideoCall | AccessTokenType::MarkVideoCallAsEnded | AccessTokenType::BotCommand(_) => true,
}
}

Expand Down
5 changes: 5 additions & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Add new prize message criteria ([#6831](https://github.com/open-chat-labs/open-chat/pull/6831))

### Changed

- Add cycles balance check to more timer jobs ([#6822](https://github.com/open-chat-labs/open-chat/pull/6822))
- Add the `BotCommand` access token type ([#6830](https://github.com/open-chat-labs/open-chat/pull/6830))

## [[2.0.1453](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1453-group)] - 2024-11-14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn c2c_can_issue_access_token_impl(args: Args, state: &RuntimeState) -> bool {

match args.access_type {
AccessTokenType::StartVideoCallV2(vc) => can_start_video_call(member, vc.call_type, &state.data.chat),
AccessTokenType::JoinVideoCall | AccessTokenType::MarkVideoCallAsEnded => true,
AccessTokenType::JoinVideoCall | AccessTokenType::MarkVideoCallAsEnded | AccessTokenType::BotCommand(_) => true,
}
}

Expand Down
6 changes: 5 additions & 1 deletion backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Add `BotApiCanister` to the canister state ([#6828](https://github.com/open-chat-labs/open-chat/pull/6828))
- Add the `BotCommand` access token type ([#6830](https://github.com/open-chat-labs/open-chat/pull/6830))

## [[2.0.1454](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1454-local_user_index)] - 2024-11-14

### Changed

- Top up canisters which have fewer than `MIN_CYCLES_BALANCE` cycles ([#6819](https://github.com/open-chat-labs/open-chat/pull/6819))
- Reduce top up amount to 0.02T ([#6821](https://github.com/open-chat-labs/open-chat/pull/6821))
- Add `BotApiCanister` to the canister state ([#6828](https://github.com/open-chat-labs/open-chat/pull/6828))

## [[2.0.1447](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1447-local_user_index)] - 2024-11-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use local_user_index_canister::access_token::{Response::*, *};
use rand::rngs::StdRng;
use rand::SeedableRng;
use serde::Serialize;
use types::{AccessTokenType, ChannelId, Chat, ChatId, CommunityId, JoinOrEndVideoCallClaims, StartVideoCallClaims, UserId};
use types::{
AccessTokenType, BotCommandClaims, ChannelId, Chat, ChatId, CommunityId, JoinOrEndVideoCallClaims, StartVideoCallClaims,
UserId,
};

#[query(composite = true, guard = "caller_is_openchat_user", candid = true, msgpack = true)]
#[trace]
Expand Down Expand Up @@ -53,6 +56,18 @@ async fn access_token(args: Args) -> Response {
};
build_token(args.token_type, custom_claims, state)
}
AccessTokenType::BotCommand(bc) => {
let bot_api_gateway = state.data.internet_identity_canister_id;
let custom_claims = BotCommandClaims {
user_id: bc.user_id,
bot: bc.bot,
thread_root_message_index: bc.thread_root_message_index,
message_id: bc.message_id,
bot_api_gateway,
reply_url: format!("https://{bot_api_gateway}.icp0.io/call"),
};
build_token(args.token_type, custom_claims, state)
}
})
}

Expand Down
5 changes: 5 additions & 0 deletions backend/canisters/user/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Added

- Add new prize message criteria ([#6831](https://github.com/open-chat-labs/open-chat/pull/6831))

### Changed

- Avoid extra key lookup when iterating over events ([#6680](https://github.com/open-chat-labs/open-chat/pull/6680))
Expand All @@ -17,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Run cycles check (+ other background tasks) when executing timer jobs ([#6815](https://github.com/open-chat-labs/open-chat/pull/6815))
- Add cycles balance check to more timer jobs ([#6822](https://github.com/open-chat-labs/open-chat/pull/6822))
- Avoid iterating all events when migrating private replies after group import ([#6827](https://github.com/open-chat-labs/open-chat/pull/6827))
- Add the `BotCommand` access token type ([#6830](https://github.com/open-chat-labs/open-chat/pull/6830))

### Removed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fn c2c_can_issue_access_token_impl(args: Args, state: &RuntimeState) -> bool {
}

match args.access_type {
AccessTokenType::StartVideoCallV2(_) | AccessTokenType::JoinVideoCall | AccessTokenType::MarkVideoCallAsEnded => true,
AccessTokenType::StartVideoCallV2(_)
| AccessTokenType::JoinVideoCall
| AccessTokenType::MarkVideoCallAsEnded
| AccessTokenType::BotCommand(_) => true,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ fn pending_prizes_transferred_to_community() {
end_date: now_millis(env) + HOUR_IN_MS,
caption: None,
diamond_only: false,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
}),
sender_name: user1.username(),
sender_display_name: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ fn send_prize_in_channel() {
prizes_v2: prizes,
end_date: now_millis(env) + 1000,
diamond_only: false,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
}),
sender_name: user1.username(),
sender_display_name: None,
Expand Down
9 changes: 9 additions & 0 deletions backend/integration_tests/src/prize_message_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ fn prize_messages_can_be_claimed_successfully() {
end_date: now_millis(env) + HOUR_IN_MS,
caption: None,
diamond_only: false,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
}),
sender_name: user1.username(),
sender_display_name: None,
Expand Down Expand Up @@ -163,6 +166,9 @@ fn unclaimed_prizes_get_refunded(case: u32) {
end_date: now_millis(env) + HOUR_IN_MS,
caption: None,
diamond_only: false,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
}),
sender_name: user1.username(),
sender_display_name: None,
Expand Down Expand Up @@ -246,6 +252,9 @@ fn old_transactions_fixed_by_updating_created_date() {
end_date: now_millis(env) + HOUR_IN_MS,
caption: None,
diamond_only: false,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
}),
sender_name: user.username(),
sender_display_name: None,
Expand Down
15 changes: 15 additions & 0 deletions backend/libraries/chat_events/src/message_content_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ impl MessageContentInternal {
token: c.transaction.token().token_symbol().to_string(),
amount: c.transaction.units(),
diamond_only: c.diamond_only,
lifetime_diamond_only: c.lifetime_diamond_only,
unique_person_only: c.unique_person_only,
streak_only: c.streak_only,
}),
MessageContentInternal::PrizeWinner(c) => MessageContentEventPayload::PrizeWinner(PrizeWinnerContentEventPayload {
token: c.token_symbol.clone(),
Expand Down Expand Up @@ -1194,6 +1197,12 @@ pub struct PrizeContentInternal {
pub caption: Option<String>,
#[serde(rename = "d", default, skip_serializing_if = "is_default")]
pub diamond_only: bool,
#[serde(rename = "g", default, skip_serializing_if = "is_default")]
pub lifetime_diamond_only: bool,
#[serde(rename = "u", default, skip_serializing_if = "is_default")]
pub unique_person_only: bool,
#[serde(rename = "s", default, skip_serializing_if = "is_default")]
pub streak_only: u16,
#[serde(rename = "f", default, skip_serializing_if = "is_default")]
pub refund_started: bool,
#[serde(rename = "l", default, skip_serializing_if = "is_default")]
Expand All @@ -1210,6 +1219,9 @@ impl PrizeContentInternal {
end_date: content.end_date,
caption: content.caption,
diamond_only: content.diamond_only,
lifetime_diamond_only: content.lifetime_diamond_only,
unique_person_only: content.unique_person_only,
streak_only: content.streak_only,
refund_started: false,
ledger_error: false,
}
Expand Down Expand Up @@ -1252,6 +1264,9 @@ impl MessageContentInternalSubtype for PrizeContentInternal {
end_date: self.end_date,
caption: self.caption,
diamond_only: self.diamond_only,
lifetime_diamond_only: self.lifetime_diamond_only,
unique_person_only: self.unique_person_only,
streak_only: self.streak_only,
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions backend/libraries/chat_events/src/stable_storage/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ fn prize_content() {
end_date: random(),
caption: Some(random_string()),
diamond_only: true,
lifetime_diamond_only: false,
unique_person_only: false,
streak_only: 0,
refund_started: true,
ledger_error: true,
});
Expand Down
6 changes: 6 additions & 0 deletions backend/libraries/types/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,9 @@ type PrizeContentInitial = record {
end_date : TimestampMillis;
caption : opt text;
diamond_only : bool;
lifetime_diamond_only : bool;
unique_person_only : bool;
streak_only: nat16;
};

type PrizeContent = record {
Expand All @@ -1501,6 +1504,9 @@ type PrizeContent = record {
end_date : TimestampMillis;
caption : opt text;
diamond_only : bool;
lifetime_diamond_only : bool;
unique_person_only : bool;
streak_only: nat16;
};

type PrizeWinnerContent = record {
Expand Down
13 changes: 12 additions & 1 deletion backend/libraries/types/src/access_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::VideoCallType;
use crate::{MessageId, MessageIndex, UserId, VideoCallType};
use candid::CandidType;
use serde::{Deserialize, Serialize};
use ts_export::ts_export;
Expand All @@ -9,6 +9,7 @@ pub enum AccessTokenType {
StartVideoCallV2(VideoCallAccessTokenArgs),
JoinVideoCall,
MarkVideoCallAsEnded,
BotCommand(BotCommandArgs),
}

#[ts_export]
Expand All @@ -17,12 +18,22 @@ pub struct VideoCallAccessTokenArgs {
pub call_type: VideoCallType,
}

#[ts_export]
#[derive(CandidType, Serialize, Deserialize, Debug, Clone)]
pub struct BotCommandArgs {
pub user_id: UserId,
pub bot: UserId,
pub thread_root_message_index: Option<MessageIndex>,
pub message_id: MessageId,
}

impl AccessTokenType {
pub fn type_name(&self) -> &str {
match self {
AccessTokenType::StartVideoCallV2(_) => "StartVideoCall",
AccessTokenType::JoinVideoCall => "JoinVideoCall",
AccessTokenType::MarkVideoCallAsEnded => "MarkVideoCallAsEnded",
AccessTokenType::BotCommand(_) => "BotCommand",
}
}
}
12 changes: 11 additions & 1 deletion backend/libraries/types/src/claims.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Chat, UserId, VideoCallType};
use crate::{CanisterId, Chat, MessageId, MessageIndex, UserId, VideoCallType};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone)]
Expand Down Expand Up @@ -31,3 +31,13 @@ pub struct StartVideoCallClaims {
pub call_type: VideoCallType,
pub is_diamond: bool,
}

#[derive(Serialize, Deserialize)]
pub struct BotCommandClaims {
pub user_id: UserId,
pub bot: UserId,
pub thread_root_message_index: Option<MessageIndex>,
pub message_id: MessageId,
pub bot_api_gateway: CanisterId,
pub reply_url: String,
}
3 changes: 3 additions & 0 deletions backend/libraries/types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ pub struct PrizeContentEventPayload {
pub token: String,
pub amount: u128,
pub diamond_only: bool,
pub lifetime_diamond_only: bool,
pub unique_person_only: bool,
pub streak_only: u16,
}

#[derive(Serialize)]
Expand Down
9 changes: 9 additions & 0 deletions backend/libraries/types/src/message_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,9 @@ impl From<MessageContentInitial> for MessageContent {
caption: c.caption,
prizes_pending: 0,
diamond_only: c.diamond_only,
lifetime_diamond_only: c.lifetime_diamond_only,
unique_person_only: c.unique_person_only,
streak_only: c.streak_only,
}),
MessageContentInitial::MessageReminderCreated(r) => MessageContent::MessageReminderCreated(r),
MessageContentInitial::MessageReminder(r) => MessageContent::MessageReminder(r),
Expand Down Expand Up @@ -613,6 +616,9 @@ pub struct PrizeContentInitial {
pub end_date: TimestampMillis,
pub caption: Option<String>,
pub diamond_only: bool,
pub lifetime_diamond_only: bool,
pub unique_person_only: bool,
pub streak_only: u16,
}

#[ts_export]
Expand All @@ -627,6 +633,9 @@ pub struct PrizeContent {
pub end_date: TimestampMillis,
pub caption: Option<String>,
pub diamond_only: bool,
pub lifetime_diamond_only: bool,
pub unique_person_only: bool,
pub streak_only: u16,
}

#[ts_export]
Expand Down
Loading

0 comments on commit 0634c76

Please sign in to comment.