fix(permissions): wire up MUTE_MEMBERS bitmask and fix member permissions in frontend
This commit is contained in:
@@ -4,6 +4,7 @@ import { useAuthStore } from "../stores/auth.ts";
|
||||
import { useMemberStore, type Member } from "../stores/member.ts";
|
||||
import { usePresenceStore } from "../stores/presence.ts";
|
||||
import type { UserStatus } from "../stores/auth.ts";
|
||||
import { usePermissions } from "../lib/usePermissions.ts";
|
||||
import { MemberContextMenu } from "./MemberContextMenu.tsx";
|
||||
import { useConversationStore } from "../stores/conversation.ts";
|
||||
import { useLayoutStore } from "../stores/layout.ts";
|
||||
@@ -59,16 +60,13 @@ function MemberRow({ member, onProfileClick }: MemberRowProps) {
|
||||
const status = presence?.status ?? member.status;
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const currentUser = useAuthStore((s) => s.user);
|
||||
const userPerms = useServerStore((s) => s.userPermissions);
|
||||
const activeServerId = useServerStore((s) => s.activeServerId);
|
||||
const setActiveServer = useServerStore((s) => s.setActiveServer);
|
||||
const createConversation = useConversationStore((s) => s.createConversation);
|
||||
const setDM = useLayoutStore((s) => s.setDM);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const canKick = userPerms?.kick_members ?? false;
|
||||
const canBan = userPerms?.ban_members ?? false;
|
||||
const canMute = userPerms?.mute_members ?? false;
|
||||
const { canKick, canBan, canMute } = usePermissions(activeServerId);
|
||||
const isSelf = currentUser?.id === member.id;
|
||||
|
||||
return (
|
||||
|
||||
@@ -5,6 +5,8 @@ import { api } from '../lib/api.ts';
|
||||
import { VoiceControls } from './VoiceControls.tsx';
|
||||
import { VideoGrid } from './VideoGrid.tsx';
|
||||
import { AudioRenderers } from './AudioRenderers.tsx';
|
||||
import { usePermissions } from '../lib/usePermissions.ts';
|
||||
import { useChannelStore } from '../stores/channel.ts';
|
||||
|
||||
export function VoicePanel() {
|
||||
const isConnected = useVoiceStore((state) => state.isConnected);
|
||||
@@ -17,8 +19,15 @@ export function VoicePanel() {
|
||||
const dismissWhisper = useVoiceStore((state) => state.dismissWhisper);
|
||||
const currentUserId = useAuthStore((state) => state.user?.id);
|
||||
|
||||
const userPermissions = useServerStore((state) => state.userPermissions);
|
||||
const canMute = userPermissions.mute_members || userPermissions.administrator;
|
||||
const activeChannelId = useChannelStore((s) => s.activeChannelId);
|
||||
const channelsByServer = useChannelStore((s) => s.channelsByServer);
|
||||
const activeServerId = useServerStore((s) => s.activeServerId);
|
||||
|
||||
const serverId = activeChannelId
|
||||
? Object.entries(channelsByServer).find(([_, channels]) => channels.some(c => c.id === activeChannelId))?.[0]
|
||||
: null;
|
||||
|
||||
const { canMute } = usePermissions(serverId || activeServerId);
|
||||
|
||||
const handleMute = async (identity: string) => {
|
||||
if (!currentRoom) return;
|
||||
|
||||
@@ -15,6 +15,7 @@ const PERMS = {
|
||||
CONNECT_VOICE: 256,
|
||||
SPEAK_VOICE: 512,
|
||||
SHARE_SCREEN: 1024,
|
||||
MUTE_MEMBERS: 2048,
|
||||
CHANGE_NICKNAME: 8192,
|
||||
MANAGE_NICKNAMES: 16384,
|
||||
MANAGE_ROLES: 32768,
|
||||
@@ -46,7 +47,7 @@ export function usePermissions(serverId: string | null) {
|
||||
return {
|
||||
canKick: has(PERMS.KICK_MEMBERS),
|
||||
canBan: has(PERMS.BAN_MEMBERS),
|
||||
canMute: has(PERMS.MANAGE_MESSAGES),
|
||||
canMute: has(PERMS.MUTE_MEMBERS),
|
||||
canManageChannels: has(PERMS.MANAGE_CHANNELS),
|
||||
canManageRoles: has(PERMS.MANAGE_ROLES),
|
||||
canManageServer: has(PERMS.MANAGE_SERVER),
|
||||
|
||||
Reference in New Issue
Block a user