Skip to content

Commit

Permalink
Merge branch 'master' into nns_proposal_payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Jan 1, 2024
2 parents 1f0b77b + c88bfdc commit cb873ae
Show file tree
Hide file tree
Showing 50 changed files with 624 additions and 337 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ubuntu:22.04 as builder
SHELL ["bash", "-c"]

ARG git_commit_id
ARG rust_version=1.73.0
ARG rust_version=1.75.0

ENV GIT_COMMIT_ID=$git_commit_id
ENV TZ=UTC
Expand Down
8 changes: 8 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Show proposal payloads for NNS proposals ([#5072](https://github.com/open-chat-labs/open-chat/pull/5072))

### Changed

- Add `subtype` to channel search results ([#5084](https://github.com/open-chat-labs/open-chat/pull/5084))

### Fixed

- Prevent latest messages of payment gated groups from being public ([#5080](https://github.com/open-chat-labs/open-chat/pull/5080))

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

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ async fn make_payment(ledger_canister: CanisterId, transfer_args: TransferArg) -

fn memo(reason: PendingPaymentReason) -> Memo {
match reason {
PendingPaymentReason::AccessGate => MEMO_JOINING_FEE.to_vec().try_into().unwrap(),
PendingPaymentReason::AccessGate => MEMO_JOINING_FEE.to_vec().into(),
}
}
4 changes: 3 additions & 1 deletion backend/canisters/community/impl/src/model/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ impl Channel {
}

fn can_view_latest_message(&self, is_channel_member: bool, is_community_member: bool, is_community_public: bool) -> bool {
is_channel_member || (self.chat.is_public.value && (is_community_member || is_community_public))
is_channel_member
|| (self.chat.is_public.value && !self.chat.has_payment_gate() && (is_community_member || is_community_public))
}
}

Expand All @@ -388,6 +389,7 @@ impl From<&Channel> for ChannelMatch {
avatar_id: types::Document::id(&channel.chat.avatar),
member_count: channel.chat.members.len(),
gate: channel.chat.gate.value.clone(),
subtype: channel.chat.subtype.value.clone(),
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/cycles_dispenser/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod lifecycle;
mod queries;
mod updates;

pub use lifecycle::*;
pub use queries::*;
pub use updates::*;
1 change: 0 additions & 1 deletion backend/canisters/cycles_dispenser/api/src/queries/mod.rs

This file was deleted.

2 changes: 0 additions & 2 deletions backend/canisters/escrow/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use sha256::sha256;
use types::UserId;

mod lifecycle;
mod queries;
mod updates;

pub use lifecycle::*;
pub use queries::*;
pub use updates::*;

pub fn deposit_subaccount(user_id: UserId, offer_id: u32) -> Subaccount {
Expand Down
1 change: 0 additions & 1 deletion backend/canisters/escrow/api/src/queries/mod.rs

This file was deleted.

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

- Show proposal payloads for NNS proposals ([#5072](https://github.com/open-chat-labs/open-chat/pull/5072))

### Fixed

- Prevent latest messages of payment gated groups from being public ([#5080](https://github.com/open-chat-labs/open-chat/pull/5080))

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

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ async fn make_payment(ledger_canister: CanisterId, transfer_args: TransferArg) -

fn memo(reason: PendingPaymentReason) -> Memo {
match reason {
PendingPaymentReason::AccessGate => MEMO_JOINING_FEE.to_vec().try_into().unwrap(),
PendingPaymentReason::AccessGate => MEMO_JOINING_FEE.to_vec().into(),
}
}
2 changes: 1 addition & 1 deletion backend/canisters/group/impl/src/queries/public_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn public_summary_impl(args: Args, state: &RuntimeState) -> Response {
let events_ttl = data.chat.events.get_events_time_to_live();

// You can't see private group messages unless you are a member of the group
let latest_message = if is_public || state.data.get_member(caller).is_some() {
let latest_message = if (is_public && !data.chat.has_payment_gate()) || state.data.get_member(caller).is_some() {
events_reader.latest_message_event(None)
} else {
None
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/group_index/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Add `subtype` to group search results ([#5084](https://github.com/open-chat-labs/open-chat/pull/5084))

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

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ impl From<&PublicGroupInfo> for GroupMatch {
avatar_id: group.avatar_id,
member_count: group.activity.member_count,
gate: group.gate.clone(),
subtype: group.subtype.clone(),
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions backend/canisters/neuron_controller/api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod lifecycle;
mod queries;
mod updates;

pub use lifecycle::*;
pub use queries::*;
pub use updates::*;
1 change: 0 additions & 1 deletion backend/canisters/neuron_controller/api/src/queries/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion backend/canisters/proposals_bot/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn generate_message_id(governance_canister_id: CanisterId, proposal_id: Proposal
hash.update(b"proposals_bot");
hash.update(governance_canister_id.as_slice());
hash.update(proposal_id.to_ne_bytes());
let array32: [u8; 32] = hash.finalize().try_into().unwrap();
let array32: [u8; 32] = hash.finalize().into();
let array16: [u8; 16] = array32[..16].try_into().unwrap();
u128::from_ne_bytes(array16).into()
}
4 changes: 4 additions & 0 deletions backend/canisters/user/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [unreleased]

### Changed

- Add `local_user_index_canister_id` to `initial_state` response ([#5083](https://github.com/open-chat-labs/open-chat/pull/5083))

### Removed

- Remove group summary cache ([#5067](https://github.com/open-chat-labs/open-chat/pull/5067))
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ type InitialStateResponse = variant {
avatar_id : opt nat;
blocked_users : vec UserId;
suspended : bool;
local_user_index_canister_id : CanisterId;
};
};

Expand Down
3 changes: 2 additions & 1 deletion backend/canisters/user/api/src/queries/initial_state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use candid::CandidType;
use serde::{Deserialize, Serialize};
use types::{Chat, ChatId, DirectChatSummary, Empty, GroupChatSummary, TimestampMillis, UserId};
use types::{CanisterId, Chat, ChatId, DirectChatSummary, Empty, GroupChatSummary, TimestampMillis, UserId};

pub type Args = Empty;

Expand All @@ -19,6 +19,7 @@ pub struct SuccessResult {
pub avatar_id: Option<u128>,
pub blocked_users: Vec<UserId>,
pub suspended: bool,
pub local_user_index_canister_id: CanisterId,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/user/impl/src/queries/initial_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ fn initial_state_impl(state: &RuntimeState) -> Response {
avatar_id,
blocked_users,
suspended: state.data.suspended.value,
local_user_index_canister_id: state.data.local_user_index_canister_id,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async fn make_payment(pending_payment: &PendingPayment) -> Result<BlockIndex, bo
to: pending_payment.recipient_account,
fee: None,
created_at_time: Some(pending_payment.timestamp),
memo: Some(pending_payment.memo.to_vec().try_into().unwrap()),
memo: Some(pending_payment.memo.to_vec().into()),
amount: pending_payment.amount.into(),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn get_batched_events_succeeds() {
},
);

assert_is_message_with_text(responses.get(0).unwrap(), "User: 0");
assert_is_message_with_text(responses.first().unwrap(), "User: 0");
assert_is_message_with_text(responses.get(1).unwrap(), "Group1: 1");
assert_is_message_with_text(responses.get(2).unwrap(), "Group2: 2");
assert_is_message_with_text(responses.get(3).unwrap(), "Channel: 3");
Expand Down Expand Up @@ -123,13 +123,13 @@ fn get_batched_summaries_succeeds() {
},
);

assert_is_summary_with_id(responses.get(0).unwrap(), group_id1.into(), false);
assert_is_summary_with_id(responses.first().unwrap(), group_id1.into(), false);
assert_is_summary_with_id(responses.get(1).unwrap(), group_id2.into(), false);
assert_is_summary_with_id(responses.get(2).unwrap(), community_id.into(), true);
}

fn assert_is_message_with_text(response: &EventsResponse, text: &str) {
if let local_user_index_canister::chat_events::EventsResponse::Success(result) = response {
if let EventsResponse::Success(result) = response {
assert_eq!(result.events.len(), 1);
if let ChatEvent::Message(message) = &result.events.first().unwrap().event {
assert_eq!(message.content.text().unwrap(), text);
Expand Down
2 changes: 1 addition & 1 deletion backend/libraries/candid_gen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn generate_candid_method_no_args(input: TokenStream) -> TokenStream {
}

fn get_method_attribute(inputs: Vec<String>) -> MethodAttribute {
let first_arg = inputs.get(0).unwrap();
let first_arg = inputs.first().unwrap();
let second_arg = inputs.get(1).unwrap();
let third_arg = inputs.get(2).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion backend/libraries/canister_api_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn get_arg_names(signature: &Signature) -> Vec<Ident> {
}

fn get_validation_method_attribute(inputs: Vec<String>) -> ValidationMethodAttribute {
let service_name = inputs.get(0).unwrap().to_string();
let service_name = inputs.first().unwrap().to_string();
let function_name = inputs.get(1).unwrap().to_string();

ValidationMethodAttribute {
Expand Down
8 changes: 2 additions & 6 deletions backend/libraries/group_chat_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,12 +1731,8 @@ impl GroupChatCore {
})
}

fn has_payment_gate(&self) -> bool {
self.gate
.value
.as_ref()
.map(|g| matches!(g, AccessGate::Payment(_)))
.unwrap_or_default()
pub fn has_payment_gate(&self) -> bool {
self.gate.value.as_ref().map(|g| g.is_payment_gate()).unwrap_or_default()
}
}

Expand Down
2 changes: 2 additions & 0 deletions backend/libraries/types/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ type GroupMatch = record {
avatar_id : opt nat;
member_count : nat32;
gate : opt AccessGate;
subtype : opt GroupSubtype;
};

type ChannelMatch = record {
Expand All @@ -1599,6 +1600,7 @@ type ChannelMatch = record {
avatar_id : opt nat;
member_count : nat32;
gate : opt AccessGate;
subtype : opt GroupSubtype;
};

type ThreadPreview = record {
Expand Down
4 changes: 4 additions & 0 deletions backend/libraries/types/src/gated_groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ impl AccessGate {
pub fn synchronous(&self) -> bool {
matches!(self, AccessGate::DiamondMember)
}

pub fn is_payment_gate(&self) -> bool {
matches!(self, AccessGate::Payment(_))
}
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
Expand Down
4 changes: 3 additions & 1 deletion backend/libraries/types/src/group_match.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{AccessGate, ChannelId, ChatId, CommunityId};
use crate::{AccessGate, ChannelId, ChatId, CommunityId, GroupSubtype};
use candid::CandidType;
use serde::{Deserialize, Serialize};

Expand All @@ -10,6 +10,7 @@ pub struct GroupMatch {
pub avatar_id: Option<u128>,
pub member_count: u32,
pub gate: Option<AccessGate>,
pub subtype: Option<GroupSubtype>,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand All @@ -35,4 +36,5 @@ pub struct ChannelMatch {
pub avatar_id: Option<u128>,
pub member_count: u32,
pub gate: Option<AccessGate>,
pub subtype: Option<GroupSubtype>,
}
Loading

0 comments on commit cb873ae

Please sign in to comment.