Format
This commit is contained in:
parent
adb6f3e9f7
commit
fbdca993ff
3 changed files with 56 additions and 64 deletions
|
@ -19,10 +19,7 @@ impl Database {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub async fn create_root_channel(&self, name: &str, creator_id: UserId) -> Result<ChannelId> {
|
pub async fn create_root_channel(&self, name: &str, creator_id: UserId) -> Result<ChannelId> {
|
||||||
Ok(self
|
Ok(self.create_channel(name, None, creator_id).await?.id)
|
||||||
.create_channel(name, None, creator_id)
|
|
||||||
.await?
|
|
||||||
.id)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -18,13 +18,9 @@ async fn test_channel_message_retrieval(db: &Arc<Database>) {
|
||||||
let channel = db.create_channel("channel", None, user).await.unwrap();
|
let channel = db.create_channel("channel", None, user).await.unwrap();
|
||||||
|
|
||||||
let owner_id = db.create_server("test").await.unwrap().0 as u32;
|
let owner_id = db.create_server("test").await.unwrap().0 as u32;
|
||||||
db.join_channel_chat(
|
db.join_channel_chat(channel.id, rpc::ConnectionId { owner_id, id: 0 }, user)
|
||||||
channel.id,
|
.await
|
||||||
rpc::ConnectionId { owner_id, id: 0 },
|
.unwrap();
|
||||||
user,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut all_messages = Vec::new();
|
let mut all_messages = Vec::new();
|
||||||
for i in 0..10 {
|
for i in 0..10 {
|
||||||
|
@ -366,11 +362,7 @@ async fn test_channel_message_mentions(db: &Arc<Database>) {
|
||||||
let user_b = new_test_user(db, "user_b@example.com").await;
|
let user_b = new_test_user(db, "user_b@example.com").await;
|
||||||
let user_c = new_test_user(db, "user_c@example.com").await;
|
let user_c = new_test_user(db, "user_c@example.com").await;
|
||||||
|
|
||||||
let channel = db
|
let channel = db.create_channel("channel", None, user_a).await.unwrap().id;
|
||||||
.create_channel("channel", None, user_a)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.id;
|
|
||||||
db.invite_channel_member(channel, user_b, user_a, ChannelRole::Member)
|
db.invite_channel_member(channel, user_b, user_a, ChannelRole::Member)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -3,11 +3,10 @@ mod connection_pool;
|
||||||
use crate::{
|
use crate::{
|
||||||
auth::{self, Impersonator},
|
auth::{self, Impersonator},
|
||||||
db::{
|
db::{
|
||||||
self, BufferId, ChannelId, ChannelRole, ChannelsForUser,
|
self, BufferId, ChannelId, ChannelRole, ChannelsForUser, CreatedChannelMessage, Database,
|
||||||
CreatedChannelMessage, Database, InviteMemberResult, MembershipUpdated, MessageId,
|
InviteMemberResult, MembershipUpdated, MessageId, NotificationId, ProjectId,
|
||||||
NotificationId, ProjectId, RemoveChannelMemberResult,
|
RemoveChannelMemberResult, RenameChannelResult, RespondToChannelInvite, RoomId, ServerId,
|
||||||
RenameChannelResult, RespondToChannelInvite, RoomId, ServerId, SetChannelVisibilityResult,
|
SetChannelVisibilityResult, User, UserId,
|
||||||
User, UserId,
|
|
||||||
},
|
},
|
||||||
executor::Executor,
|
executor::Executor,
|
||||||
AppState, Error, Result,
|
AppState, Error, Result,
|
||||||
|
@ -2570,53 +2569,57 @@ async fn move_channel(
|
||||||
let channel_id = ChannelId::from_proto(request.channel_id);
|
let channel_id = ChannelId::from_proto(request.channel_id);
|
||||||
let to = request.to.map(ChannelId::from_proto);
|
let to = request.to.map(ChannelId::from_proto);
|
||||||
|
|
||||||
let result = session.db().await.move_channel(channel_id, to, session.user_id).await?;
|
let result = session
|
||||||
|
.db()
|
||||||
|
.await
|
||||||
|
.move_channel(channel_id, to, session.user_id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
if let Some(result) = result {
|
if let Some(result) = result {
|
||||||
let participants_to_update: HashMap<_, _> = session.db().await
|
let participants_to_update: HashMap<_, _> = session
|
||||||
.new_participants_to_notify(
|
.db()
|
||||||
to.unwrap_or(channel_id)
|
.await
|
||||||
)
|
.new_participants_to_notify(to.unwrap_or(channel_id))
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut moved_channels: HashSet<ChannelId> = HashSet::default();
|
let mut moved_channels: HashSet<ChannelId> = HashSet::default();
|
||||||
for id in result.descendent_ids {
|
for id in result.descendent_ids {
|
||||||
moved_channels.insert(id);
|
moved_channels.insert(id);
|
||||||
}
|
|
||||||
moved_channels.insert(channel_id);
|
|
||||||
|
|
||||||
let mut participants_to_remove: HashSet<UserId> = HashSet::default();
|
|
||||||
for participant in result.previous_participants {
|
|
||||||
if participant.kind == proto::channel_member::Kind::AncestorMember {
|
|
||||||
if !participants_to_update.contains_key(&participant.user_id) {
|
|
||||||
participants_to_remove.insert(participant.user_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let moved_channels: Vec<u64> = moved_channels.iter().map(|id| id.to_proto()).collect();
|
|
||||||
|
|
||||||
let connection_pool = session.connection_pool().await;
|
|
||||||
for (user_id, channels) in participants_to_update {
|
|
||||||
let mut update = build_channels_update(channels, vec![]);
|
|
||||||
update.delete_channels = moved_channels.clone();
|
|
||||||
for connection_id in connection_pool.user_connection_ids(user_id) {
|
|
||||||
session.peer.send(connection_id, update.clone())?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for user_id in participants_to_remove {
|
|
||||||
let update = proto::UpdateChannels {
|
|
||||||
delete_channels: moved_channels.clone(),
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
for connection_id in connection_pool.user_connection_ids(user_id) {
|
|
||||||
session.peer.send(connection_id, update.clone())?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
moved_channels.insert(channel_id);
|
||||||
|
|
||||||
|
let mut participants_to_remove: HashSet<UserId> = HashSet::default();
|
||||||
|
for participant in result.previous_participants {
|
||||||
|
if participant.kind == proto::channel_member::Kind::AncestorMember {
|
||||||
|
if !participants_to_update.contains_key(&participant.user_id) {
|
||||||
|
participants_to_remove.insert(participant.user_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let moved_channels: Vec<u64> = moved_channels.iter().map(|id| id.to_proto()).collect();
|
||||||
|
|
||||||
|
let connection_pool = session.connection_pool().await;
|
||||||
|
for (user_id, channels) in participants_to_update {
|
||||||
|
let mut update = build_channels_update(channels, vec![]);
|
||||||
|
update.delete_channels = moved_channels.clone();
|
||||||
|
for connection_id in connection_pool.user_connection_ids(user_id) {
|
||||||
|
session.peer.send(connection_id, update.clone())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for user_id in participants_to_remove {
|
||||||
|
let update = proto::UpdateChannels {
|
||||||
|
delete_channels: moved_channels.clone(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
for connection_id in connection_pool.user_connection_ids(user_id) {
|
||||||
|
session.peer.send(connection_id, update.clone())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response.send(Ack {})?;
|
response.send(Ack {})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue