Skip to content

Commit

Permalink
Merge branch 'master' into bot
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Dec 20, 2024
2 parents 1cadbdc + d7375d6 commit 0feaac2
Show file tree
Hide file tree
Showing 53 changed files with 709 additions and 299 deletions.
6 changes: 6 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1540](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1540-community)] - 2024-12-19

### Fixed

- Fix community `RoleChanged` event deserialization ([#7098](https://github.com/open-chat-labs/open-chat/pull/7098))

## [[2.0.1538](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1538-community)] - 2024-12-19

### Changed
Expand Down
10 changes: 1 addition & 9 deletions backend/canisters/community/impl/src/lifecycle/post_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use ic_cdk::post_upgrade;
use instruction_counts_log::InstructionCountFunctionId;
use stable_memory::get_reader;
use tracing::info;
use utils::env::Environment;

#[post_upgrade]
#[trace]
Expand All @@ -19,19 +18,12 @@ fn post_upgrade(args: Args) {
let memory = get_upgrades_memory();
let reader = get_reader(&memory);

let (mut data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
let (data, errors, logs, traces): (Data, Vec<LogEntry>, Vec<LogEntry>, Vec<LogEntry>) =
msgpack::deserialize(reader).unwrap();

canister_logger::init_with_logs(data.test_mode, errors, logs, traces);

data.events.fix_role_changed_events();

let env = init_env(data.rng_seed);
let now = env.now();
for channel in data.channels.iter_mut() {
channel.chat.events.remove_spurious_video_call_in_progress(now);
}

init_state(env, data, args.wasm_version);

let completed_imports = read_state(|state| state.data.groups_being_imported.completed_imports());
Expand Down
104 changes: 4 additions & 100 deletions backend/canisters/community/impl/src/model/events.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use crate::model::events::stable_memory::EventsStableStorage;
use chat_events::GroupGateUpdatedInternal;
use serde::{Deserialize, Serialize};
use tracing::info;
use types::{
AvatarChanged, BannerChanged, BotAdded, BotRemoved, BotUpdated, ChannelDeleted, ChannelId, ChatId, CommunityMembersRemoved,
CommunityPermissionsChanged, CommunityRole, CommunityUsersBlocked, CommunityVisibilityChanged, EventIndex,
CommunityPermissionsChanged, CommunityRoleChanged, CommunityUsersBlocked, CommunityVisibilityChanged, EventIndex,
EventWrapperInternal, GroupCreated, GroupDescriptionChanged, GroupFrozen, GroupInviteCodeChanged, GroupNameChanged,
GroupUnfrozen, PrimaryLanguageChanged, TimestampMillis, UserId, UsersInvited, UsersUnblocked,
GroupRulesChanged, GroupUnfrozen, PrimaryLanguageChanged, TimestampMillis, UserId, UsersInvited, UsersUnblocked,
};
use user_canister::token_swap_status::CandidType;

mod stable_memory;

Expand All @@ -19,54 +17,6 @@ pub struct CommunityEvents {
latest_event_timestamp: TimestampMillis,
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum CommunityEventInternalOld {
#[serde(rename = "cr", alias = "Created")]
Created(Box<GroupCreated>),
#[serde(rename = "nc", alias = "NameChanged")]
NameChanged(Box<GroupNameChanged>),
#[serde(rename = "dc", alias = "DescriptionChanged")]
DescriptionChanged(Box<GroupDescriptionChanged>),
#[serde(rename = "rc", alias = "RulesChanged")]
RulesChangedOrRoleChanged(Box<RulesChangedOrRoleChanged>),
#[serde(rename = "ac", alias = "AvatarChanged")]
AvatarChanged(Box<AvatarChanged>),
#[serde(rename = "bc", alias = "BannerChanged")]
BannerChanged(Box<BannerChanged>),
#[serde(rename = "ui", alias = "UsersInvited")]
UsersInvited(Box<UsersInvited>),
#[serde(rename = "mr", alias = "MembersRemoved")]
MembersRemoved(Box<CommunityMembersRemoved>),
#[serde(rename = "ub", alias = "UsersBlocked")]
UsersBlocked(Box<CommunityUsersBlocked>),
#[serde(rename = "uu", alias = "UsersUnblocked")]
UsersUnblocked(Box<UsersUnblocked>),
#[serde(rename = "pc", alias = "PermissionsChanged")]
PermissionsChanged(Box<CommunityPermissionsChanged>),
#[serde(rename = "vc", alias = "VisibilityChanged")]
VisibilityChanged(Box<CommunityVisibilityChanged>),
#[serde(rename = "ic", alias = "InviteCodeChanged")]
InviteCodeChanged(Box<GroupInviteCodeChanged>),
#[serde(rename = "fr", alias = "Frozen")]
Frozen(Box<GroupFrozen>),
#[serde(rename = "uf", alias = "Unfrozen")]
Unfrozen(Box<GroupUnfrozen>),
#[serde(rename = "gu", alias = "GateUpdated")]
GateUpdated(Box<GroupGateUpdatedInternal>),
#[serde(rename = "cd", alias = "ChannelDeleted")]
ChannelDeleted(Box<ChannelDeleted>),
#[serde(rename = "pl", alias = "PrimaryLanguageChanged")]
PrimaryLanguageChanged(Box<PrimaryLanguageChanged>),
#[serde(rename = "gi", alias = "GroupImported")]
GroupImported(Box<GroupImportedInternal>),
#[serde(rename = "ba")]
BotAdded(Box<BotAdded>),
#[serde(rename = "br")]
BotRemoved(Box<BotRemoved>),
#[serde(rename = "bu")]
BotUpdated(Box<BotUpdated>),
}

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum CommunityEventInternal {
#[serde(rename = "cr", alias = "Created")]
Expand All @@ -76,7 +26,7 @@ pub enum CommunityEventInternal {
#[serde(rename = "dc", alias = "DescriptionChanged")]
DescriptionChanged(Box<GroupDescriptionChanged>),
#[serde(rename = "rc", alias = "RulesChanged")]
RulesChanged(Box<types::GroupRulesChanged>),
RulesChanged(Box<GroupRulesChanged>),
#[serde(rename = "ac", alias = "AvatarChanged")]
AvatarChanged(Box<AvatarChanged>),
#[serde(rename = "bc", alias = "BannerChanged")]
Expand All @@ -86,7 +36,7 @@ pub enum CommunityEventInternal {
#[serde(rename = "mr", alias = "MembersRemoved")]
MembersRemoved(Box<CommunityMembersRemoved>),
#[serde(rename = "rl", alias = "RoleChanged")]
RoleChanged(Box<types::CommunityRoleChanged>),
RoleChanged(Box<CommunityRoleChanged>),
#[serde(rename = "ub", alias = "UsersBlocked")]
UsersBlocked(Box<CommunityUsersBlocked>),
#[serde(rename = "uu", alias = "UsersUnblocked")]
Expand Down Expand Up @@ -117,53 +67,7 @@ pub enum CommunityEventInternal {
BotUpdated(Box<BotUpdated>),
}

#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(untagged)]
pub enum RulesChangedOrRoleChanged {
RulesChanged(GroupRulesChanged),
RoleChanged(CommunityRoleChanged),
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
pub struct GroupRulesChanged {
pub enabled: bool,
pub prev_enabled: bool,
pub changed_by: UserId,
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
pub struct CommunityRoleChanged {
pub user_ids: Vec<UserId>,
pub changed_by: UserId,
pub old_role: CommunityRole,
pub new_role: CommunityRole,
}

impl CommunityEvents {
pub fn fix_role_changed_events(&mut self) {
let mut count_updated = 0;
for event_wrapper in self.stable_events_map.read_all() {
if let CommunityEventInternalOld::RulesChangedOrRoleChanged(r) = event_wrapper.event {
if let RulesChangedOrRoleChanged::RoleChanged(role) = *r {
self.stable_events_map.insert(EventWrapperInternal {
index: event_wrapper.index,
timestamp: event_wrapper.timestamp,
correlation_id: 0,
expires_at: event_wrapper.expires_at,
event: CommunityEventInternal::RoleChanged(Box::new(types::CommunityRoleChanged {
user_ids: role.user_ids,
changed_by: role.changed_by,
old_role: role.old_role,
new_role: role.new_role,
})),
});
count_updated += 1;
}
}
}
info!(count_updated, "Fixed community events");
}

pub fn new(name: String, description: String, created_by: UserId, now: TimestampMillis) -> CommunityEvents {
let event_index = EventIndex::default();
let event = EventWrapperInternal {
Expand Down
14 changes: 3 additions & 11 deletions backend/canisters/community/impl/src/model/events/stable_memory.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
use crate::model::events::{CommunityEventInternal, CommunityEventInternalOld};
use crate::model::events::CommunityEventInternal;
use candid::Deserialize;
use serde::Serialize;
use stable_memory_map::{with_map, with_map_mut, CommunityEventKeyPrefix, KeyPrefix};
use types::{EventIndex, EventWrapperInternal};
use stable_memory_map::{with_map_mut, CommunityEventKeyPrefix, KeyPrefix};
use types::EventWrapperInternal;

#[derive(Serialize, Deserialize, Default)]
pub struct EventsStableStorage {
prefix: CommunityEventKeyPrefix,
}

impl EventsStableStorage {
pub fn read_all(&self) -> Vec<EventWrapperInternal<CommunityEventInternalOld>> {
with_map(|m| {
m.range(self.prefix.create_key(&EventIndex::default())..)
.map(|(_, bytes)| msgpack::deserialize_then_unwrap(&bytes))
.collect()
})
}

pub fn insert(&mut self, event: EventWrapperInternal<CommunityEventInternal>) {
with_map_mut(|m| m.insert(self.prefix.create_key(&event.index), event_to_bytes(event)));
}
Expand Down
8 changes: 7 additions & 1 deletion backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

## [[2.0.1541](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1541-group_index)] - 2024-12-19

### Changed

- Handle retry attempts when adding a new LocalGroupIndex ([#7091](https://github.com/open-chat-labs/open-chat/pull/7091))
- Add logging + skip steps that have already been completed ([#7093](https://github.com/open-chat-labs/open-chat/pull/7093))

## [[2.0.1519](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1519-group_index)] - 2024-12-19
### Fixed

- Set `wasm_hash` field which was previously empty ([#7097](https://github.com/open-chat-labs/open-chat/pull/7097))

## [[2.0.1528](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1528-group_index)] - 2024-12-19

### Changed

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

## [unreleased]

## [[2.0.1542](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1542-user_index)] - 2024-12-19

### Changed

- Add logging + skip steps that have already been completed ([#7093](https://github.com/open-chat-labs/open-chat/pull/7093))
- Change bot cmd number param values from u16 to f64 ([#7095](https://github.com/open-chat-labs/open-chat/pull/7095))

### Fixed

- Set `wasm_hash` field which was previously empty ([#7097](https://github.com/open-chat-labs/open-chat/pull/7097))

## [[2.0.1537](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1537-user_index)] - 2024-12-19

### Changed
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user_index/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ fn main() {
generate_ts_method!(user_index, submit_proof_of_unique_personhood);
generate_ts_method!(user_index, suspend_user);
generate_ts_method!(user_index, unsuspend_user);
generate_ts_method!(user_index, update_bot);
generate_ts_method!(user_index, update_diamond_membership_subscription);
}
6 changes: 6 additions & 0 deletions frontend/app/src/components/Input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
children?: Snippet;
onblur?: () => void;
onfocus?: () => void;
oninput?: () => void;
onenter?: () => void;
}
</script>

Expand All @@ -40,6 +42,8 @@
pattern = undefined,
onblur = undefined,
onfocus = undefined,
oninput = undefined,
onenter = undefined,
children,
}: InputProps = $props();
Expand All @@ -61,6 +65,7 @@
value = parseInt(e.currentTarget.value, 10);
}
dispatch("change", value);
oninput?.();
};
export function setValue(text: string) {
Expand All @@ -70,6 +75,7 @@
function keyDown(e: KeyboardEvent) {
if (e.key === "Enter") {
dispatch("enter");
onenter?.();
}
}
Expand Down
Loading

0 comments on commit 0feaac2

Please sign in to comment.