fix(web): prevent invalid owner leave action in group/channel info
Some checks are pending
CI / test (push) Has started running

This commit is contained in:
2026-03-08 22:37:06 +03:00
parent d971e0ac0f
commit 794dcece29
2 changed files with 19 additions and 3 deletions

View File

@@ -92,6 +92,16 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
const canManageMembers = Boolean(isGroupLike && (myRoleNormalized === "owner" || myRoleNormalized === "admin"));
const canEditTitle = Boolean(isGroupLike && (myRoleNormalized === "owner" || myRoleNormalized === "admin"));
const canEditChatProfile = Boolean(isGroupLike && (myRoleNormalized === "owner" || myRoleNormalized === "admin"));
const canLeaveGroupLikeChat = useMemo(() => {
if (!chat || !isGroupLike) {
return false;
}
if (myRoleNormalized !== "owner") {
return true;
}
const count = chat.members_count ?? members.length;
return count <= 1;
}, [chat, isGroupLike, myRoleNormalized, members.length]);
const photoAttachments = useMemo(() => attachments.filter((item) => item.file_type.startsWith("image/")).sort((a, b) => b.id - a.id), [attachments]);
const videoAttachments = useMemo(() => attachments.filter((item) => item.file_type.startsWith("video/")).sort((a, b) => b.id - a.id), [attachments]);
const voiceAttachments = useMemo(() => attachments.filter((item) => item.message_type === "voice").sort((a, b) => b.id - a.id), [attachments]);
@@ -983,8 +993,12 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
</button>
) : null}
<button
className="w-full rounded bg-slate-700 px-3 py-2 text-sm"
className="w-full rounded bg-slate-700 px-3 py-2 text-sm disabled:cursor-not-allowed disabled:opacity-60"
disabled={!canLeaveGroupLikeChat}
onClick={async () => {
if (!canLeaveGroupLikeChat) {
return;
}
try {
await leaveChat(chatId);
await loadChats();
@@ -995,7 +1009,9 @@ export function ChatInfoPanel({ chatId, open, onClose }: Props) {
}
}}
>
{chat.type === "channel" ? "Leave channel" : "Leave chat"}
{canLeaveGroupLikeChat
? (chat.type === "channel" ? "Leave channel" : "Leave chat")
: "Owner cannot leave while members remain"}
</button>
</>
) : null}