fix(realtime,ui): sync message deletes and channel delete/leave behavior
All checks were successful
CI / test (push) Successful in 23s
All checks were successful
CI / test (push) Successful in 23s
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import { archiveChat, clearChat, createPrivateChat, deleteChat, getChats, getSavedMessagesChat, joinChat, pinChat, unarchiveChat, unpinChat } from "../api/chats";
|
||||
import { archiveChat, clearChat, createPrivateChat, deleteChat, getChats, getSavedMessagesChat, joinChat, leaveChat, pinChat, unarchiveChat, unpinChat } from "../api/chats";
|
||||
import { globalSearch } from "../api/search";
|
||||
import type { DiscoverChat, Message, UserSearchItem } from "../chat/types";
|
||||
import { addContact, addContactByEmail, listContacts, removeContact, updateMyProfile } from "../api/users";
|
||||
@@ -50,7 +50,16 @@ export function ChatList() {
|
||||
const canDeleteForEveryone = Boolean(
|
||||
deleteModalChat &&
|
||||
!deleteModalChat.is_saved &&
|
||||
(deleteModalChat.type === "group" || deleteModalChat.type === "private")
|
||||
(
|
||||
deleteModalChat.type === "group" ||
|
||||
deleteModalChat.type === "private" ||
|
||||
(deleteModalChat.type === "channel" && (deleteModalChat.my_role === "owner" || deleteModalChat.my_role === "admin"))
|
||||
)
|
||||
);
|
||||
const channelMemberLeaveOnly = Boolean(
|
||||
deleteModalChat &&
|
||||
deleteModalChat.type === "channel" &&
|
||||
deleteModalChat.my_role === "member"
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -598,7 +607,13 @@ export function ChatList() {
|
||||
setDeleteForAll(false);
|
||||
}}
|
||||
>
|
||||
{chats.find((c) => c.id === ctxChatId)?.is_saved ? "Clear chat" : "Delete chat"}
|
||||
{(() => {
|
||||
const chat = chats.find((c) => c.id === ctxChatId);
|
||||
if (!chat) return "Delete chat";
|
||||
if (chat.is_saved) return "Clear chat";
|
||||
if (chat.type === "channel" && chat.my_role === "member") return "Leave channel";
|
||||
return "Delete chat";
|
||||
})()}
|
||||
</button>
|
||||
<button
|
||||
className="block w-full rounded px-2 py-1.5 text-left text-sm hover:bg-slate-800"
|
||||
@@ -653,10 +668,19 @@ export function ChatList() {
|
||||
<div className="absolute inset-0 z-50 flex items-end justify-center bg-slate-950/55 p-3">
|
||||
<div className="w-full rounded-xl border border-slate-700/80 bg-slate-900 p-3">
|
||||
<p className="mb-2 text-sm font-semibold">
|
||||
{deleteModalChat?.is_saved ? "Clear chat" : "Delete chat"}: {deleteModalChat ? chatLabel(deleteModalChat) : "selected chat"}
|
||||
{(deleteModalChat?.is_saved
|
||||
? "Clear chat"
|
||||
: deleteModalChat?.type === "channel" && deleteModalChat.my_role === "member"
|
||||
? "Leave channel"
|
||||
: "Delete chat")}
|
||||
: {deleteModalChat ? chatLabel(deleteModalChat) : "selected chat"}
|
||||
</p>
|
||||
{deleteModalChat?.type === "channel" ? (
|
||||
<p className="mb-3 text-xs text-slate-400">Channels are removed for all subscribers.</p>
|
||||
<p className="mb-3 text-xs text-slate-400">
|
||||
{channelMemberLeaveOnly
|
||||
? "You will leave this channel."
|
||||
: "Channel deletion removes it for all subscribers."}
|
||||
</p>
|
||||
) : null}
|
||||
{deleteModalChat?.is_saved ? (
|
||||
<p className="mb-3 text-xs text-slate-400">This will clear all messages in Saved Messages.</p>
|
||||
@@ -677,7 +701,11 @@ export function ChatList() {
|
||||
setDeleteModalChatId(null);
|
||||
return;
|
||||
}
|
||||
await deleteChat(deleteModalChatId, canDeleteForEveryone && deleteForAll);
|
||||
if (channelMemberLeaveOnly) {
|
||||
await leaveChat(deleteModalChatId);
|
||||
} else {
|
||||
await deleteChat(deleteModalChatId, canDeleteForEveryone && deleteForAll);
|
||||
}
|
||||
await loadChats();
|
||||
if (activeChatId === deleteModalChatId) {
|
||||
setActiveChatId(null);
|
||||
@@ -685,7 +713,7 @@ export function ChatList() {
|
||||
setDeleteModalChatId(null);
|
||||
}}
|
||||
>
|
||||
{deleteModalChat?.is_saved ? "Clear" : "Delete"}
|
||||
{deleteModalChat?.is_saved ? "Clear" : channelMemberLeaveOnly ? "Leave" : "Delete"}
|
||||
</button>
|
||||
<button className="flex-1 rounded bg-slate-700 px-3 py-2 text-sm" onClick={() => setDeleteModalChatId(null)}>
|
||||
Cancel
|
||||
|
||||
Reference in New Issue
Block a user