Skip to content

Commit

Permalink
Make is_invited optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Jul 25, 2024
1 parent af67a5b commit ce96717
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
6 changes: 5 additions & 1 deletion backend/canisters/community/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ impl RuntimeState {
jobs::make_pending_payments::start_job_if_required(self);
}

pub fn summary(&self, member: Option<&CommunityMemberInternal>, is_invited: bool) -> CommunityCanisterCommunitySummary {
pub fn summary(
&self,
member: Option<&CommunityMemberInternal>,
is_invited: Option<bool>,
) -> CommunityCanisterCommunitySummary {
let data = &self.data;

let (channels, membership) = if let Some(m) = member {
Expand Down
10 changes: 7 additions & 3 deletions backend/canisters/community/impl/src/model/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,16 @@ impl Channel {
let member = user_id.and_then(|user_id| chat.members.get(&user_id));

let (min_visible_event_index, min_visible_message_index, is_invited) = if let Some(member) = member {
(member.min_visible_event_index(), member.min_visible_message_index(), false)
(member.min_visible_event_index(), member.min_visible_message_index(), None)
} else if let Some(invitation) = user_id.and_then(|user_id| chat.invited_users.get(&user_id)) {
(invitation.min_visible_event_index, invitation.min_visible_message_index, true)
(
invitation.min_visible_event_index,
invitation.min_visible_message_index,
Some(true),
)
} else if chat.is_public.value {
let (e, m) = chat.min_visible_indexes_for_new_members.unwrap_or_default();
(e, m, false)
(e, m, Some(false))
} else {
return None;
};
Expand Down
2 changes: 1 addition & 1 deletion backend/canisters/community/impl/src/queries/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn summary_impl(invite_code: Option<u64>, on_behalf_of: Option<Principal>, state
let member = state.data.members.get(caller);
let is_invited = state.data.is_invited(caller);

let summary = state.summary(member, is_invited);
let summary = state.summary(member, Some(is_invited));

Success(summary)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn c2c_join_channel(args: Args) -> Response {
if matches!(response, Success(_) | AlreadyInChannel(_)) {
let summary = read_state(|state| {
let member = state.data.members.get_by_user_id(&args.user_id);
state.summary(member, false)
state.summary(member, None)
});
SuccessJoinedCommunity(Box::new(summary))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub(crate) async fn join_community(args: Args) -> Response {
}
read_state(|state| {
if let Some(member) = state.data.members.get_by_user_id(&args.user_id) {
Success(Box::new(state.summary(Some(member), false)))
Success(Box::new(state.summary(Some(member), None)))
} else {
InternalError("User not found in community".to_string())
}
Expand All @@ -58,7 +58,7 @@ fn is_permitted_to_join(args: &Args, state: &RuntimeState) -> Result<Option<(Acc
if caller == state.data.user_index_canister_id {
Ok(None)
} else if let Some(member) = state.data.members.get_by_user_id(&args.user_id) {
Err(AlreadyInCommunity(Box::new(state.summary(Some(member), false))))
Err(AlreadyInCommunity(Box::new(state.summary(Some(member), None))))
} else if state.data.members.is_blocked(&args.user_id) {
Err(UserBlocked)
} else if state.data.is_frozen() {
Expand Down Expand Up @@ -135,7 +135,7 @@ pub(crate) fn join_community_impl(args: &Args, state: &mut RuntimeState) -> Resu
}
AddResult::AlreadyInCommunity => {
let member = state.data.members.get_by_user_id(&args.user_id).unwrap();
let summary = state.summary(Some(member), false);
let summary = state.summary(Some(member), None);
Err(AlreadyInCommunity(Box::new(summary)))
}
AddResult::Blocked => Err(UserBlocked),
Expand Down
2 changes: 1 addition & 1 deletion backend/libraries/types/src/channel_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct CommunityCanisterChannelSummary {
pub gate: Option<AccessGate>,
pub membership: Option<GroupMembership>,
pub video_call_in_progress: Option<VideoCall>,
pub is_invited: bool,
pub is_invited: Option<bool>,
}

#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion backend/libraries/types/src/community_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct CommunityCanisterCommunitySummary {
pub channels: Vec<CommunityCanisterChannelSummary>,
pub membership: Option<CommunityMembership>,
pub user_groups: Vec<UserGroupSummary>,
pub is_invited: bool,
pub is_invited: Option<bool>,
pub metrics: ChatMetrics,
}

Expand Down

0 comments on commit ce96717

Please sign in to comment.