Wire through public access toggle

This commit is contained in:
Conrad Irwin 2023-10-13 16:59:30 -06:00
parent f8fd77b83e
commit f6f9b5c8cb
13 changed files with 209 additions and 38 deletions

View file

@ -432,6 +432,7 @@ pub struct NewUserResult {
pub struct Channel {
pub id: ChannelId,
pub name: String,
pub visibility: ChannelVisibility,
}
#[derive(Debug, PartialEq)]

View file

@ -137,7 +137,7 @@ impl Into<i32> for ChannelRole {
}
}
#[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default)]
#[derive(Eq, PartialEq, Copy, Clone, Debug, EnumIter, DeriveActiveEnum, Default, Hash)]
#[sea_orm(rs_type = "String", db_type = "String(None)")]
pub enum ChannelVisibility {
#[sea_orm(string_value = "public")]
@ -151,7 +151,7 @@ impl From<proto::ChannelVisibility> for ChannelVisibility {
fn from(value: proto::ChannelVisibility) -> Self {
match value {
proto::ChannelVisibility::Public => ChannelVisibility::Public,
proto::ChannelVisibility::ChannelMembers => ChannelVisibility::Members,
proto::ChannelVisibility::Members => ChannelVisibility::Members,
}
}
}
@ -160,7 +160,7 @@ impl Into<proto::ChannelVisibility> for ChannelVisibility {
fn into(self) -> proto::ChannelVisibility {
match self {
ChannelVisibility::Public => proto::ChannelVisibility::Public,
ChannelVisibility::Members => proto::ChannelVisibility::ChannelMembers,
ChannelVisibility::Members => proto::ChannelVisibility::Members,
}
}
}

View file

@ -93,12 +93,12 @@ impl Database {
channel_id: ChannelId,
visibility: ChannelVisibility,
user_id: UserId,
) -> Result<()> {
) -> Result<channel::Model> {
self.transaction(move |tx| async move {
self.check_user_is_channel_admin(channel_id, user_id, &*tx)
.await?;
channel::ActiveModel {
let channel = channel::ActiveModel {
id: ActiveValue::Unchanged(channel_id),
visibility: ActiveValue::Set(visibility),
..Default::default()
@ -106,7 +106,7 @@ impl Database {
.update(&*tx)
.await?;
Ok(())
Ok(channel)
})
.await
}
@ -219,14 +219,14 @@ impl Database {
channel_id: ChannelId,
user_id: UserId,
new_name: &str,
) -> Result<String> {
) -> Result<Channel> {
self.transaction(move |tx| async move {
let new_name = Self::sanitize_channel_name(new_name)?.to_string();
self.check_user_is_channel_admin(channel_id, user_id, &*tx)
.await?;
channel::ActiveModel {
let channel = channel::ActiveModel {
id: ActiveValue::Unchanged(channel_id),
name: ActiveValue::Set(new_name.clone()),
..Default::default()
@ -234,7 +234,11 @@ impl Database {
.update(&*tx)
.await?;
Ok(new_name)
Ok(Channel {
id: channel.id,
name: channel.name,
visibility: channel.visibility,
})
})
.await
}
@ -336,6 +340,7 @@ impl Database {
.map(|channel| Channel {
id: channel.id,
name: channel.name,
visibility: channel.visibility,
})
.collect();
@ -443,6 +448,7 @@ impl Database {
channels.push(Channel {
id: channel.id,
name: channel.name,
visibility: channel.visibility,
});
if role == ChannelRole::Admin {
@ -963,6 +969,7 @@ impl Database {
Ok(Some((
Channel {
id: channel.id,
visibility: channel.visibility,
name: channel.name,
},
is_accepted,

View file

@ -159,6 +159,7 @@ fn graph(channels: &[(ChannelId, &'static str)], edges: &[(ChannelId, ChannelId)
graph.channels.push(Channel {
id: *id,
name: name.to_string(),
visibility: ChannelVisibility::Members,
})
}

View file

@ -3,8 +3,8 @@ mod connection_pool;
use crate::{
auth,
db::{
self, BufferId, ChannelId, ChannelsForUser, Database, MessageId, ProjectId, RoomId,
ServerId, User, UserId,
self, BufferId, ChannelId, ChannelVisibility, ChannelsForUser, Database, MessageId,
ProjectId, RoomId, ServerId, User, UserId,
},
executor::Executor,
AppState, Result,
@ -38,8 +38,8 @@ use lazy_static::lazy_static;
use prometheus::{register_int_gauge, IntGauge};
use rpc::{
proto::{
self, Ack, AnyTypedEnvelope, ChannelEdge, ChannelVisibility, EntityMessage,
EnvelopedMessage, LiveKitConnectionInfo, RequestMessage, UpdateChannelBufferCollaborators,
self, Ack, AnyTypedEnvelope, ChannelEdge, EntityMessage, EnvelopedMessage,
LiveKitConnectionInfo, RequestMessage, UpdateChannelBufferCollaborators,
},
Connection, ConnectionId, Peer, Receipt, TypedEnvelope,
};
@ -255,6 +255,7 @@ impl Server {
.add_request_handler(invite_channel_member)
.add_request_handler(remove_channel_member)
.add_request_handler(set_channel_member_role)
.add_request_handler(set_channel_visibility)
.add_request_handler(rename_channel)
.add_request_handler(join_channel_buffer)
.add_request_handler(leave_channel_buffer)
@ -2210,8 +2211,7 @@ async fn create_channel(
let channel = proto::Channel {
id: id.to_proto(),
name: request.name,
// TODO: Visibility
visibility: proto::ChannelVisibility::ChannelMembers as i32,
visibility: proto::ChannelVisibility::Members as i32,
};
response.send(proto::CreateChannelResponse {
@ -2300,9 +2300,8 @@ async fn invite_channel_member(
let mut update = proto::UpdateChannels::default();
update.channel_invitations.push(proto::Channel {
id: channel.id.to_proto(),
visibility: channel.visibility.into(),
name: channel.name,
// TODO: Visibility
visibility: proto::ChannelVisibility::ChannelMembers as i32,
});
for connection_id in session
.connection_pool()
@ -2343,6 +2342,39 @@ async fn remove_channel_member(
Ok(())
}
async fn set_channel_visibility(
request: proto::SetChannelVisibility,
response: Response<proto::SetChannelVisibility>,
session: Session,
) -> Result<()> {
let db = session.db().await;
let channel_id = ChannelId::from_proto(request.channel_id);
let visibility = request.visibility().into();
let channel = db
.set_channel_visibility(channel_id, visibility, session.user_id)
.await?;
let mut update = proto::UpdateChannels::default();
update.channels.push(proto::Channel {
id: channel.id.to_proto(),
name: channel.name,
visibility: channel.visibility.into(),
});
let member_ids = db.get_channel_members(channel_id).await?;
let connection_pool = session.connection_pool().await;
for member_id in member_ids {
for connection_id in connection_pool.user_connection_ids(member_id) {
session.peer.send(connection_id, update.clone())?;
}
}
response.send(proto::Ack {})?;
Ok(())
}
async fn set_channel_member_role(
request: proto::SetChannelMemberRole,
response: Response<proto::SetChannelMemberRole>,
@ -2391,15 +2423,14 @@ async fn rename_channel(
) -> Result<()> {
let db = session.db().await;
let channel_id = ChannelId::from_proto(request.channel_id);
let new_name = db
let channel = db
.rename_channel(channel_id, session.user_id, &request.name)
.await?;
let channel = proto::Channel {
id: request.channel_id,
name: new_name,
// TODO: Visibility
visibility: proto::ChannelVisibility::ChannelMembers as i32,
id: channel.id.to_proto(),
name: channel.name,
visibility: channel.visibility.into(),
};
response.send(proto::RenameChannelResponse {
channel: Some(channel.clone()),
@ -2437,9 +2468,8 @@ async fn link_channel(
.into_iter()
.map(|channel| proto::Channel {
id: channel.id.to_proto(),
visibility: channel.visibility.into(),
name: channel.name,
// TODO: Visibility
visibility: proto::ChannelVisibility::ChannelMembers as i32,
})
.collect(),
insert_edge: channels_to_send.edges,
@ -2530,9 +2560,8 @@ async fn move_channel(
.into_iter()
.map(|channel| proto::Channel {
id: channel.id.to_proto(),
visibility: channel.visibility.into(),
name: channel.name,
// TODO: Visibility
visibility: proto::ChannelVisibility::ChannelMembers as i32,
})
.collect(),
insert_edge: channels_to_send.edges,
@ -2588,9 +2617,8 @@ async fn respond_to_channel_invite(
.into_iter()
.map(|channel| proto::Channel {
id: channel.id.to_proto(),
visibility: channel.visibility.into(),
name: channel.name,
// TODO: Visibility
visibility: ChannelVisibility::ChannelMembers.into(),
}),
);
update.unseen_channel_messages = result.channel_messages;
@ -3094,8 +3122,7 @@ fn build_initial_channels_update(
update.channels.push(proto::Channel {
id: channel.id.to_proto(),
name: channel.name,
// TODO: Visibility
visibility: ChannelVisibility::Public.into(),
visibility: channel.visibility.into(),
});
}

View file

@ -11,7 +11,10 @@ use collections::HashMap;
use editor::{Anchor, Editor, ToOffset};
use futures::future;
use gpui::{executor::Deterministic, ModelHandle, TestAppContext, ViewContext};
use rpc::{proto::PeerId, RECEIVE_TIMEOUT};
use rpc::{
proto::{self, PeerId},
RECEIVE_TIMEOUT,
};
use serde_json::json;
use std::{ops::Range, sync::Arc};
@ -445,6 +448,7 @@ fn channel(id: u64, name: &'static str) -> Channel {
Channel {
id,
name: name.to_string(),
visibility: proto::ChannelVisibility::Members,
unseen_note_version: None,
unseen_message_id: None,
}