2026-09-12 19:46:06 -04:00
|
|
|
import { Room } from 'matrix-js-sdk';
|
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
import { useStateEvent } from './useStateEvent';
|
|
|
|
|
import { StateEvent } from '../../types/matrix/room';
|
|
|
|
|
import { VoiceLimitContent } from '../features/common-settings/general/RoomVoiceLimit';
|
|
|
|
|
import { useCallMembers, useCallSession } from './useCall';
|
|
|
|
|
import { useMatrixClient } from './useMatrixClient';
|
2026-10-11 22:07:18 -04:00
|
|
|
import { voiceChannelOccupancy } from '../utils/voiceChannelFull';
|
2026-09-12 19:46:06 -04:00
|
|
|
|
|
|
|
|
export type VoiceChannelFull = {
|
|
|
|
|
channelFull: boolean;
|
|
|
|
|
current: number;
|
|
|
|
|
max: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [Gitea #30] Voice channel user limit (`io.lotus.voice_limit`), shared between
|
|
|
|
|
* `CallPrescreen` and any other join path (e.g. the room-nav second-click join)
|
|
|
|
|
* so they agree on when a channel is full. 0/absent `max_users` means no limit.
|
|
|
|
|
*/
|
|
|
|
|
export const useVoiceChannelFull = (room: Room): VoiceChannelFull => {
|
|
|
|
|
const mx = useMatrixClient();
|
|
|
|
|
const callSession = useCallSession(room);
|
|
|
|
|
const callMembers = useCallMembers(callSession);
|
|
|
|
|
|
|
|
|
|
const limitEvent = useStateEvent(room, StateEvent.LotusVoiceLimit);
|
|
|
|
|
|
|
|
|
|
return useMemo(() => {
|
|
|
|
|
const maxUsers = limitEvent?.getContent<VoiceLimitContent>().max_users ?? 0;
|
2026-10-11 22:07:18 -04:00
|
|
|
// Distinct people, not per-device memberships (Gitea #342).
|
|
|
|
|
return voiceChannelOccupancy(
|
|
|
|
|
callMembers.map((m) => m.sender),
|
|
|
|
|
mx.getSafeUserId(),
|
|
|
|
|
maxUsers,
|
|
|
|
|
);
|
2026-09-12 19:46:06 -04:00
|
|
|
}, [limitEvent, callMembers, mx]);
|
|
|
|
|
};
|