Skip to content

Commit

Permalink
Wire up user_index to use synced chit and streak (#5979)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Jul 4, 2024
1 parent cbb1725 commit 3739f90
Show file tree
Hide file tree
Showing 34 changed files with 118 additions and 559 deletions.
2 changes: 1 addition & 1 deletion backend/canisters/user/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use fire_and_forget_handler::FireAndForgetHandler;
use model::chit::ChitEarnedEvents;
use model::contacts::Contacts;
use model::favourite_chats::FavouriteChats;
use model::streak::Streak;
use notifications_canister::c2c_push_notification;
use serde::{Deserialize, Serialize};
use serde_bytes::ByteBuf;
Expand All @@ -33,7 +34,6 @@ use user_canister::{NamedAccount, UserCanisterEvent};
use utils::canister_event_sync_queue::CanisterEventSyncQueue;
use utils::env::Environment;
use utils::regular_jobs::RegularJobs;
use utils::streak::Streak;
use utils::time::{today, tomorrow, MINUTE_IN_MS};

mod crypto;
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user/impl/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pub mod group_chats;
pub mod hot_group_exclusions;
pub mod p2p_swaps;
pub mod pin_number;
pub mod streak;
pub mod token_swaps;
pub mod unread_message_index_map;
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ impl Streak {
}
}

pub fn expired_yesterday(&self, today: u16) -> bool {
today == self.end_day + 2
}

pub fn timestamp_to_day(ts: TimestampMillis) -> Option<u16> {
if ts < DAY_ZERO {
return None;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use event_store_producer::EventBuilder;
use ic_cdk::update;
use serde::Serialize;
use types::{Achievement, ChitEarned, ChitEarnedReason, Timestamped, UserId};
use user_index_canister::claim_daily_chit::{Response::*, *};
use user_canister::claim_daily_chit::{Response::*, *};
use utils::time::tomorrow;

#[update(guard = "caller_is_owner")]
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 @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Wire up user_index to use synced chit and streak ([#5979](https://github.com/open-chat-labs/open-chat/pull/5979))

## [[2.0.1221](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1221-user_index)] - 2024-07-03

### Added
Expand Down
30 changes: 0 additions & 30 deletions backend/canisters/user_index/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ type CurrentUserResponse = variant {
diamond_membership_details : opt DiamondMembershipDetails;
diamond_membership_status : DiamondMembershipStatusFull;
moderation_flags_enabled : nat32;
chit_balance : int32;
streak : nat16;
next_daily_claim : TimestampMillis;
};
UserNotFound;
};
Expand Down Expand Up @@ -107,21 +104,6 @@ type UsersResponse = variant {
};
};

type UsersV2Args = record {
user_groups : vec record {
users : vec UserId;
updated_since : TimestampMillis;
};
users_suspended_since : opt TimestampMillis;
};

type UsersV2Response = variant {
Success : record {
users : vec UserSummary;
timestamp : TimestampMillis;
};
};

type SearchArgs = record {
search_term : text;
max_results : nat8;
Expand Down Expand Up @@ -326,16 +308,6 @@ type ReferralStats = record {
total_users : nat32;
};

type ClaimDailyChitResponse = variant {
Success : record {
chit_earned : nat32;
chit_balance : int32;
streak : nat16;
next_claim : TimestampMillis;
};
AlreadyClaimed : TimestampMillis;
};

type ChitLeaderboardResponse = variant {
Success : vec ChitUserBalance;
};
Expand Down Expand Up @@ -412,7 +384,6 @@ service : {

// Gets some users by id
users : (UsersArgs) -> (UsersResponse) query;
users_v2 : (UsersV2Args) -> (UsersV2Response) query;

// Search for users matching some query
search : (SearchArgs) -> (SearchResponse) query;
Expand All @@ -427,7 +398,6 @@ service : {
update_diamond_membership_subscription : (UpdateDiamondMembershipSubscriptionArgs) -> (UpdateDiamondMembershipSubscriptionResponse);
referral_metrics : (EmptyArgs) -> (ReferralMetricsResponse) query;
referral_leaderboard : (ReferralLeaderboardArgs) -> (ReferralLeaderboardResponse) query;
claim_daily_chit : (EmptyArgs) -> (ClaimDailyChitResponse);
chit_leaderboard : (EmptyArgs) -> (ChitLeaderboardResponse) query;

// List the platform moderators/operators
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/user_index/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ fn main() {
generate_candid_method!(user_index, user, query);
generate_candid_method!(user_index, user_registration_canister, query);
generate_candid_method!(user_index, users, query);
generate_candid_method!(user_index, users_v2, query);

generate_candid_method!(user_index, add_platform_moderator, update);
generate_candid_method!(user_index, add_platform_operator, update);
generate_candid_method!(user_index, add_referral_codes, update);
generate_candid_method!(user_index, assign_platform_moderators_group, update);
generate_candid_method!(user_index, claim_daily_chit, update);
generate_candid_method!(user_index, mark_suspected_bot, update);
generate_candid_method!(user_index, pay_for_diamond_membership, update);
generate_candid_method!(user_index, remove_platform_moderator, update);
Expand Down
3 changes: 0 additions & 3 deletions backend/canisters/user_index/api/src/queries/current_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,4 @@ pub struct SuccessResult {
pub diamond_membership_details: Option<DiamondMembershipDetails>,
pub diamond_membership_status: DiamondMembershipStatusFull,
pub moderation_flags_enabled: u32,
pub chit_balance: i32,
pub streak: u16,
pub next_daily_claim: TimestampMillis,
}
1 change: 0 additions & 1 deletion backend/canisters/user_index/api/src/queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ pub mod suspected_bots;
pub mod user;
pub mod user_registration_canister;
pub mod users;
pub mod users_v2;
26 changes: 0 additions & 26 deletions backend/canisters/user_index/api/src/queries/users_v2.rs

This file was deleted.

19 changes: 0 additions & 19 deletions backend/canisters/user_index/api/src/updates/claim_daily_chit.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
Expand Up @@ -12,7 +12,6 @@ pub mod c2c_report_message;
pub mod c2c_send_openchat_bot_messages;
pub mod c2c_set_avatar;
pub mod c2c_suspend_users;
pub mod claim_daily_chit;
pub mod create_challenge;
pub mod delete_user;
pub mod mark_local_user_index_full;
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/user_index/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ generate_query_call!(search);
generate_query_call!(platform_moderators);
generate_query_call!(platform_operators);
generate_query_call!(user);
generate_query_call!(users_v2);

// Updates
generate_update_call!(add_local_user_index_canister);
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/user_index/impl/src/jobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ pub mod make_pending_payments;
pub mod submit_message_to_modclub;
pub mod sync_events_to_local_user_index_canisters;
pub mod sync_users_to_storage_index;
pub mod update_user_streaks;
pub mod upgrade_canisters;

pub(crate) fn start(state: &RuntimeState) {
make_pending_payments::start_job_if_required(state);
submit_message_to_modclub::start_job_if_required(state);
sync_events_to_local_user_index_canisters::start_job_if_required(state);
sync_users_to_storage_index::start_job_if_required(state);
update_user_streaks::start_job_if_required(state);
upgrade_canisters::start_job_if_required(state);
}
40 changes: 0 additions & 40 deletions backend/canisters/user_index/impl/src/jobs/update_user_streaks.rs

This file was deleted.

12 changes: 3 additions & 9 deletions backend/canisters/user_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,9 @@ impl RuntimeState {
suspension_details: user.suspension_details.clone(),
moderation_flags_enabled: user.moderation_flags_enabled,
chit_balance: user.chit_balance,
chit_balance_v2: user.chit_balance_v2,
streak: user.streak.days(now),
streak_v2: user.streak_v2,
streak: user.streak(now),
streak_ends: user.streak_ends,
date_updated_volatile: user.date_updated_volatile,
date_updated_volatile_v2: user.chit_updated,
chit_updated: user.chit_updated,
}
})
}
Expand Down Expand Up @@ -485,12 +482,9 @@ pub struct UserMetrics {
pub suspension_details: Option<SuspensionDetails>,
pub moderation_flags_enabled: u32,
pub chit_balance: i32,
pub chit_balance_v2: i32,
pub chit_updated: TimestampMillis,
pub streak: u16,
pub streak_v2: u16,
pub streak_ends: TimestampMillis,
pub date_updated_volatile: TimestampMillis,
pub date_updated_volatile_v2: TimestampMillis,
}

#[derive(Serialize, Debug, Default)]
Expand Down
Loading

0 comments on commit 3739f90

Please sign in to comment.