Skip to content

Commit

Permalink
Merge branch 'master' into send_message_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 20, 2023
2 parents 6c04a91 + f9a8e0f commit 66e5f33
Show file tree
Hide file tree
Showing 31 changed files with 42 additions and 245 deletions.
2 changes: 2 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.985](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.985-community)] - 2023-12-19

### Added

- Support getting batches of summary updates via LocalUserIndex ([#4983](https://github.com/open-chat-labs/open-chat/pull/4983))
Expand Down
5 changes: 0 additions & 5 deletions backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ struct Data {
local_group_index_canister_id: CanisterId,
notifications_canister_id: CanisterId,
proposals_bot_user_id: UserId,
#[serde(default = "escrow_canister_id")]
escrow_canister_id: CanisterId,
date_created: TimestampMillis,
members: CommunityMembers,
Expand All @@ -298,10 +297,6 @@ struct Data {
pub total_payment_receipts: PaymentReceipts,
}

fn escrow_canister_id() -> CanisterId {
CanisterId::from_text("s4yi7-yiaaa-aaaar-qacpq-cai").unwrap()
}

impl Data {
#[allow(clippy::too_many_arguments)]
fn new(
Expand Down
54 changes: 1 addition & 53 deletions backend/canisters/community/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use crate::activity_notifications::handle_activity_notification;
use crate::jobs::import_groups::finalize_group_import;
use crate::lifecycle::{init_env, init_state};
use crate::memory::get_upgrades_memory;
use crate::updates::c2c_join_channel::join_channel_unchecked;
use crate::{mutate_state, read_state, Data};
use crate::{read_state, Data};
use canister_logger::LogEntry;
use canister_tracing_macros::trace;
use community_canister::post_upgrade::Args;
use ic_cdk_macros::post_upgrade;
use instruction_counts_log::InstructionCountFunctionId;
use stable_memory::get_reader;
use std::time::Duration;
use tracing::info;
use types::{AccessGate, CanisterId, UserId};

#[post_upgrade]
#[trace]
Expand Down Expand Up @@ -41,52 +37,4 @@ fn post_upgrade(args: Args) {
.data
.record_instructions_count(InstructionCountFunctionId::PostUpgrade, now)
});

ic_cdk_timers::set_timer(Duration::ZERO, join_members_to_diamond_gated_channels);
}

fn join_members_to_diamond_gated_channels() {
read_state(|state| {
if state
.data
.channels
.iter()
.any(|c| c.chat.is_public.value && matches!(c.chat.gate.value, Some(AccessGate::DiamondMember)))
{
let user_ids: Vec<_> = state.data.members.iter().map(|m| m.user_id).collect();

ic_cdk::spawn(join_members_to_diamond_gated_channels_async(
state.data.local_user_index_canister_id,
user_ids,
));
}
});
}

async fn join_members_to_diamond_gated_channels_async(local_user_index_canister_id: CanisterId, user_ids: Vec<UserId>) {
if let Ok(local_user_index_canister::c2c_diamond_membership_expiry_dates::Response::Success(expiry_dates)) =
local_user_index_canister_c2c_client::c2c_diamond_membership_expiry_dates(
local_user_index_canister_id,
&local_user_index_canister::c2c_diamond_membership_expiry_dates::Args { user_ids },
)
.await
{
mutate_state(|state| {
let now = state.env.now();

for channel in state
.data
.channels
.iter_mut()
.filter(|c| c.chat.is_public.value && matches!(c.chat.gate.value, Some(AccessGate::DiamondMember)))
{
for m in state.data.members.iter_mut() {
if !m.channels.contains(&channel.id) && expiry_dates.get(&m.user_id).copied() > Some(now) {
join_channel_unchecked(channel, m, true, now);
}
}
}
handle_activity_notification(state);
})
}
}
2 changes: 2 additions & 0 deletions backend/canisters/cycles_dispenser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.980](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.980-cycles_dispenser)] - 2023-12-19

### Changed

- Avoid reseeding random number generator after each upgrade ([#4755](https://github.com/open-chat-labs/open-chat/pull/4755))
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/cycles_dispenser/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ struct Data {
pub ledger_canister: CanisterId,
pub cycles_minting_canister: CanisterId,
pub cycles_top_up_pending_notification: Option<BlockIndex>,
#[serde(default)]
pub rng_seed: [u8; 32],
pub test_mode: bool,
}
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/group/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.986](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.986-group)] - 2023-12-19

### Added

- Support getting batches of summary updates via LocalUserIndex ([#4983](https://github.com/open-chat-labs/open-chat/pull/4983))
Expand Down
5 changes: 0 additions & 5 deletions backend/canisters/group/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ struct Data {
pub local_user_index_canister_id: CanisterId,
pub notifications_canister_id: CanisterId,
pub proposals_bot_user_id: UserId,
#[serde(default = "escrow_canister_id")]
pub escrow_canister_id: CanisterId,
pub invite_code: Option<u64>,
pub invite_code_enabled: bool,
Expand All @@ -371,10 +370,6 @@ struct Data {
pub total_payment_receipts: PaymentReceipts,
}

fn escrow_canister_id() -> CanisterId {
CanisterId::from_text("s4yi7-yiaaa-aaaar-qacpq-cai").unwrap()
}

fn init_instruction_counts_log() -> InstructionCountsLog {
InstructionCountsLog::init(get_instruction_counts_index_memory(), get_instruction_counts_data_memory())
}
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.979](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.979-group_index)] - 2023-12-19

### Changed

- Add `escrow_canister_id` to LocalGroupIndex canister init args ([#4897](https://github.com/open-chat-labs/open-chat/pull/4897))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use types::{local_user_index_canister_id, AccessGate, CanisterId, CommunityId, CommunityPermissions, Document, Rules};
use types::{AccessGate, CanisterId, CommunityId, CommunityPermissions, Document, Rules};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
Expand All @@ -27,22 +27,7 @@ pub enum Response {
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
#[serde(from = "SuccessResultPrevious")]
pub struct SuccessResult {
pub community_id: CommunityId,
pub local_user_index_canister_id: CanisterId,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResultPrevious {
pub community_id: CommunityId,
}

impl From<SuccessResultPrevious> for SuccessResult {
fn from(value: SuccessResultPrevious) -> Self {
SuccessResult {
community_id: value.community_id,
local_user_index_canister_id: local_user_index_canister_id(value.community_id.into()),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use types::{
local_user_index_canister_id, AccessGate, CanisterId, ChatId, Document, GroupPermissions, GroupSubtype, Milliseconds, Rules,
};
use types::{AccessGate, CanisterId, ChatId, Document, GroupPermissions, GroupSubtype, Milliseconds, Rules};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
Expand All @@ -28,22 +26,7 @@ pub enum Response {
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
#[serde(from = "SuccessResultPrevious")]
pub struct SuccessResult {
pub chat_id: ChatId,
pub local_user_index_canister_id: CanisterId,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResultPrevious {
pub chat_id: ChatId,
}

impl From<SuccessResultPrevious> for SuccessResult {
fn from(value: SuccessResultPrevious) -> Self {
SuccessResult {
chat_id: value.chat_id,
local_user_index_canister_id: local_user_index_canister_id(value.chat_id.into()),
}
}
}
5 changes: 0 additions & 5 deletions backend/canisters/group_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ struct Data {
pub user_index_canister_id: CanisterId,
pub cycles_dispenser_canister_id: CanisterId,
pub proposals_bot_user_id: UserId,
#[serde(default = "escrow_canister_id")]
pub escrow_canister_id: CanisterId,
pub canisters_requiring_upgrade: CanistersRequiringUpgrade,
pub test_mode: bool,
Expand All @@ -138,10 +137,6 @@ struct Data {
pub rng_seed: [u8; 32],
}

fn escrow_canister_id() -> CanisterId {
CanisterId::from_text("s4yi7-yiaaa-aaaar-qacpq-cai").unwrap()
}

impl Data {
#[allow(clippy::too_many_arguments)]
fn new(
Expand Down
35 changes: 2 additions & 33 deletions backend/canisters/group_index/impl/src/model/cached_hot_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use tracing::trace;
use types::{
local_user_index_canister_id, AccessGate, CanisterId, ChatId, EventIndex, EventWrapper, Message, MessageIndex,
Milliseconds, PublicGroupSummary, TimestampMillis,
AccessGate, CanisterId, ChatId, EventIndex, EventWrapper, Message, MessageIndex, Milliseconds, PublicGroupSummary,
TimestampMillis,
};

#[derive(Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -37,7 +37,6 @@ impl CachedHotGroups {
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(from = "CachedPublicGroupSummaryPrevious")]
pub struct CachedPublicGroupSummary {
pub chat_id: ChatId,
pub local_user_index_canister_id: CanisterId,
Expand All @@ -51,36 +50,6 @@ pub struct CachedPublicGroupSummary {
pub gate: Option<AccessGate>,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct CachedPublicGroupSummaryPrevious {
pub chat_id: ChatId,
pub last_updated: TimestampMillis,
pub latest_message: Option<EventWrapper<Message>>,
pub latest_event_index: EventIndex,
pub latest_message_index: Option<MessageIndex>,
pub participant_count: u32,
pub events_ttl: Option<Milliseconds>,
pub events_ttl_last_updated: TimestampMillis,
pub gate: Option<AccessGate>,
}

impl From<CachedPublicGroupSummaryPrevious> for CachedPublicGroupSummary {
fn from(value: CachedPublicGroupSummaryPrevious) -> Self {
CachedPublicGroupSummary {
chat_id: value.chat_id,
local_user_index_canister_id: local_user_index_canister_id(value.chat_id.into()),
last_updated: value.last_updated,
latest_message: value.latest_message,
latest_event_index: value.latest_event_index,
latest_message_index: value.latest_message_index,
participant_count: value.participant_count,
events_ttl: value.events_ttl,
events_ttl_last_updated: value.events_ttl_last_updated,
gate: value.gate,
}
}
}

impl From<PublicGroupSummary> for CachedPublicGroupSummary {
fn from(summary: PublicGroupSummary) -> Self {
CachedPublicGroupSummary {
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/local_group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.978](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.978-local_group_index)] - 2023-12-19

### Changed

- Add `escrow_canister_id` to Group & Community canister init args ([#4897](https://github.com/open-chat-labs/open-chat/pull/4897))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use candid::Principal;
use serde::{Deserialize, Serialize};
use types::{
local_user_index_canister_id, AccessGate, CanisterId, CommunityId, CommunityPermissions, Document, Rules, SourceGroup,
UserId,
};
use types::{AccessGate, CanisterId, CommunityId, CommunityPermissions, Document, Rules, SourceGroup, UserId};

#[derive(Serialize, Deserialize, Debug)]
pub struct Args {
Expand Down Expand Up @@ -31,22 +28,7 @@ pub enum Response {
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(from = "SuccessResultPrevious")]
pub struct SuccessResult {
pub community_id: CommunityId,
pub local_user_index_canister_id: CanisterId,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct SuccessResultPrevious {
pub community_id: CommunityId,
}

impl From<SuccessResultPrevious> for SuccessResult {
fn from(value: SuccessResultPrevious) -> Self {
SuccessResult {
community_id: value.community_id,
local_user_index_canister_id: local_user_index_canister_id(value.community_id.into()),
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use candid::{CandidType, Principal};
use serde::{Deserialize, Serialize};
use types::{
local_user_index_canister_id, AccessGate, CanisterId, ChatId, Document, GroupPermissions, GroupSubtype, Milliseconds,
Rules, UserId,
};
use types::{AccessGate, CanisterId, ChatId, Document, GroupPermissions, GroupSubtype, Milliseconds, Rules, UserId};

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct Args {
Expand Down Expand Up @@ -33,17 +30,3 @@ pub struct SuccessResult {
pub chat_id: ChatId,
pub local_user_index_canister_id: CanisterId,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
pub struct SuccessResultPrevious {
pub chat_id: ChatId,
}

impl From<SuccessResultPrevious> for SuccessResult {
fn from(value: SuccessResultPrevious) -> Self {
SuccessResult {
chat_id: value.chat_id,
local_user_index_canister_id: local_user_index_canister_id(value.chat_id.into()),
}
}
}
5 changes: 0 additions & 5 deletions backend/canisters/local_group_index/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ struct Data {
pub communities_requiring_upgrade: CanistersRequiringUpgrade,
pub cycles_dispenser_canister_id: CanisterId,
pub proposals_bot_user_id: UserId,
#[serde(default = "escrow_canister_id")]
pub escrow_canister_id: CanisterId,
pub canister_pool: canister::Pool,
pub total_cycles_spent_on_canisters: Cycles,
Expand All @@ -127,10 +126,6 @@ struct Data {
pub rng_seed: [u8; 32],
}

fn escrow_canister_id() -> CanisterId {
CanisterId::from_text("s4yi7-yiaaa-aaaar-qacpq-cai").unwrap()
}

impl Data {
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/local_user_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.976](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.976-local_user_index)] - 2023-12-19

### Added

- Support getting batches of summary updates via LocalUserIndex ([#4983](https://github.com/open-chat-labs/open-chat/pull/4983))
Expand Down
Loading

0 comments on commit 66e5f33

Please sign in to comment.