Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
861293243c |
@@ -5,6 +5,7 @@ import { StateEvent } from '../../types/matrix/room';
|
|||||||
import { VoiceLimitContent } from '../features/common-settings/general/RoomVoiceLimit';
|
import { VoiceLimitContent } from '../features/common-settings/general/RoomVoiceLimit';
|
||||||
import { useCallMembers, useCallSession } from './useCall';
|
import { useCallMembers, useCallSession } from './useCall';
|
||||||
import { useMatrixClient } from './useMatrixClient';
|
import { useMatrixClient } from './useMatrixClient';
|
||||||
|
import { voiceChannelOccupancy } from '../utils/voiceChannelFull';
|
||||||
|
|
||||||
export type VoiceChannelFull = {
|
export type VoiceChannelFull = {
|
||||||
channelFull: boolean;
|
channelFull: boolean;
|
||||||
@@ -26,9 +27,11 @@ export const useVoiceChannelFull = (room: Room): VoiceChannelFull => {
|
|||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
const maxUsers = limitEvent?.getContent<VoiceLimitContent>().max_users ?? 0;
|
const maxUsers = limitEvent?.getContent<VoiceLimitContent>().max_users ?? 0;
|
||||||
// A user already counted in the session is rejoining and should not be blocked.
|
// Distinct people, not per-device memberships (Gitea #342).
|
||||||
const alreadyMember = callMembers.some((m) => m.sender === mx.getSafeUserId());
|
return voiceChannelOccupancy(
|
||||||
const channelFull = maxUsers > 0 && !alreadyMember && callMembers.length >= maxUsers;
|
callMembers.map((m) => m.sender),
|
||||||
return { channelFull, current: callMembers.length, max: maxUsers };
|
mx.getSafeUserId(),
|
||||||
|
maxUsers,
|
||||||
|
);
|
||||||
}, [limitEvent, callMembers, mx]);
|
}, [limitEvent, callMembers, mx]);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -783,20 +783,15 @@ function ReminderMonitor() {
|
|||||||
const { reminders, removeReminder } = useReminders();
|
const { reminders, removeReminder } = useReminders();
|
||||||
const setToast = useSetAtom(toastQueueAtom);
|
const setToast = useSetAtom(toastQueueAtom);
|
||||||
const mDirects = useAtomValue(mDirectAtom);
|
const mDirects = useAtomValue(mDirectAtom);
|
||||||
const [showNotifications] = useSetting(settingsAtom, 'showNotifications');
|
|
||||||
const quietActive = useNotificationsQuiet();
|
|
||||||
const firedRef = useRef<Set<string>>(new Set());
|
const firedRef = useRef<Set<string>>(new Set());
|
||||||
const removingRef = useRef<Set<string>>(new Set());
|
const removingRef = useRef<Set<string>>(new Set());
|
||||||
// Read the latest reminders / DM map / notification prefs via refs so the poll
|
// Read the latest reminders / DM map via refs so the poll interval below is
|
||||||
// interval below is created once — not torn down and restarted (which resets
|
// created once — not torn down and restarted (which resets its 30s countdown
|
||||||
// its 30s countdown and can indefinitely defer a near-due reminder) on every
|
// and can indefinitely defer a near-due reminder) on every reminder sync (N115).
|
||||||
// reminder sync (N115).
|
|
||||||
const remindersRef = useRef(reminders);
|
const remindersRef = useRef(reminders);
|
||||||
remindersRef.current = reminders;
|
remindersRef.current = reminders;
|
||||||
const mDirectsRef = useRef(mDirects);
|
const mDirectsRef = useRef(mDirects);
|
||||||
mDirectsRef.current = mDirects;
|
mDirectsRef.current = mDirects;
|
||||||
const osNotifyRef = useRef(false);
|
|
||||||
osNotifyRef.current = showNotifications && !quietActive;
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const check = () => {
|
const check = () => {
|
||||||
@@ -820,23 +815,6 @@ function ReminderMonitor() {
|
|||||||
const hashPath = mDirectsRef.current.has(r.roomId)
|
const hashPath = mDirectsRef.current.has(r.roomId)
|
||||||
? getDirectRoomPath(r.roomId, r.eventId)
|
? getDirectRoomPath(r.roomId, r.eventId)
|
||||||
: getHomeRoomPath(r.roomId, r.eventId);
|
: getHomeRoomPath(r.roomId, r.eventId);
|
||||||
// [Gitea #338] A reminder is only done once the user has SEEN it: the
|
|
||||||
// toast stays until clicked or dismissed (it used to vanish after 4 s
|
|
||||||
// and the reminder was deleted at once, so one due while the user was
|
|
||||||
// away was lost). The removal is persisted on that click/dismiss; an
|
|
||||||
// unseen reminder comes back on the next start.
|
|
||||||
const done = () => {
|
|
||||||
if (removingRef.current.has(key)) return;
|
|
||||||
removingRef.current.add(key);
|
|
||||||
removeReminder(r.eventId, r.timestamp).catch(() => {
|
|
||||||
removingRef.current.delete(key);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
const open = () => {
|
|
||||||
done();
|
|
||||||
// window.location.hash setter auto-prepends '#' (as the toast does)
|
|
||||||
window.location.hash = hashPath;
|
|
||||||
};
|
|
||||||
setToast({
|
setToast({
|
||||||
id: `reminder-${key}`,
|
id: `reminder-${key}`,
|
||||||
displayName: 'Reminder',
|
displayName: 'Reminder',
|
||||||
@@ -844,30 +822,16 @@ function ReminderMonitor() {
|
|||||||
roomName,
|
roomName,
|
||||||
roomId: r.roomId,
|
roomId: r.roomId,
|
||||||
hashPath,
|
hashPath,
|
||||||
sticky: true,
|
|
||||||
onClick: open,
|
|
||||||
onDismiss: done,
|
|
||||||
});
|
});
|
||||||
// Away from the window: also raise an OS notification (the reminder is
|
}
|
||||||
// an explicit request, but quiet hours / notifications-off win). Never
|
// Persist the removal, retrying on a later tick if it fails — without
|
||||||
// put decrypted E2EE text in it (N106).
|
// re-showing the toast (N114). The server echo drops it from
|
||||||
if (osNotifyRef.current && notificationPermission('granted') && !document.hasFocus()) {
|
// `reminders` once the write lands.
|
||||||
const encrypted = !!room?.hasEncryptionStateEvent();
|
if (!removingRef.current.has(key)) {
|
||||||
showOsNotification(
|
removingRef.current.add(key);
|
||||||
'Reminder',
|
removeReminder(r.eventId, r.timestamp).catch(() => {
|
||||||
{
|
removingRef.current.delete(key);
|
||||||
icon: LogoSVG,
|
});
|
||||||
badge: LogoSVG,
|
|
||||||
body: encrypted ? `A message in ${roomName}` : body,
|
|
||||||
tag: `reminder-${key}`,
|
|
||||||
data: { path: hashPath, roomId: r.roomId },
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
window.focus();
|
|
||||||
open();
|
|
||||||
},
|
|
||||||
).catch(() => undefined);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { test } from 'node:test';
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import { voiceChannelOccupancy } from './voiceChannelFull';
|
||||||
|
|
||||||
|
test('voiceChannelOccupancy: one user on two devices fills one slot, not two', () => {
|
||||||
|
assert.deepEqual(voiceChannelOccupancy(['@a:x', '@a:x'], '@b:x', 2), {
|
||||||
|
channelFull: false,
|
||||||
|
current: 1,
|
||||||
|
max: 2,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('voiceChannelOccupancy: full when distinct users reach the limit', () => {
|
||||||
|
assert.deepEqual(voiceChannelOccupancy(['@a:x', '@c:x', '@a:x'], '@b:x', 2), {
|
||||||
|
channelFull: true,
|
||||||
|
current: 2,
|
||||||
|
max: 2,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('voiceChannelOccupancy: someone already in the call can always join another device', () => {
|
||||||
|
assert.equal(voiceChannelOccupancy(['@a:x', '@b:x'], '@b:x', 2).channelFull, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('voiceChannelOccupancy: no limit (0) is never full; unknown senders are ignored', () => {
|
||||||
|
assert.equal(voiceChannelOccupancy(['@a:x', '@c:x'], '@b:x', 0).channelFull, false);
|
||||||
|
assert.equal(voiceChannelOccupancy([undefined, '@a:x'], '@b:x', 2).current, 1);
|
||||||
|
});
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/**
|
||||||
|
* [Gitea #342] Whether a voice channel with an `io.lotus.voice_limit` is full.
|
||||||
|
* Counts distinct PEOPLE, not call memberships: a MatrixRTC membership is per
|
||||||
|
* device, so one user on desktop + phone (or with a crashed tab's membership
|
||||||
|
* not yet expired) used to fill two slots. This matches the server-side guard
|
||||||
|
* (matrix `voice-limit-guard.py`, which reduces LiveKit identities to users).
|
||||||
|
*/
|
||||||
|
export type VoiceChannelOccupancy = {
|
||||||
|
channelFull: boolean;
|
||||||
|
/** Distinct users in the call. */
|
||||||
|
current: number;
|
||||||
|
max: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const voiceChannelOccupancy = (
|
||||||
|
memberSenders: Array<string | undefined>,
|
||||||
|
myUserId: string,
|
||||||
|
maxUsers: number,
|
||||||
|
): VoiceChannelOccupancy => {
|
||||||
|
const users = new Set(memberSenders.filter((s): s is string => !!s));
|
||||||
|
// A user already in the call (another device, or rejoining) is never blocked.
|
||||||
|
const alreadyMember = users.has(myUserId);
|
||||||
|
const channelFull = maxUsers > 0 && !alreadyMember && users.size >= maxUsers;
|
||||||
|
return { channelFull, current: users.size, max: maxUsers };
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user