Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into next
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/app/src/i18n/cn.json
  • Loading branch information
megrogan committed Jan 1, 2024
2 parents 9008752 + c88bfdc commit 59ffcc6
Show file tree
Hide file tree
Showing 28 changed files with 61 additions and 46 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
4 changes: 4 additions & 0 deletions backend/canisters/community/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 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))
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(),
}
}
1 change: 1 addition & 0 deletions backend/canisters/community/impl/src/model/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,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.

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

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

type ThreadPreview = record {
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>,
}
41 changes: 22 additions & 19 deletions frontend/app/src/components/home/MessageEntry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
let emojiQuery: string | undefined;
let messageEntryHeight: number;
let messageActions: MessageActions;
let rangeToReplace: [number, number] | undefined = undefined;
let rangeToReplace: [Node, number, number] | undefined = undefined;
let previousChatId = chat.id;
// Update this to force a new textbox instance to be created
Expand Down Expand Up @@ -172,23 +172,26 @@
function uptoCaret(
inputContent: string | null,
fn: (slice: string, pos: number) => void,
fn: (slice: string, node: Node, pos: number) => void,
): void {
if (inputContent === null) return;
const pos = window.getSelection()?.anchorOffset;
if (pos === undefined) return;
const selection = window.getSelection();
if (selection === null) return;
const anchorNode = selection.anchorNode;
if (anchorNode?.textContent == null) return;
const text = anchorNode.textContent;
const slice = inputContent.slice(0, pos);
fn(slice, pos);
const slice = text.slice(0, selection.anchorOffset);
fn(slice, anchorNode, selection.anchorOffset);
}
function triggerEmojiLookup(inputContent: string | null): void {
uptoCaret(inputContent, (slice: string, pos: number) => {
uptoCaret(inputContent, (slice: string, node: Node, pos: number) => {
const matches = slice.match(emojiRegex);
if (matches !== null) {
if (matches.index !== undefined) {
rangeToReplace = [matches.index, pos];
rangeToReplace = [node, matches.index, pos];
emojiQuery = matches[1].toLowerCase() || undefined;
showEmojiSearch = true;
}
Expand All @@ -201,11 +204,11 @@
function triggerMentionLookup(inputContent: string | null): void {
if (chat.kind === "direct_chat" || chat.memberCount <= 1) return;
uptoCaret(inputContent, (slice: string, pos: number) => {
uptoCaret(inputContent, (slice: string, node: Node, pos: number) => {
const matches = slice.match(mentionRegex);
if (matches !== null) {
if (matches.index !== undefined) {
rangeToReplace = [matches.index, pos];
rangeToReplace = [node, matches.index, pos];
mentionPrefix = matches[1].toLowerCase() || undefined;
showMentionPicker = true;
}
Expand Down Expand Up @@ -436,10 +439,10 @@
sel?.addRange(range);
}
function setCaretTo(pos: number) {
function setCaretTo(node: Node, pos: number) {
const range = document.createRange();
range.selectNodeContents(inp);
range.setStart(inp.childNodes[0], pos);
range.selectNodeContents(node);
range.setStart(node, pos);
range.collapse(true);
const sel = window.getSelection();
sel?.removeAllRanges();
Expand All @@ -454,18 +457,18 @@
function replaceTextWith(replacement: string) {
if (rangeToReplace === undefined) return;
const start = rangeToReplace[0];
const [node, start, end] = rangeToReplace;
const replaced = `${inp.textContent?.slice(
const replaced = `${node.textContent?.slice(
0,
rangeToReplace[0],
)}${replacement} ${inp.textContent?.slice(rangeToReplace[1])}`;
inp.textContent = replaced;
start,
)}${replacement} ${node.textContent?.slice(end)}`;
node.textContent = replaced;
dispatch("setTextContent", inp.textContent || undefined);
tick().then(() => {
setCaretTo(start + replacement.length);
setCaretTo(node, start + replacement.length + 1);
});
rangeToReplace = undefined;
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/i18n/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@
"communities": "社区",
"selectCommunity": "选择一个社区",
"global": "全球的",
"block": "堵塞",
"unblock": "解锁"
"block": "屏蔽",
"unblock": "取消屏蔽"
},
"undeleteMessage": "取消删除",
"undeletingMessage": "{username} 在 {timestamp} 上取消删除消息",
Expand Down Expand Up @@ -1209,4 +1209,4 @@
},
"messageBlocked": "消息已隐藏",
"removePreviewQuestion": "删除预览?"
}
}
4 changes: 2 additions & 2 deletions frontend/openchat-client/src/openchat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2354,9 +2354,9 @@ export class OpenChat extends OpenChatAgentWorker {
return Promise.resolve();
}

const context = this._liveState.selectedMessageContext;
const context = { chatId, threadRootMessageIndex };

if (context?.threadRootMessageIndex === undefined) return;
if (!messageContextsEqual(context, this._liveState.selectedMessageContext)) return;

const eventsResponse = await this.sendRequest({
kind: "chatEvents",
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.73.0"
channel = "1.75.0"
targets = ["wasm32-unknown-unknown"]

0 comments on commit 59ffcc6

Please sign in to comment.