Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02950499ea |
@@ -18,10 +18,8 @@ import {
|
||||
toRem,
|
||||
} from 'folds';
|
||||
import {
|
||||
ClientEvent,
|
||||
EventTimelineSetHandlerMap,
|
||||
EventType,
|
||||
SyncState,
|
||||
RelationType,
|
||||
Room,
|
||||
RoomEvent,
|
||||
@@ -74,7 +72,7 @@ import { useSetting } from '../state/hooks/settings';
|
||||
import { useCallPreferences } from '../state/hooks/callPreferences';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import { getStateEvent, getMemberName } from '../utils/room';
|
||||
import { declinedRing, hasActiveCallMembership, isRingableRoom } from '../utils/callRing';
|
||||
import { isRingableRoom } from '../utils/callRing';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { getPowersLevelFromMatrixEvent } from '../hooks/usePowerLevels';
|
||||
import { getRoomCreatorsForRoomId } from '../hooks/useRoomCreators';
|
||||
@@ -598,50 +596,11 @@ function IncomingCallListener({ callEmbed, joined }: IncomingCallListenerProps)
|
||||
refEventId,
|
||||
};
|
||||
|
||||
// [Gitea #312] Don't ring for a call that is already over or handled: after
|
||||
// a reload the first sync replays the ring together with the caller's
|
||||
// hang-up and our own decline. Check the room STATE (not the possibly
|
||||
// stale RTC session). The caller's membership can arrive just after the
|
||||
// ring, so an absent one gets a short grace period before giving up.
|
||||
const myUserId = mx.getSafeUserId();
|
||||
if (declinedRing(room, refEventId, myUserId) || hasActiveCallMembership(room, myUserId)) {
|
||||
return;
|
||||
}
|
||||
if (hasActiveCallMembership(room, sender)) {
|
||||
setCallInfo(info);
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (Date.now() >= senderTs + lifetime) return;
|
||||
if (declinedRing(room, refEventId, myUserId) || hasActiveCallMembership(room, myUserId)) {
|
||||
return;
|
||||
}
|
||||
if (hasActiveCallMembership(room, sender)) setCallInfo(info);
|
||||
}, 4000);
|
||||
setCallInfo(info);
|
||||
},
|
||||
[mx, directs, callEmbed, setToast],
|
||||
);
|
||||
|
||||
// [Gitea #312] A catch-up sync (after a reload or reconnect) can replay a
|
||||
// call's join and leave in one batch, and the RTC session may keep the join
|
||||
// (stale "1 Live", call screen instead of chat). Once sync is live again,
|
||||
// recompute every active session from the room's current state.
|
||||
useEffect(() => {
|
||||
const onSync = (state: SyncState, prev: SyncState | null) => {
|
||||
if (state !== SyncState.Syncing || prev === SyncState.Syncing) return;
|
||||
mx.getRooms().forEach((r) => {
|
||||
mx.matrixRTC
|
||||
.getActiveRoomSession(r)
|
||||
?._onRTCSessionMemberUpdate()
|
||||
.catch(() => undefined);
|
||||
});
|
||||
};
|
||||
mx.on(ClientEvent.Sync, onSync);
|
||||
return () => {
|
||||
mx.removeListener(ClientEvent.Sync, onSync);
|
||||
};
|
||||
}, [mx]);
|
||||
|
||||
useEffect(() => {
|
||||
mx.on(RoomEvent.Timeline, handleTimelineEvent);
|
||||
return () => {
|
||||
@@ -670,10 +629,7 @@ function IncomingCallListener({ callEmbed, joined }: IncomingCallListenerProps)
|
||||
const { memberships } = session;
|
||||
if (memberships.some((m) => m.sender === myUserId))
|
||||
dismiss(); // answered elsewhere
|
||||
else if (memberships.length === 0)
|
||||
dismiss(); // caller gone
|
||||
// [Gitea #312] The session can be stale after a reload; the room state isn't.
|
||||
else if (!hasActiveCallMembership(room, callInfo.sender)) dismiss();
|
||||
else if (memberships.length === 0) dismiss(); // caller gone
|
||||
};
|
||||
const onTimeline: EventTimelineSetHandlerMap[RoomEvent.Timeline] = (
|
||||
event,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import type { Room } from 'matrix-js-sdk';
|
||||
import { declinedRing, hasActiveCallMembership, isRingableRoom } from './callRing';
|
||||
import { isRingableRoom } from './callRing';
|
||||
|
||||
const fakeRoom = (opts: { callRoom?: boolean; joinRule?: string; spaceParent?: boolean }): Room =>
|
||||
({
|
||||
@@ -27,43 +27,3 @@ test('space channels, public and restricted rooms do not ring', () => {
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'public' }), false), false);
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'restricted' }), false), false);
|
||||
});
|
||||
|
||||
const stateRoom = (
|
||||
members: Array<{ sender: string; content: Record<string, unknown> }>,
|
||||
timeline: unknown[] = [],
|
||||
): Room =>
|
||||
({
|
||||
getLiveTimeline: () => ({
|
||||
getState: () => ({
|
||||
getStateEvents: () =>
|
||||
members.map((m) => ({
|
||||
getSender: () => m.sender,
|
||||
getStateKey: () => `_${m.sender}_DEV_m.call`,
|
||||
getContent: () => m.content,
|
||||
})),
|
||||
}),
|
||||
getEvents: () => timeline,
|
||||
}),
|
||||
}) as unknown as Room;
|
||||
|
||||
test('hasActiveCallMembership reads the room state: joined vs left (#312)', () => {
|
||||
const room = stateRoom([
|
||||
{ sender: '@bob:x', content: { application: 'm.call', call_id: '' } },
|
||||
{ sender: '@carol:x', content: {} },
|
||||
]);
|
||||
assert.equal(hasActiveCallMembership(room, '@bob:x'), true);
|
||||
assert.equal(hasActiveCallMembership(room, '@carol:x'), false, 'left = empty content');
|
||||
assert.equal(hasActiveCallMembership(room, '@dave:x'), false);
|
||||
});
|
||||
|
||||
test('declinedRing finds our own decline of that ring only (#312)', () => {
|
||||
const decline = (sender: string, rel: string) => ({
|
||||
getType: () => 'org.matrix.msc4310.rtc.decline',
|
||||
getSender: () => sender,
|
||||
getRelation: () => ({ event_id: rel }),
|
||||
});
|
||||
const room = stateRoom([], [decline('@me:x', '$ring1'), decline('@bob:x', '$ring2')]);
|
||||
assert.equal(declinedRing(room, '$ring1', '@me:x'), true);
|
||||
assert.equal(declinedRing(room, '$ring2', '@me:x'), false, "someone else's decline");
|
||||
assert.equal(declinedRing(room, '$ring3', '@me:x'), false);
|
||||
});
|
||||
|
||||
@@ -16,37 +16,3 @@ export const isRingableRoom = (room: Room, isDirect: boolean): boolean => {
|
||||
const isSpaceChild = getStateEvents(room, StateEvent.SpaceParent).length > 0;
|
||||
return !isSpaceChild && room.getJoinRule() === JoinRule.Invite;
|
||||
};
|
||||
|
||||
/** A call-membership state event that is still "in the call" (left = empty content). */
|
||||
const isActiveMembership = (content: Record<string, unknown> | undefined): boolean =>
|
||||
!!content &&
|
||||
(typeof content.application === 'string' ||
|
||||
(Array.isArray(content.memberships) && content.memberships.length > 0));
|
||||
|
||||
/**
|
||||
* [Gitea #312] Whether `userId` is in a call in `room` according to the room's
|
||||
* current STATE. After a reload the MatrixRTC session can be stale (a join and
|
||||
* leave replayed in one catch-up batch), but the state is right.
|
||||
*/
|
||||
export const hasActiveCallMembership = (room: Room, userId: string): boolean =>
|
||||
getStateEvents(room, StateEvent.GroupCallMemberPrefix).some(
|
||||
(ev) =>
|
||||
(ev.getSender() === userId || ev.getStateKey()?.includes(userId)) &&
|
||||
isActiveMembership(ev.getContent()),
|
||||
);
|
||||
|
||||
/**
|
||||
* [Gitea #312] Whether we already handled the ring `refEventId` points at:
|
||||
* declined it (our own RTCDecline relates to it) — e.g. replayed together with
|
||||
* the ring in the first sync after a restart, before any dismiss listener.
|
||||
*/
|
||||
export const declinedRing = (room: Room, refEventId: string, myUserId: string): boolean =>
|
||||
room
|
||||
.getLiveTimeline()
|
||||
.getEvents()
|
||||
.some(
|
||||
(ev) =>
|
||||
ev.getType() === 'org.matrix.msc4310.rtc.decline' &&
|
||||
ev.getSender() === myUserId &&
|
||||
ev.getRelation()?.event_id === refEventId,
|
||||
);
|
||||
|
||||
@@ -20,9 +20,12 @@ export const IDB_VERSION_CONFLICT = 'IDB_VERSION_CONFLICT';
|
||||
* session. When that happens the device "resurrects" with a blank key store and the
|
||||
* client re-uploads a one-time key at an id Synapse already holds → a permanent
|
||||
* `400 M_UNKNOWN: … already exists` upload-conflict storm (and, downstream,
|
||||
* undecryptable to-device/media keys). `persist()` grants based on engagement / PWA
|
||||
* install and shows no prompt; denial/absence is non-fatal.
|
||||
* undecryptable to-device/media keys). Chromium/WebKit answer `persist()` at once
|
||||
* (engagement / PWA install); Firefox shows a permission prompt and the promise
|
||||
* stays pending until it's answered. Denial/absence is non-fatal.
|
||||
*/
|
||||
const PERSIST_WAIT_MS = 1500;
|
||||
|
||||
export const requestPersistentStorage = async (): Promise<boolean> => {
|
||||
try {
|
||||
if (!navigator.storage?.persist) return false;
|
||||
@@ -39,7 +42,15 @@ export const requestPersistentStorage = async (): Promise<boolean> => {
|
||||
|
||||
export const initClient = async (session: Session): Promise<MatrixClient> => {
|
||||
// Protect the crypto store from eviction before we create and write to it.
|
||||
await requestPersistentStorage();
|
||||
// [Gitea #303] Never block startup on the answer: Firefox prompts and leaves
|
||||
// the promise pending until the user responds, which froze the app on
|
||||
// "Heating up". KE-1 only needs the request made; give it 1.5 s at most.
|
||||
await Promise.race([
|
||||
requestPersistentStorage(),
|
||||
new Promise<boolean>((resolve) => {
|
||||
setTimeout(() => resolve(false), PERSIST_WAIT_MS);
|
||||
}),
|
||||
]);
|
||||
|
||||
const indexedDBStore = new IndexedDBStore({
|
||||
indexedDB: globalThis.indexedDB,
|
||||
|
||||
Reference in New Issue
Block a user