Skip to content

Commit

Permalink
Add external_url property to channel (#6226)
Browse files Browse the repository at this point in the history
  • Loading branch information
megrogan authored Aug 12, 2024
1 parent d327695 commit 9e023bd
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ tokio = "1.37.0"
tracing = "0.1.40"
tracing-attributes = "0.1.27"
tracing-subscriber = "0.3.18"
url = "2.5.2"
web-push = { version = "0.10.1", default-features = false, features = [
"hyper-client",
] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async fn prepare_airdrop(config: AirdropConfig, user_index_canister_id: Canister
gate: OptionUpdate::SetToSome(AccessGate::Locked),
public: None,
messages_visible_to_non_members: None,
external_url: OptionUpdate::NoChange,
},
)
.await
Expand Down
6 changes: 6 additions & 0 deletions backend/canisters/community/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Added

- Add `external_url` property to channel ([#6226](https://github.com/open-chat-labs/open-chat/pull/6226))

## [[2.0.1286](https://github.com/open-chat-labs/open-chat/releases/tag/v2.0.1286-community)] - 2024-08-12

### Added

- Support updating add members permission ([#6194](https://github.com/open-chat-labs/open-chat/pull/6194))

### Changed
Expand Down
4 changes: 4 additions & 0 deletions backend/canisters/community/api/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ type CreateChannelArgs = record {
permissions_v2 : opt GroupPermissions;
events_ttl : opt Milliseconds;
gate : opt AccessGate;
external_url : opt text;
messages_visible_to_non_members: opt bool;
};

Expand All @@ -498,6 +499,7 @@ type CreateChannelResponse = variant {
UserSuspended;
NotAuthorized;
CommunityFrozen;
ExternalUrlInvalid;
InternalError : text;
};

Expand Down Expand Up @@ -958,6 +960,7 @@ type UpdateChannelArgs = record {
gate : AccessGateUpdate;
public : opt bool;
messages_visible_to_non_members: opt bool;
external_url : TextUpdate;
};

type UpdateChannelResponse = variant {
Expand All @@ -979,6 +982,7 @@ type UpdateChannelResponse = variant {
RulesTooShort : FieldTooShortResult;
UserSuspended;
CommunityFrozen;
ExternalUrlInvalid;
};

type UpdateCommunityArgs = record {
Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/community/api/src/updates/create_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct Args {
pub permissions_v2: Option<GroupPermissions>,
pub events_ttl: Option<Milliseconds>,
pub gate: Option<AccessGate>,
pub external_url: Option<String>,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand All @@ -36,6 +37,7 @@ pub enum Response {
UserSuspended,
NotAuthorized,
CommunityFrozen,
ExternalUrlInvalid,
InternalError(String),
}

Expand Down
2 changes: 2 additions & 0 deletions backend/canisters/community/api/src/updates/update_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Args {
pub gate: OptionUpdate<AccessGate>,
pub public: Option<bool>,
pub messages_visible_to_non_members: Option<bool>,
pub external_url: OptionUpdate<String>,
}

#[derive(CandidType, Serialize, Deserialize, Debug)]
Expand All @@ -36,6 +37,7 @@ pub enum Response {
RulesTooLong(FieldTooLongResult),
RulesTooShort(FieldTooShortResult),
UserSuspended,
ExternalUrlInvalid,
CommunityFrozen,
}

Expand Down
1 change: 1 addition & 0 deletions backend/canisters/community/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ stable_memory = { path = "../../../libraries/stable_memory" }
storage_bucket_client = { path = "../../../libraries/storage_bucket_client" }
tracing = { workspace = true }
types = { path = "../../../libraries/types" }
url = { workspace = true }
user_canister = { path = "../../user/api" }
user_canister_c2c_client = { path = "../../user/c2c_client" }
user_index_canister = { path = "../../user_index/api" }
Expand Down
3 changes: 3 additions & 0 deletions backend/canisters/community/impl/src/model/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl Channel {
None,
created_by_user_type,
anonymized_id,
None,
now,
),
date_imported: None,
Expand Down Expand Up @@ -305,6 +306,7 @@ impl Channel {
membership,
video_call_in_progress: chat.events.video_call_in_progress().value.clone(),
is_invited,
external_url: chat.external_url.value.clone(),
})
}

Expand Down Expand Up @@ -388,6 +390,7 @@ impl Channel {
gate: updates.gate,
membership,
video_call_in_progress: updates.video_call_in_progress,
external_url: updates.external_url,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use group_chat_core::GroupChatCore;
use rand::Rng;
use std::collections::HashMap;
use types::{AccessGate, ChannelId, MultiUserChat, TimestampMillis, UserId, UserType};
use url::Url;
use utils::document_validation::validate_avatar;
use utils::text_validation::{
validate_description, validate_group_name, validate_rules, NameValidationError, RulesValidationError,
Expand Down Expand Up @@ -75,6 +76,12 @@ fn create_channel_impl(
return CommunityFrozen;
}

if let Some(external_url) = &args.external_url {
if Url::parse(external_url).is_err() {
return ExternalUrlInvalid;
}
}

let messages_visible_to_non_members = args.is_public && args.messages_visible_to_non_members.unwrap_or(args.gate.is_none());

let caller = state.env.caller();
Expand Down Expand Up @@ -137,6 +144,7 @@ fn create_channel_impl(
args.events_ttl,
member.user_type,
state.env.rng().gen(),
args.external_url,
now,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use community_canister::update_channel::{Response::*, *};
use group_chat_core::UpdateResult;
use ic_cdk::update;
use types::OptionUpdate;
use url::Url;

#[update]
#[trace]
Expand All @@ -21,6 +22,12 @@ fn update_channel_impl(mut args: Args, state: &mut RuntimeState) -> Response {
return CommunityFrozen;
}

if let OptionUpdate::SetToSome(external_url) = &args.external_url {
if Url::parse(external_url).is_err() {
return ExternalUrlInvalid;
}
}

if let OptionUpdate::SetToSome(gate) = &args.gate {
if !gate.validate() {
return AccessGateInvalid;
Expand Down Expand Up @@ -49,6 +56,7 @@ fn update_channel_impl(mut args: Args, state: &mut RuntimeState) -> Response {
args.public,
args.messages_visible_to_non_members,
args.events_ttl,
args.external_url,
now,
) {
UpdateResult::Success(result) => {
Expand Down
1 change: 1 addition & 0 deletions backend/canisters/group/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ impl Data {
events_ttl,
creator_user_type,
anonymized_chat_id,
None,
now,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ fn commit(my_user_id: UserId, args: Args, state: &mut RuntimeState) -> SuccessRe
args.public,
args.messages_visible_to_non_members,
args.events_ttl,
OptionUpdate::NoChange,
state.env.now(),
);

Expand Down
2 changes: 2 additions & 0 deletions backend/integration_tests/src/client/community.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub mod happy_path {
permissions_v2: None,
events_ttl: None,
gate: None,
external_url: None,
},
);

Expand Down Expand Up @@ -104,6 +105,7 @@ pub mod happy_path {
permissions_v2: None,
events_ttl: None,
gate: Some(gate),
external_url: None,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn existing_users_joined_to_new_public_channel(diamond_gate: bool) {
permissions_v2: None,
events_ttl: None,
gate: diamond_gate.then_some(AccessGate::DiamondMember),
external_url: None,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn disappearing_messages_in_channel() {
gate: OptionUpdate::NoChange,
public: None,
messages_visible_to_non_members: None,
external_url: OptionUpdate::NoChange,
},
);

Expand Down Expand Up @@ -80,6 +81,7 @@ fn disappearing_messages_in_channel() {
gate: OptionUpdate::NoChange,
public: None,
messages_visible_to_non_members: None,
external_url: OptionUpdate::NoChange,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ fn set_channel_rules(env: &mut PocketIc, sender: Principal, community_id: Commun
public: None,
channel_id,
messages_visible_to_non_members: None,
external_url: OptionUpdate::NoChange,
};

client::community::happy_path::update_channel(env, sender, community_id, &args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ fn members_added_if_channel_made_public_or_gate_removed(make_public: bool) {
gate: if !make_public { OptionUpdate::SetToNone } else { OptionUpdate::NoChange },
public: make_public.then_some(true),
messages_visible_to_non_members: None,
external_url: OptionUpdate::NoChange,
},
);

Expand Down
14 changes: 8 additions & 6 deletions backend/libraries/chat_events/src/chat_event_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use std::collections::{HashMap, HashSet};
use std::ops::{Deref, DerefMut};
use types::{
is_default, is_empty_slice, AvatarChanged, ChannelId, Chat, ChatId, ChatMetrics, CommunityId, Cryptocurrency, DeletedBy,
DirectChatCreated, EventIndex, EventWrapperInternal, EventsTimeToLiveUpdated, GroupCreated, GroupDescriptionChanged,
GroupFrozen, GroupGateUpdated, GroupInviteCodeChanged, GroupNameChanged, GroupReplyContext, GroupRulesChanged,
GroupUnfrozen, GroupVisibilityChanged, MemberJoined, MemberLeft, MembersAdded, MembersAddedToDefaultChannel,
MembersRemoved, Message, MessageContent, MessageId, MessageIndex, MessagePinned, MessageUnpinned, MultiUserChat,
PermissionsChanged, PushIfNotContains, Reaction, ReplyContext, RoleChanged, ThreadSummary, TimestampMillis, Timestamped,
Tips, UserId, UsersBlocked, UsersInvited, UsersUnblocked,
DirectChatCreated, EventIndex, EventWrapperInternal, EventsTimeToLiveUpdated, ExternalUrlUpdated, GroupCreated,
GroupDescriptionChanged, GroupFrozen, GroupGateUpdated, GroupInviteCodeChanged, GroupNameChanged, GroupReplyContext,
GroupRulesChanged, GroupUnfrozen, GroupVisibilityChanged, MemberJoined, MemberLeft, MembersAdded,
MembersAddedToDefaultChannel, MembersRemoved, Message, MessageContent, MessageId, MessageIndex, MessagePinned,
MessageUnpinned, MultiUserChat, PermissionsChanged, PushIfNotContains, Reaction, ReplyContext, RoleChanged, ThreadSummary,
TimestampMillis, Timestamped, Tips, UserId, UsersBlocked, UsersInvited, UsersUnblocked,
};

#[derive(Serialize, Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -66,6 +66,8 @@ pub enum ChatEventInternal {
UsersInvited(Box<UsersInvited>),
#[serde(rename = "adc")]
MembersAddedToPublicChannel(Box<MembersAddedToPublicChannelInternal>),
#[serde(rename = "xu")]
ExternalUrlUpdated(Box<ExternalUrlUpdated>),
#[serde(rename = "e")]
Empty,
}
Expand Down
1 change: 1 addition & 0 deletions backend/libraries/chat_events/src/chat_events_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ pub trait Reader {
ChatEventInternal::GroupGateUpdated(g) => ChatEvent::GroupGateUpdated(*g.clone()),
ChatEventInternal::UsersInvited(e) => ChatEvent::UsersInvited(*e.clone()),
ChatEventInternal::MembersAddedToPublicChannel(m) => ChatEvent::MembersAddedToDefaultChannel(m.as_ref().into()),
ChatEventInternal::ExternalUrlUpdated(u) => ChatEvent::ExternalUrlUpdated(*u.clone()),
ChatEventInternal::Empty => ChatEvent::Empty,
};

Expand Down
Loading

0 comments on commit 9e023bd

Please sign in to comment.