Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57036bb6a4 | ||
|
|
400ee76b63 | ||
|
|
47c1e435b7 | ||
|
|
4650796120 | ||
|
|
d55a8ba8a5 | ||
|
|
4b8c3219e9 | ||
|
|
47328d6fee | ||
|
|
b0eb3da830 | ||
|
|
2700aad209 | ||
|
|
a8a7e639a9 |
@@ -20,7 +20,6 @@ import {
|
||||
import {
|
||||
EventTimelineSetHandlerMap,
|
||||
EventType,
|
||||
JoinRule,
|
||||
RelationType,
|
||||
Room,
|
||||
RoomEvent,
|
||||
@@ -72,7 +71,8 @@ import { useReducedMotion } from '../hooks/useReducedMotion';
|
||||
import { useSetting } from '../state/hooks/settings';
|
||||
import { useCallPreferences } from '../state/hooks/callPreferences';
|
||||
import { settingsAtom } from '../state/settings';
|
||||
import { getStateEvent, getStateEvents, getMemberName } from '../utils/room';
|
||||
import { getStateEvent, getMemberName } from '../utils/room';
|
||||
import { isRingableRoom } from '../utils/callRing';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { getPowersLevelFromMatrixEvent } from '../hooks/usePowerLevels';
|
||||
import { getRoomCreatorsForRoomId } from '../hooks/useRoomCreators';
|
||||
@@ -581,12 +581,7 @@ function IncomingCallListener({ callEmbed, joined }: IncomingCallListenerProps)
|
||||
// Only ring in rooms where the call button is visible: DMs or invite-only rooms
|
||||
// with no space parent. Persistent voice rooms (call rooms), space channels,
|
||||
// restricted rooms, and public rooms must never trigger ringing.
|
||||
if (room.isCallRoom()) return;
|
||||
const isDirect = directs.has(room.roomId);
|
||||
const isSpaceChild = getStateEvents(room, StateEvent.SpaceParent).length > 0;
|
||||
const joinRule = room.getJoinRule();
|
||||
const isPrivateInviteGroup = !isSpaceChild && joinRule === JoinRule.Invite;
|
||||
if (!isDirect && !isPrivateInviteGroup) return;
|
||||
if (!isRingableRoom(room, directs.has(room.roomId))) return;
|
||||
|
||||
const info: IncomingCallInfo = {
|
||||
room,
|
||||
|
||||
@@ -40,6 +40,7 @@ import { creatorsSupported } from '../../../utils/matrix';
|
||||
import { useRoomCreators } from '../../../hooks/useRoomCreators';
|
||||
import { BreakWord } from '../../../styles/Text.css';
|
||||
import { useModalStyle } from '../../../hooks/useModalStyle';
|
||||
import { stateToCarry } from '../../../utils/roomUpgradeState';
|
||||
|
||||
function RoomUpgradeDialog({ requestClose }: { requestClose: () => void }) {
|
||||
const mx = useMatrixClient();
|
||||
@@ -63,10 +64,41 @@ function RoomUpgradeDialog({ requestClose }: { requestClose: () => void }) {
|
||||
const [upgradeState, upgrade] = useAsyncCallback(
|
||||
useCallback(
|
||||
async (version: string, newAdditionalCreators?: string[]) => {
|
||||
await mx.http.authedRequest(Method.Post, `/rooms/${room.roomId}/upgrade`, undefined, {
|
||||
new_version: version,
|
||||
additional_creators: newAdditionalCreators,
|
||||
});
|
||||
// [Gitea #327] Synapse doesn't copy Lotus room state (voice limit, call
|
||||
// policy, soundboard, retention, role tags, emoji packs) into the
|
||||
// replacement room: read it first, re-create it after the upgrade.
|
||||
const carried = stateToCarry(
|
||||
Array.from(room.currentState.events.values()).flatMap((byKey) =>
|
||||
Array.from(byKey.values()),
|
||||
),
|
||||
);
|
||||
const res = await mx.http.authedRequest<{ replacement_room?: string }>(
|
||||
Method.Post,
|
||||
`/rooms/${room.roomId}/upgrade`,
|
||||
undefined,
|
||||
{
|
||||
new_version: version,
|
||||
additional_creators: newAdditionalCreators,
|
||||
},
|
||||
);
|
||||
const newRoomId = res?.replacement_room;
|
||||
if (!newRoomId || carried.length === 0) return;
|
||||
const results = await Promise.allSettled(
|
||||
carried.map((st) =>
|
||||
mx.http.authedRequest(
|
||||
Method.Put,
|
||||
`/rooms/${encodeURIComponent(newRoomId)}/state/${encodeURIComponent(st.type)}/${encodeURIComponent(st.stateKey)}`,
|
||||
undefined,
|
||||
st.content,
|
||||
),
|
||||
),
|
||||
);
|
||||
const failed = results.filter((r) => r.status === 'rejected').length;
|
||||
if (failed > 0) {
|
||||
throw new Error(
|
||||
`Room upgraded, but ${failed} of ${carried.length} Lotus settings (voice limit, call policy, soundboard, retention…) could not be copied to the new room.`,
|
||||
);
|
||||
}
|
||||
},
|
||||
[mx, room],
|
||||
),
|
||||
|
||||
@@ -51,7 +51,7 @@ const dark: CSSProperties = {
|
||||
backgroundSize: '260% 240%, 300% 260%, 240% 280%, 220% 200%, 100% 100%, 100% 100%',
|
||||
backgroundPosition: '0% 30%, 100% 70%, 50% 0%, 20% 80%, 50% 50%, 50% 50%',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
animation: `${auroraFlow} 60s ease-in-out infinite`,
|
||||
animation: `${auroraFlow} 60s steps(180) infinite`,
|
||||
};
|
||||
|
||||
const light: CSSProperties = {
|
||||
@@ -75,7 +75,7 @@ const light: CSSProperties = {
|
||||
backgroundSize: '260% 240%, 300% 260%, 240% 280%, 220% 200%, 100% 100%, 100% 100%',
|
||||
backgroundPosition: '0% 30%, 100% 70%, 50% 0%, 20% 80%, 50% 50%, 50% 50%',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
animation: `${auroraFlow} 60s ease-in-out infinite`,
|
||||
animation: `${auroraFlow} 60s steps(180) infinite`,
|
||||
};
|
||||
|
||||
export const animAurora: ChatBgVariants = { dark, light };
|
||||
|
||||
@@ -55,7 +55,7 @@ export const animFireflies: ChatBgVariants = {
|
||||
'0 0', // wash A (static)
|
||||
'0 0', // wash B (static)
|
||||
].join(','),
|
||||
animation: `${firefliesDrift} 44s linear infinite`,
|
||||
animation: `${firefliesDrift} 44s steps(528) infinite`,
|
||||
},
|
||||
|
||||
// Light: a cozy warm dim-dusk. No harsh dots on white — soft amber motes with
|
||||
@@ -93,6 +93,6 @@ export const animFireflies: ChatBgVariants = {
|
||||
'0 0', // wash A (static)
|
||||
'0 0', // wash B (static)
|
||||
].join(','),
|
||||
animation: `${firefliesDrift} 44s linear infinite`,
|
||||
animation: `${firefliesDrift} 44s steps(528) infinite`,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -76,7 +76,7 @@ export const animPulse: ChatBgVariants = {
|
||||
'0 0', // base wash
|
||||
'0 0', // vignette
|
||||
].join(','),
|
||||
animation: `${gridPulse} 22s ease-in-out infinite`,
|
||||
animation: `${gridPulse} 22s steps(528) infinite`,
|
||||
},
|
||||
|
||||
// Light: soft slate-blue grid on pale cool-white, a gentle luminance breathe.
|
||||
@@ -116,6 +116,6 @@ export const animPulse: ChatBgVariants = {
|
||||
'0 0', // base wash
|
||||
'0 0', // vignette
|
||||
].join(','),
|
||||
animation: `${gridPulse} 22s ease-in-out infinite`,
|
||||
animation: `${gridPulse} 22s steps(528) infinite`,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -97,7 +97,7 @@ export const animRain: ChatBgVariants = {
|
||||
].join(','),
|
||||
backgroundSize: ['260px 200px', '100% 100%', '100% 100%', '100% 100%'].join(','),
|
||||
backgroundPosition: ['0 0', '0 0', '0 0', '0 0'].join(','),
|
||||
animation: `${rainFall} 12s linear infinite`,
|
||||
animation: `${rainFall} 12s steps(288) infinite`,
|
||||
},
|
||||
|
||||
// Light: soft teal-grey streaks on a pale cool base — elegant, never neon.
|
||||
@@ -118,6 +118,6 @@ export const animRain: ChatBgVariants = {
|
||||
].join(','),
|
||||
backgroundSize: ['260px 200px', '100% 100%', '100% 100%', '100% 100%'].join(','),
|
||||
backgroundPosition: ['0 0', '0 0', '0 0', '0 0'].join(','),
|
||||
animation: `${rainFall} 12s linear infinite`,
|
||||
animation: `${rainFall} 12s steps(288) infinite`,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -68,7 +68,7 @@ export const animStars: ChatBgVariants = {
|
||||
'0 0', // nebula A
|
||||
'0 0', // nebula B
|
||||
].join(','),
|
||||
animation: `${starDrift} 90s linear infinite`,
|
||||
animation: `${starDrift} 90s steps(1080) infinite`,
|
||||
},
|
||||
|
||||
// Light: an airy pre-dawn sky. No literal white-on-white stars — instead very
|
||||
@@ -112,6 +112,6 @@ export const animStars: ChatBgVariants = {
|
||||
'0 0', // wash A
|
||||
'0 0', // wash B
|
||||
].join(','),
|
||||
animation: `${starDrift} 100s linear infinite`,
|
||||
animation: `${starDrift} 100s steps(1200) infinite`,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -149,6 +149,11 @@ export const getChatBg = (
|
||||
}
|
||||
// For animated backgrounds, promote the element to its own compositor layer so
|
||||
// background-position keyframes don't trigger repaints on descendant elements.
|
||||
// [Gitea #337] background-position can't run on the compositor, so every
|
||||
// animation frame repaints the whole chat area (45 to 70% main-thread busy
|
||||
// at 60 fps). The drifts are slow (3–22 px/s), so each animation uses steps():
|
||||
// ~12 updates/s for the slow ones, ~24/s for rain and pulse: visually the
|
||||
// same, a fraction of the repaints.
|
||||
if (style.animation) {
|
||||
return { ...style, willChange: 'background-position', contain: 'paint' };
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||
import { useIgnoredUsers } from '../../hooks/useIgnoredUsers';
|
||||
import { useImagePackRooms } from '../../hooks/useImagePackRooms';
|
||||
import { useIsDirectRoom } from '../../hooks/useRoom';
|
||||
import { isRingableRoom } from '../../utils/callRing';
|
||||
import { useOpenUserRoomProfile } from '../../state/hooks/userRoomProfile';
|
||||
import { useSpaceOptionally } from '../../hooks/useSpace';
|
||||
import { useRoomCreators } from '../../hooks/useRoomCreators';
|
||||
@@ -2030,6 +2031,9 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
[EventType.RTCNotification]: (mEventId, mEvent, item) => {
|
||||
const senderId = mEvent.getSender() ?? '';
|
||||
if (!senderId || senderId === mx.getUserId()) return null;
|
||||
// Same rule as ringing: no "Missed call" in voice rooms or space
|
||||
// channels, where starting a call is just joining the channel.
|
||||
if (!isRingableRoom(room, direct)) return null;
|
||||
const content = mEvent.getContent();
|
||||
const mention =
|
||||
content['m.mentions']?.room ||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import type { Room } from 'matrix-js-sdk';
|
||||
import { isRingableRoom } from './callRing';
|
||||
|
||||
const fakeRoom = (opts: { callRoom?: boolean; joinRule?: string; spaceParent?: boolean }): Room =>
|
||||
({
|
||||
isCallRoom: () => !!opts.callRoom,
|
||||
getJoinRule: () => opts.joinRule ?? 'invite',
|
||||
getLiveTimeline: () => ({
|
||||
getState: () => ({ getStateEvents: () => (opts.spaceParent ? [{}] : []) }),
|
||||
}),
|
||||
}) as unknown as Room;
|
||||
|
||||
test('voice rooms never ring or show "missed call", even as DMs', () => {
|
||||
assert.equal(isRingableRoom(fakeRoom({ callRoom: true }), false), false);
|
||||
assert.equal(isRingableRoom(fakeRoom({ callRoom: true }), true), false);
|
||||
});
|
||||
|
||||
test('DMs and invite-only groups outside a space ring', () => {
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'public' }), true), true);
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'invite' }), false), true);
|
||||
});
|
||||
|
||||
test('space channels, public and restricted rooms do not ring', () => {
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'invite', spaceParent: true }), false), false);
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'public' }), false), false);
|
||||
assert.equal(isRingableRoom(fakeRoom({ joinRule: 'restricted' }), false), false);
|
||||
});
|
||||
@@ -0,0 +1,18 @@
|
||||
import { JoinRule, Room } from 'matrix-js-sdk';
|
||||
import { StateEvent } from '../../types/matrix/room';
|
||||
import { getStateEvents } from './room';
|
||||
|
||||
/**
|
||||
* Whether a call notification in this room may ring — and, by the same rule,
|
||||
* whether an unanswered one may show as "Missed call" (Gitea #162 follow-up).
|
||||
* Only DMs and invite-only groups outside any space ring, i.e. rooms where the
|
||||
* call button is shown. Persistent voice rooms, space channels, restricted and
|
||||
* public rooms never do: joining a voice channel alone is normal and isn't a
|
||||
* "call" anyone missed.
|
||||
*/
|
||||
export const isRingableRoom = (room: Room, isDirect: boolean): boolean => {
|
||||
if (room.isCallRoom()) return false;
|
||||
if (isDirect) return true;
|
||||
const isSpaceChild = getStateEvents(room, StateEvent.SpaceParent).length > 0;
|
||||
return !isSpaceChild && room.getJoinRule() === JoinRule.Invite;
|
||||
};
|
||||
@@ -38,3 +38,38 @@ test('hostFromText only accepts URL/host-shaped text; IDN becomes punycode', ()
|
||||
assert.equal(analyzeLink('paypal.com', 'https://xn--pypal-4ve.com/')?.punycode, true);
|
||||
assert.equal(analyzeLink('paypal.com', 'https://xn--pypal-4ve.com/')?.mismatch, true);
|
||||
});
|
||||
|
||||
test('a trusted name inside a sentence still exposes a different destination (#335)', () => {
|
||||
const a = analyzeLink('Log in at chat.lotusguild.org', 'https://evil.example/');
|
||||
assert.equal(a?.mismatch, true);
|
||||
assert.equal(a?.shownHost, 'chat.lotusguild.org');
|
||||
assert.equal(
|
||||
analyzeLink('chat.lotusguild.org (official)', 'https://evil.example/')?.mismatch,
|
||||
true,
|
||||
);
|
||||
assert.equal(
|
||||
analyzeLink('Open https://paypal.com/login now', 'https://evil.example/')?.mismatch,
|
||||
true,
|
||||
);
|
||||
// honest sentences are not flagged
|
||||
assert.equal(
|
||||
analyzeLink('Log in at chat.lotusguild.org', 'https://chat.lotusguild.org/login')?.mismatch,
|
||||
false,
|
||||
);
|
||||
assert.equal(analyzeLink('read the docs', 'https://evil.example/')?.mismatch, false);
|
||||
assert.equal(analyzeLink('see main.py and report.pdf', 'https://github.com/x')?.mismatch, false);
|
||||
assert.equal(analyzeLink('release v1.2.3 notes', 'https://github.com/x')?.mismatch, false);
|
||||
});
|
||||
|
||||
test('shared hosting suffixes are separate sites (#335)', () => {
|
||||
assert.equal(registrableDomain('alice.github.io'), 'alice.github.io');
|
||||
assert.equal(registrableDomain('www.alice.github.io'), 'alice.github.io');
|
||||
assert.equal(registrableDomain('bucket.s3.amazonaws.com'), 'bucket.s3.amazonaws.com');
|
||||
assert.equal(analyzeLink('alice.github.io', 'https://evil.github.io/')?.mismatch, true);
|
||||
assert.equal(analyzeLink('lotusguild.pages.dev', 'https://evil.pages.dev/')?.mismatch, true);
|
||||
assert.equal(
|
||||
analyzeLink('alice.github.io/blog', 'https://alice.github.io/blog/1')?.mismatch,
|
||||
false,
|
||||
);
|
||||
assert.equal(registrableDomain('news.bbc.co.uk'), 'bbc.co.uk');
|
||||
});
|
||||
|
||||
+131
-7
@@ -48,11 +48,53 @@ const TWO_LABEL_SUFFIXES = new Set([
|
||||
'com.tw',
|
||||
]);
|
||||
|
||||
// [Gitea #335] Shared-hosting suffixes (the Public Suffix List's "private"
|
||||
// section, the ones phishing actually uses): every customer gets their own
|
||||
// subdomain, so `alice.github.io` and `evil.github.io` are different sites.
|
||||
// A curated list rather than the full PSL keeps this out of the bundle budget.
|
||||
const SHARED_HOSTING_SUFFIXES = new Set([
|
||||
'github.io',
|
||||
'gitlab.io',
|
||||
'codeberg.page',
|
||||
'pages.dev',
|
||||
'workers.dev',
|
||||
'trycloudflare.com',
|
||||
'netlify.app',
|
||||
'vercel.app',
|
||||
'web.app',
|
||||
'firebaseapp.com',
|
||||
'appspot.com',
|
||||
'herokuapp.com',
|
||||
'onrender.com',
|
||||
'fly.dev',
|
||||
'glitch.me',
|
||||
'replit.app',
|
||||
'repl.co',
|
||||
'surge.sh',
|
||||
'blogspot.com',
|
||||
'wordpress.com',
|
||||
'wixsite.com',
|
||||
'weebly.com',
|
||||
'azurewebsites.net',
|
||||
'cloudfront.net',
|
||||
'ngrok.io',
|
||||
'ngrok-free.app',
|
||||
'duckdns.org',
|
||||
's3.amazonaws.com',
|
||||
]);
|
||||
|
||||
const isPublicSuffix = (suffix: string): boolean =>
|
||||
TWO_LABEL_SUFFIXES.has(suffix) || SHARED_HOSTING_SUFFIXES.has(suffix);
|
||||
|
||||
export const registrableDomain = (host: string): string => {
|
||||
const labels = host.toLowerCase().replace(/\.$/, '').split('.');
|
||||
if (labels.length <= 2) return labels.join('.');
|
||||
const lastTwo = labels.slice(-2).join('.');
|
||||
return TWO_LABEL_SUFFIXES.has(lastTwo) ? labels.slice(-3).join('.') : lastTwo;
|
||||
// Longest matching public suffix wins (3 labels, e.g. s3.amazonaws.com, then 2).
|
||||
for (const n of [3, 2]) {
|
||||
if (labels.length > n && isPublicSuffix(labels.slice(-n).join('.'))) {
|
||||
return labels.slice(-(n + 1)).join('.');
|
||||
}
|
||||
}
|
||||
return labels.slice(-2).join('.');
|
||||
};
|
||||
|
||||
const HOST_LIKE =
|
||||
@@ -72,6 +114,85 @@ export const hostFromText = (text: string): string | null => {
|
||||
}
|
||||
};
|
||||
|
||||
// Words that look like hosts but are usually files or versions in chat
|
||||
// ("see main.py", "report.pdf", "v1.2.3"): skipped inside sentences unless
|
||||
// written as a URL (scheme, www., or a path) so ordinary links aren't flagged.
|
||||
const FILE_EXTENSIONS = new Set([
|
||||
'py',
|
||||
'sh',
|
||||
'md',
|
||||
'rs',
|
||||
'js',
|
||||
'ts',
|
||||
'tsx',
|
||||
'jsx',
|
||||
'json',
|
||||
'yaml',
|
||||
'yml',
|
||||
'toml',
|
||||
'txt',
|
||||
'log',
|
||||
'csv',
|
||||
'pdf',
|
||||
'zip',
|
||||
'gz',
|
||||
'tar',
|
||||
'png',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'gif',
|
||||
'webp',
|
||||
'svg',
|
||||
'mp3',
|
||||
'mp4',
|
||||
'mov',
|
||||
'html',
|
||||
'htm',
|
||||
'css',
|
||||
'exe',
|
||||
'dll',
|
||||
'lock',
|
||||
'cfg',
|
||||
'conf',
|
||||
'ini',
|
||||
'xml',
|
||||
'doc',
|
||||
'docx',
|
||||
'xls',
|
||||
'xlsx',
|
||||
'ppt',
|
||||
'pptx',
|
||||
'apk',
|
||||
'iso',
|
||||
'jar',
|
||||
'java',
|
||||
'go',
|
||||
'rb',
|
||||
'php',
|
||||
'c',
|
||||
'h',
|
||||
'cpp',
|
||||
]);
|
||||
const TRIM_PUNCT = /^[\s"'“”‘’«»([{<]+|[\s"'“”‘’«»)\]}>.,;:!?]+$/g;
|
||||
|
||||
/** Every host a sentence names (Gitea #335), e.g. "Log in at chat.lotusguild.org". */
|
||||
export const hostsFromText = (text: string): string[] => {
|
||||
const hosts: string[] = [];
|
||||
text.split(/\s+/).forEach((raw) => {
|
||||
const word = raw.replace(TRIM_PUNCT, '');
|
||||
const host = word && hostFromText(word);
|
||||
if (!host) return;
|
||||
const tld = host.split('.').pop() ?? '';
|
||||
if (!/[a-z]/i.test(tld)) return; // version numbers, IPs-as-words
|
||||
const urlShaped =
|
||||
/^[a-z][a-z0-9+.-]*:\/\//i.test(word) || /^www\./i.test(word) || word.includes('/');
|
||||
if (!urlShaped && host.split('.').length === 2 && FILE_EXTENSIONS.has(tld.toLowerCase()))
|
||||
return;
|
||||
if (!hosts.includes(host)) hosts.push(host);
|
||||
});
|
||||
return hosts;
|
||||
};
|
||||
|
||||
export type LinkSafety = {
|
||||
/** The visible text names a different site than the destination. */
|
||||
mismatch: boolean;
|
||||
@@ -92,8 +213,11 @@ export const analyzeLink = (text: string, href: string): LinkSafety | null => {
|
||||
if (url.hostname === 'matrix.to') return null;
|
||||
const realHost = url.hostname;
|
||||
const punycode = realHost.split('.').some((l) => l.startsWith('xn--'));
|
||||
const shownHost = hostFromText(text) ?? undefined;
|
||||
const mismatch =
|
||||
shownHost !== undefined && registrableDomain(shownHost) !== registrableDomain(realHost);
|
||||
return { mismatch, shownHost, realHost, punycode };
|
||||
// A single URL/host-shaped text, or (Gitea #335) host-shaped words inside a
|
||||
// sentence: "Log in at chat.lotusguild.org" must not hide a different site.
|
||||
const single = hostFromText(text);
|
||||
const shown = single ? [single] : hostsFromText(text);
|
||||
const realSite = registrableDomain(realHost);
|
||||
const other = shown.find((h) => registrableDomain(h) !== realSite);
|
||||
return { mismatch: other !== undefined, shownHost: other ?? shown[0], realHost, punycode };
|
||||
};
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { isCarriedStateType, stateToCarry } from './roomUpgradeState';
|
||||
|
||||
const ev = (type: string, content: Record<string, unknown>, stateKey = '') => ({
|
||||
getType: () => type,
|
||||
getStateKey: () => stateKey,
|
||||
getContent: () => content,
|
||||
});
|
||||
|
||||
test('Lotus room state is carried; state Synapse already copies is not (#327)', () => {
|
||||
assert.equal(isCarriedStateType('io.lotus.voice_limit'), true);
|
||||
assert.equal(isCarriedStateType('io.lotus.room_quality'), true);
|
||||
assert.equal(isCarriedStateType('io.lotus.soundboard'), true);
|
||||
assert.equal(isCarriedStateType('m.room.retention'), true);
|
||||
assert.equal(isCarriedStateType('in.cinny.room.power_level_tags'), true);
|
||||
assert.equal(isCarriedStateType('im.ponies.room_emotes'), true);
|
||||
assert.equal(isCarriedStateType('m.room.power_levels'), false);
|
||||
assert.equal(isCarriedStateType('m.room.name'), false);
|
||||
assert.equal(isCarriedStateType('m.room.member'), false);
|
||||
});
|
||||
|
||||
test('stateToCarry keeps state keys and skips emptied events', () => {
|
||||
const out = stateToCarry([
|
||||
ev('io.lotus.voice_limit', { max_users: 5 }),
|
||||
ev('io.lotus.soundboard', { clips: [1] }, 'pack-a'),
|
||||
ev('io.lotus.room_quality', {}),
|
||||
ev('m.room.name', { name: 'x' }),
|
||||
ev('m.room.retention', { max_lifetime: 604800000 }),
|
||||
]);
|
||||
assert.deepEqual(
|
||||
out.map((s) => `${s.type}|${s.stateKey}`),
|
||||
['io.lotus.voice_limit|', 'io.lotus.soundboard|pack-a', 'm.room.retention|'],
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* [Gitea #327] Room state Synapse does NOT copy into the replacement room on
|
||||
* `POST /rooms/{id}/upgrade` (it carries only power levels, join rules,
|
||||
* name/topic/avatar, history visibility, guest access, encryption, server ACL
|
||||
* and space parent/child). Lotus keeps call policy, voice limits, soundboard,
|
||||
* message retention, role tags and room emoji packs in state, so an upgrade
|
||||
* silently dropped all of them.
|
||||
*/
|
||||
const CARRIED_TYPES = new Set([
|
||||
'm.room.retention',
|
||||
'in.cinny.room.power_level_tags',
|
||||
'im.ponies.room_emotes',
|
||||
]);
|
||||
const CARRIED_PREFIXES = ['io.lotus.'];
|
||||
|
||||
export type StateToCarry = { type: string; stateKey: string; content: Record<string, unknown> };
|
||||
|
||||
export const isCarriedStateType = (type: string): boolean =>
|
||||
CARRIED_TYPES.has(type) || CARRIED_PREFIXES.some((p) => type.startsWith(p));
|
||||
|
||||
/** The state events to re-create in the replacement room (non-empty content only). */
|
||||
export const stateToCarry = (
|
||||
events: Array<{
|
||||
getType: () => string;
|
||||
getStateKey: () => string | undefined;
|
||||
getContent: () => Record<string, unknown>;
|
||||
}>,
|
||||
): StateToCarry[] =>
|
||||
events
|
||||
.filter((ev) => isCarriedStateType(ev.getType()))
|
||||
.map((ev) => ({
|
||||
type: ev.getType(),
|
||||
stateKey: ev.getStateKey() ?? '',
|
||||
content: ev.getContent(),
|
||||
}))
|
||||
.filter((s) => s.content && Object.keys(s.content).length > 0);
|
||||
Reference in New Issue
Block a user