Skip to content

Commit

Permalink
Add new prize message criteria on backend
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan committed Nov 15, 2024
1 parent 9e3d14f commit 37a5b5d
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 0 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
4 changes: 4 additions & 0 deletions backend/canisters/community/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

- Store events in `HybridMap` which caches latest events on the heap ([#6762](https://github.com/open-chat-labs/open-chat/pull/6762))
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/group/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

- Store events in `HybridMap` which caches latest events on the heap ([#6762](https://github.com/open-chat-labs/open-chat/pull/6762))
Expand Down
4 changes: 4 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 Down
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
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

0 comments on commit 37a5b5d

Please sign in to comment.