mirror of
https://github.com/zed-industries/zed.git
synced 2024-11-08 07:35:01 +03:00
Minor adjustments
This commit is contained in:
parent
6ffbc3a0f5
commit
465d726bd4
@ -3,4 +3,4 @@ xtask = "run --package xtask --"
|
|||||||
|
|
||||||
[build]
|
[build]
|
||||||
# v0 mangling scheme provides more detailed backtraces around closures
|
# v0 mangling scheme provides more detailed backtraces around closures
|
||||||
rustflags = ["-C", "symbol-mangling-version=v0", "-C", "link-arg=-fuse-ld=/opt/homebrew/Cellar/llvm/16.0.6/bin/ld64.lld"]
|
rustflags = ["-C", "symbol-mangling-version=v0"]
|
||||||
|
@ -972,7 +972,6 @@ impl ChannelStore {
|
|||||||
|
|
||||||
let mut all_user_ids = Vec::new();
|
let mut all_user_ids = Vec::new();
|
||||||
let channel_participants = payload.channel_participants;
|
let channel_participants = payload.channel_participants;
|
||||||
dbg!(&channel_participants);
|
|
||||||
for entry in &channel_participants {
|
for entry in &channel_participants {
|
||||||
for user_id in entry.participant_user_ids.iter() {
|
for user_id in entry.participant_user_ids.iter() {
|
||||||
if let Err(ix) = all_user_ids.binary_search(user_id) {
|
if let Err(ix) = all_user_ids.binary_search(user_id) {
|
||||||
|
@ -123,8 +123,9 @@ impl<'a> ChannelPathsInsertGuard<'a> {
|
|||||||
|
|
||||||
pub fn insert(&mut self, channel_proto: proto::Channel) {
|
pub fn insert(&mut self, channel_proto: proto::Channel) {
|
||||||
if let Some(existing_channel) = self.channels_by_id.get_mut(&channel_proto.id) {
|
if let Some(existing_channel) = self.channels_by_id.get_mut(&channel_proto.id) {
|
||||||
Arc::make_mut(existing_channel).visibility = channel_proto.visibility();
|
let existing_channel = Arc::make_mut(existing_channel);
|
||||||
Arc::make_mut(existing_channel).name = channel_proto.name;
|
existing_channel.visibility = channel_proto.visibility();
|
||||||
|
existing_channel.name = channel_proto.name;
|
||||||
} else {
|
} else {
|
||||||
self.channels_by_id.insert(
|
self.channels_by_id.insert(
|
||||||
channel_proto.id,
|
channel_proto.id,
|
||||||
|
@ -106,6 +106,15 @@ impl ChannelRole {
|
|||||||
Guest => false,
|
Guest => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn max(&self, other: Self) -> Self {
|
||||||
|
match (self, other) {
|
||||||
|
(ChannelRole::Admin, _) | (_, ChannelRole::Admin) => ChannelRole::Admin,
|
||||||
|
(ChannelRole::Member, _) | (_, ChannelRole::Member) => ChannelRole::Member,
|
||||||
|
(ChannelRole::Banned, _) | (_, ChannelRole::Banned) => ChannelRole::Banned,
|
||||||
|
(ChannelRole::Guest, _) | (_, ChannelRole::Guest) => ChannelRole::Guest,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<proto::ChannelRole> for ChannelRole {
|
impl From<proto::ChannelRole> for ChannelRole {
|
||||||
|
@ -209,7 +209,7 @@ impl Database {
|
|||||||
let mut channels_to_remove: HashSet<ChannelId> = HashSet::default();
|
let mut channels_to_remove: HashSet<ChannelId> = HashSet::default();
|
||||||
channels_to_remove.insert(channel_id);
|
channels_to_remove.insert(channel_id);
|
||||||
|
|
||||||
let graph = self.get_channel_descendants_2([channel_id], &*tx).await?;
|
let graph = self.get_channel_descendants([channel_id], &*tx).await?;
|
||||||
for edge in graph.iter() {
|
for edge in graph.iter() {
|
||||||
channels_to_remove.insert(ChannelId::from_proto(edge.channel_id));
|
channels_to_remove.insert(ChannelId::from_proto(edge.channel_id));
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ impl Database {
|
|||||||
let mut channels_to_keep = channel_path::Entity::find()
|
let mut channels_to_keep = channel_path::Entity::find()
|
||||||
.filter(
|
.filter(
|
||||||
channel_path::Column::ChannelId
|
channel_path::Column::ChannelId
|
||||||
.is_in(channels_to_remove.clone())
|
.is_in(channels_to_remove.iter().copied())
|
||||||
.and(
|
.and(
|
||||||
channel_path::Column::IdPath
|
channel_path::Column::IdPath
|
||||||
.not_like(&format!("%/{}/%", channel_id)),
|
.not_like(&format!("%/{}/%", channel_id)),
|
||||||
@ -243,7 +243,7 @@ impl Database {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
channel::Entity::delete_many()
|
channel::Entity::delete_many()
|
||||||
.filter(channel::Column::Id.is_in(channels_to_remove.clone()))
|
.filter(channel::Column::Id.is_in(channels_to_remove.iter().copied()))
|
||||||
.exec(&*tx)
|
.exec(&*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -484,7 +484,7 @@ impl Database {
|
|||||||
tx: &DatabaseTransaction,
|
tx: &DatabaseTransaction,
|
||||||
) -> Result<ChannelsForUser> {
|
) -> Result<ChannelsForUser> {
|
||||||
let mut edges = self
|
let mut edges = self
|
||||||
.get_channel_descendants_2(channel_memberships.iter().map(|m| m.channel_id), &*tx)
|
.get_channel_descendants(channel_memberships.iter().map(|m| m.channel_id), &*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut role_for_channel: HashMap<ChannelId, ChannelRole> = HashMap::default();
|
let mut role_for_channel: HashMap<ChannelId, ChannelRole> = HashMap::default();
|
||||||
@ -515,7 +515,7 @@ impl Database {
|
|||||||
let mut channels_to_remove: HashSet<u64> = HashSet::default();
|
let mut channels_to_remove: HashSet<u64> = HashSet::default();
|
||||||
|
|
||||||
let mut rows = channel::Entity::find()
|
let mut rows = channel::Entity::find()
|
||||||
.filter(channel::Column::Id.is_in(role_for_channel.keys().cloned()))
|
.filter(channel::Column::Id.is_in(role_for_channel.keys().copied()))
|
||||||
.stream(&*tx)
|
.stream(&*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
@ -877,7 +877,7 @@ impl Database {
|
|||||||
let channel_ids = self.get_channel_ancestors(channel_id, tx).await?;
|
let channel_ids = self.get_channel_ancestors(channel_id, tx).await?;
|
||||||
|
|
||||||
let rows = channel::Entity::find()
|
let rows = channel::Entity::find()
|
||||||
.filter(channel::Column::Id.is_in(channel_ids.clone()))
|
.filter(channel::Column::Id.is_in(channel_ids.iter().copied()))
|
||||||
.filter(channel::Column::Visibility.eq(ChannelVisibility::Public))
|
.filter(channel::Column::Visibility.eq(ChannelVisibility::Public))
|
||||||
.all(&*tx)
|
.all(&*tx)
|
||||||
.await?;
|
.await?;
|
||||||
@ -928,40 +928,39 @@ impl Database {
|
|||||||
.stream(&*tx)
|
.stream(&*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut is_admin = false;
|
let mut user_role: Option<ChannelRole> = None;
|
||||||
let mut is_member = false;
|
let max_role = |role| {
|
||||||
|
user_role
|
||||||
|
.map(|user_role| user_role.max(role))
|
||||||
|
.get_or_insert(role);
|
||||||
|
};
|
||||||
|
|
||||||
let mut is_participant = false;
|
let mut is_participant = false;
|
||||||
let mut is_banned = false;
|
|
||||||
let mut current_channel_visibility = None;
|
let mut current_channel_visibility = None;
|
||||||
|
|
||||||
// note these channels are not iterated in any particular order,
|
// note these channels are not iterated in any particular order,
|
||||||
// our current logic takes the highest permission available.
|
// our current logic takes the highest permission available.
|
||||||
while let Some(row) = rows.next().await {
|
while let Some(row) = rows.next().await {
|
||||||
let (ch_id, role, visibility): (ChannelId, ChannelRole, ChannelVisibility) = row?;
|
let (membership_channel, role, visibility): (
|
||||||
|
ChannelId,
|
||||||
|
ChannelRole,
|
||||||
|
ChannelVisibility,
|
||||||
|
) = row?;
|
||||||
match role {
|
match role {
|
||||||
ChannelRole::Admin => is_admin = true,
|
ChannelRole::Admin | ChannelRole::Member | ChannelRole::Banned => max_role(role),
|
||||||
ChannelRole::Member => is_member = true,
|
ChannelRole::Guest if visibility == ChannelVisibility::Public => {
|
||||||
ChannelRole::Guest => {
|
is_participant = true
|
||||||
if visibility == ChannelVisibility::Public {
|
|
||||||
is_participant = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ChannelRole::Banned => is_banned = true,
|
ChannelRole::Guest => {}
|
||||||
}
|
}
|
||||||
if channel_id == ch_id {
|
if channel_id == membership_channel {
|
||||||
current_channel_visibility = Some(visibility);
|
current_channel_visibility = Some(visibility);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// free up database connection
|
// free up database connection
|
||||||
drop(rows);
|
drop(rows);
|
||||||
|
|
||||||
Ok(if is_admin {
|
if is_participant && user_role.is_none() {
|
||||||
Some(ChannelRole::Admin)
|
|
||||||
} else if is_member {
|
|
||||||
Some(ChannelRole::Member)
|
|
||||||
} else if is_banned {
|
|
||||||
Some(ChannelRole::Banned)
|
|
||||||
} else if is_participant {
|
|
||||||
if current_channel_visibility.is_none() {
|
if current_channel_visibility.is_none() {
|
||||||
current_channel_visibility = channel::Entity::find()
|
current_channel_visibility = channel::Entity::find()
|
||||||
.filter(channel::Column::Id.eq(channel_id))
|
.filter(channel::Column::Id.eq(channel_id))
|
||||||
@ -970,13 +969,11 @@ impl Database {
|
|||||||
.map(|channel| channel.visibility);
|
.map(|channel| channel.visibility);
|
||||||
}
|
}
|
||||||
if current_channel_visibility == Some(ChannelVisibility::Public) {
|
if current_channel_visibility == Some(ChannelVisibility::Public) {
|
||||||
Some(ChannelRole::Guest)
|
user_role = Some(ChannelRole::Guest);
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
None
|
|
||||||
})
|
Ok(user_role)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the channel ancestors in arbitrary order
|
/// Returns the channel ancestors in arbitrary order
|
||||||
@ -1007,7 +1004,7 @@ impl Database {
|
|||||||
// Returns the channel desendants as a sorted list of edges for further processing.
|
// Returns the channel desendants as a sorted list of edges for further processing.
|
||||||
// The edges are sorted such that you will see unknown channel ids as children
|
// The edges are sorted such that you will see unknown channel ids as children
|
||||||
// before you see them as parents.
|
// before you see them as parents.
|
||||||
async fn get_channel_descendants_2(
|
async fn get_channel_descendants(
|
||||||
&self,
|
&self,
|
||||||
channel_ids: impl IntoIterator<Item = ChannelId>,
|
channel_ids: impl IntoIterator<Item = ChannelId>,
|
||||||
tx: &DatabaseTransaction,
|
tx: &DatabaseTransaction,
|
||||||
|
Loading…
Reference in New Issue
Block a user