From 37a5b5da64a91045c2372970395d0d273f3c9714 Mon Sep 17 00:00:00 2001 From: megrogan Date: Fri, 15 Nov 2024 15:02:28 +0000 Subject: [PATCH] Add new prize message criteria on backend --- .../group_prize_bot/impl/src/jobs/send_prizes.rs | 3 +++ backend/canisters/community/CHANGELOG.md | 4 ++++ backend/canisters/group/CHANGELOG.md | 4 ++++ backend/canisters/user/CHANGELOG.md | 4 ++++ .../src/communities/import_group_tests.rs | 3 +++ .../src/communities/send_message_tests.rs | 3 +++ .../integration_tests/src/prize_message_tests.rs | 9 +++++++++ .../chat_events/src/message_content_internal.rs | 15 +++++++++++++++ .../chat_events/src/stable_storage/tests.rs | 3 +++ backend/libraries/types/can.did | 6 ++++++ backend/libraries/types/src/message.rs | 3 +++ backend/libraries/types/src/message_content.rs | 9 +++++++++ 12 files changed, 66 insertions(+) diff --git a/backend/bots/examples/group_prize_bot/impl/src/jobs/send_prizes.rs b/backend/bots/examples/group_prize_bot/impl/src/jobs/send_prizes.rs index 14bb5f1225..57de69ba78 100644 --- a/backend/bots/examples/group_prize_bot/impl/src/jobs/send_prizes.rs +++ b/backend/bots/examples/group_prize_bot/impl/src/jobs/send_prizes.rs @@ -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 { diff --git a/backend/canisters/community/CHANGELOG.md b/backend/canisters/community/CHANGELOG.md index af0a0989e0..c58819dd82 100644 --- a/backend/canisters/community/CHANGELOG.md +++ b/backend/canisters/community/CHANGELOG.md @@ -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 - Store events in `HybridMap` which caches latest events on the heap ([#6762](https://github.com/open-chat-labs/open-chat/pull/6762)) diff --git a/backend/canisters/group/CHANGELOG.md b/backend/canisters/group/CHANGELOG.md index 219da0f983..cce9a95a00 100644 --- a/backend/canisters/group/CHANGELOG.md +++ b/backend/canisters/group/CHANGELOG.md @@ -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 - Store events in `HybridMap` which caches latest events on the heap ([#6762](https://github.com/open-chat-labs/open-chat/pull/6762)) diff --git a/backend/canisters/user/CHANGELOG.md b/backend/canisters/user/CHANGELOG.md index 176fe4514b..08506b7744 100644 --- a/backend/canisters/user/CHANGELOG.md +++ b/backend/canisters/user/CHANGELOG.md @@ -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)) diff --git a/backend/integration_tests/src/communities/import_group_tests.rs b/backend/integration_tests/src/communities/import_group_tests.rs index fbf96c39a3..56a6cc9784 100644 --- a/backend/integration_tests/src/communities/import_group_tests.rs +++ b/backend/integration_tests/src/communities/import_group_tests.rs @@ -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, diff --git a/backend/integration_tests/src/communities/send_message_tests.rs b/backend/integration_tests/src/communities/send_message_tests.rs index c09860fba6..7668ec51c8 100644 --- a/backend/integration_tests/src/communities/send_message_tests.rs +++ b/backend/integration_tests/src/communities/send_message_tests.rs @@ -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, diff --git a/backend/integration_tests/src/prize_message_tests.rs b/backend/integration_tests/src/prize_message_tests.rs index a68079e52b..dabfdd7325 100644 --- a/backend/integration_tests/src/prize_message_tests.rs +++ b/backend/integration_tests/src/prize_message_tests.rs @@ -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, @@ -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, @@ -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, diff --git a/backend/libraries/chat_events/src/message_content_internal.rs b/backend/libraries/chat_events/src/message_content_internal.rs index cc9b8fd2c4..805e07f50e 100644 --- a/backend/libraries/chat_events/src/message_content_internal.rs +++ b/backend/libraries/chat_events/src/message_content_internal.rs @@ -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(), @@ -1194,6 +1197,12 @@ pub struct PrizeContentInternal { pub caption: Option, #[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")] @@ -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, } @@ -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, } } } diff --git a/backend/libraries/chat_events/src/stable_storage/tests.rs b/backend/libraries/chat_events/src/stable_storage/tests.rs index c1961a7809..bccabd333d 100644 --- a/backend/libraries/chat_events/src/stable_storage/tests.rs +++ b/backend/libraries/chat_events/src/stable_storage/tests.rs @@ -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, }); diff --git a/backend/libraries/types/can.did b/backend/libraries/types/can.did index e801073979..8a2cff1f8f 100644 --- a/backend/libraries/types/can.did +++ b/backend/libraries/types/can.did @@ -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 { @@ -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 { diff --git a/backend/libraries/types/src/message.rs b/backend/libraries/types/src/message.rs index 080075a7dc..0dffbbc778 100644 --- a/backend/libraries/types/src/message.rs +++ b/backend/libraries/types/src/message.rs @@ -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)] diff --git a/backend/libraries/types/src/message_content.rs b/backend/libraries/types/src/message_content.rs index 8e2b7e9d91..3ee2c671c9 100644 --- a/backend/libraries/types/src/message_content.rs +++ b/backend/libraries/types/src/message_content.rs @@ -400,6 +400,9 @@ impl From 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), @@ -613,6 +616,9 @@ pub struct PrizeContentInitial { pub end_date: TimestampMillis, pub caption: Option, pub diamond_only: bool, + pub lifetime_diamond_only: bool, + pub unique_person_only: bool, + pub streak_only: u16, } #[ts_export] @@ -627,6 +633,9 @@ pub struct PrizeContent { pub end_date: TimestampMillis, pub caption: Option, pub diamond_only: bool, + pub lifetime_diamond_only: bool, + pub unique_person_only: bool, + pub streak_only: u16, } #[ts_export]