mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-24 17:28:40 +00:00
Adjust chat permisisons to allow deletion for channel admins
This commit is contained in:
parent
b168bded1d
commit
162f625716
2 changed files with 28 additions and 8 deletions
|
@ -337,8 +337,22 @@ impl Database {
|
||||||
.filter(channel_message::Column::SenderId.eq(user_id))
|
.filter(channel_message::Column::SenderId.eq(user_id))
|
||||||
.exec(&*tx)
|
.exec(&*tx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if result.rows_affected == 0 {
|
if result.rows_affected == 0 {
|
||||||
Err(anyhow!("no such message"))?;
|
if self
|
||||||
|
.check_user_is_channel_admin(channel_id, user_id, &*tx)
|
||||||
|
.await
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
let result = channel_message::Entity::delete_by_id(message_id)
|
||||||
|
.exec(&*tx)
|
||||||
|
.await?;
|
||||||
|
if result.rows_affected == 0 {
|
||||||
|
Err(anyhow!("no such message"))?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(anyhow!("operation could not be completed"))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(participant_connection_ids)
|
Ok(participant_connection_ids)
|
||||||
|
|
|
@ -355,8 +355,12 @@ impl ChatPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_message(&mut self, ix: usize, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
fn render_message(&mut self, ix: usize, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||||
let (message, is_continuation, is_last) = {
|
let (message, is_continuation, is_last, is_admin) = {
|
||||||
let active_chat = self.active_chat.as_ref().unwrap().0.read(cx);
|
let active_chat = self.active_chat.as_ref().unwrap().0.read(cx);
|
||||||
|
let is_admin = self
|
||||||
|
.channel_store
|
||||||
|
.read(cx)
|
||||||
|
.is_user_admin(active_chat.channel().id);
|
||||||
let last_message = active_chat.message(ix.saturating_sub(1));
|
let last_message = active_chat.message(ix.saturating_sub(1));
|
||||||
let this_message = active_chat.message(ix);
|
let this_message = active_chat.message(ix);
|
||||||
let is_continuation = last_message.id != this_message.id
|
let is_continuation = last_message.id != this_message.id
|
||||||
|
@ -366,6 +370,7 @@ impl ChatPanel {
|
||||||
active_chat.message(ix).clone(),
|
active_chat.message(ix).clone(),
|
||||||
is_continuation,
|
is_continuation,
|
||||||
active_chat.message_count() == ix + 1,
|
active_chat.message_count() == ix + 1,
|
||||||
|
is_admin,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -386,12 +391,13 @@ impl ChatPanel {
|
||||||
};
|
};
|
||||||
|
|
||||||
let belongs_to_user = Some(message.sender.id) == self.client.user_id();
|
let belongs_to_user = Some(message.sender.id) == self.client.user_id();
|
||||||
let message_id_to_remove =
|
let message_id_to_remove = if let (ChannelMessageId::Saved(id), true) =
|
||||||
if let (ChannelMessageId::Saved(id), true) = (message.id, belongs_to_user) {
|
(message.id, belongs_to_user || is_admin)
|
||||||
Some(id)
|
{
|
||||||
} else {
|
Some(id)
|
||||||
None
|
} else {
|
||||||
};
|
None
|
||||||
|
};
|
||||||
|
|
||||||
enum MessageBackgroundHighlight {}
|
enum MessageBackgroundHighlight {}
|
||||||
MouseEventHandler::new::<MessageBackgroundHighlight, _>(ix, cx, |state, cx| {
|
MouseEventHandler::new::<MessageBackgroundHighlight, _>(ix, cx, |state, cx| {
|
||||||
|
|
Loading…
Reference in a new issue