Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26cf1204b5 |
@@ -6,12 +6,13 @@ import {
|
||||
useCallJoined,
|
||||
useCallEmbedPlacementSync,
|
||||
useCallLoadError,
|
||||
useCallStart,
|
||||
} from '../../hooks/useCallEmbed';
|
||||
import { callEmbedAtom } from '../../state/callEmbed';
|
||||
import { ContainerColor } from '../../styles/ContainerColor.css';
|
||||
import { PrescreenControls } from './PrescreenControls';
|
||||
import { usePowerLevelsContext } from '../../hooks/usePowerLevels';
|
||||
import { useRoom } from '../../hooks/useRoom';
|
||||
import { useIsDirectRoom, useRoom } from '../../hooks/useRoom';
|
||||
import { useRoomCreators } from '../../hooks/useRoomCreators';
|
||||
import { useRoomPermissions } from '../../hooks/useRoomPermissions';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
@@ -160,6 +161,16 @@ function CallLoadErrorMessage() {
|
||||
// prescreen, where they can choose to join again.
|
||||
const dismiss = () => setCallEmbed(undefined);
|
||||
|
||||
// [Gitea #301] Try again: start a fresh embed for the same room with the
|
||||
// same mic/camera/sound choices (starting one disposes the hung one).
|
||||
const callEmbed = useCallEmbed();
|
||||
const startCall = useCallStart(useIsDirectRoom());
|
||||
const retry = () => {
|
||||
if (!callEmbed) return;
|
||||
const { room, control } = callEmbed;
|
||||
startCall(room, { microphone: control.microphone, video: control.video, sound: control.sound });
|
||||
};
|
||||
|
||||
return (
|
||||
<Box
|
||||
className={css.CallViewContent}
|
||||
@@ -173,6 +184,9 @@ function CallLoadErrorMessage() {
|
||||
The call failed to load. Check your connection and try again.
|
||||
</Text>
|
||||
<Box gap="200" alignItems="Center">
|
||||
<Button variant="Primary" size="300" radii="400" onClick={retry} disabled={!callEmbed}>
|
||||
<Text size="B400">Try again</Text>
|
||||
</Button>
|
||||
<Button variant="Secondary" fill="Soft" size="300" radii="400" onClick={dismiss}>
|
||||
<Text size="B400">Back</Text>
|
||||
</Button>
|
||||
|
||||
@@ -17,7 +17,6 @@ import { Page, PageContent, PageHeader } from '../../components/page';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
import { SequenceCard } from '../../components/sequence-card';
|
||||
import { SequenceCardStyle } from '../common-settings/styles.css';
|
||||
import { dedupePolicyEntries, PolicyEntry, recommendationLabel } from './policyEntries';
|
||||
|
||||
// ── Policy event types ────────────────────────────────────────────────────────
|
||||
|
||||
@@ -39,6 +38,13 @@ type PolicyRuleContent = {
|
||||
recommendation?: string;
|
||||
};
|
||||
|
||||
type PolicyEntry = {
|
||||
entity: string;
|
||||
reason: string;
|
||||
recommendation: string;
|
||||
stateKey: string;
|
||||
};
|
||||
|
||||
type PolicyTab = 'users' | 'rooms' | 'servers';
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||
@@ -47,6 +53,13 @@ function isGlob(entity: string): boolean {
|
||||
return entity.includes('*') || entity.includes('?');
|
||||
}
|
||||
|
||||
function recommendationLabel(rec: string): string {
|
||||
// `m.ban` is the stable value; `org.matrix.mjolnir.ban` is the legacy
|
||||
// (pre-stabilization) recommendation still emitted by older bots.
|
||||
if (rec === 'm.ban' || rec === 'org.matrix.mjolnir.ban') return 'Ban';
|
||||
return rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all state events of a given type from a room's live forward state.
|
||||
* Uses the raw matrix-js-sdk `getStateEvents` API which accepts any string type.
|
||||
@@ -71,6 +84,23 @@ function extractPolicyEntries(events: MatrixEvent[]): PolicyEntry[] {
|
||||
.filter((entry) => entry.entity !== '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge policy entries from the stable and legacy event types for a rule
|
||||
* kind, de-duplicating by entity+recommendation so a room that emits both a
|
||||
* stable and a legacy rule for the same target isn't double-listed.
|
||||
*/
|
||||
export function dedupePolicyEntries(entries: PolicyEntry[]): PolicyEntry[] {
|
||||
const seen = new Set<string>();
|
||||
const result: PolicyEntry[] = [];
|
||||
entries.forEach((entry) => {
|
||||
const key = `${entry.entity} ${entry.recommendation}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
result.push(entry);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
// ── Entry row ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function PolicyEntryRow({ entry }: { entry: PolicyEntry }) {
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { dedupePolicyEntries, recommendationLabel } from './policyEntries';
|
||||
|
||||
const e = (entity: string, recommendation: string, stateKey = entity) => ({
|
||||
entity,
|
||||
reason: 'spam waves',
|
||||
recommendation,
|
||||
stateKey,
|
||||
});
|
||||
|
||||
test('dedupePolicyEntries: a stable rule and its legacy twin show once (#321)', () => {
|
||||
const out = dedupePolicyEntries([
|
||||
e('@spammer:evil.example', 'm.ban'),
|
||||
e('@spammer:evil.example', 'org.matrix.mjolnir.ban'),
|
||||
e('@*:spam.example', 'm.ban'),
|
||||
]);
|
||||
assert.deepEqual(
|
||||
out.map((x) => x.entity),
|
||||
['@spammer:evil.example', '@*:spam.example'],
|
||||
);
|
||||
});
|
||||
|
||||
test('dedupePolicyEntries: different recommendations stay separate', () => {
|
||||
assert.equal(dedupePolicyEntries([e('@a:x', 'm.ban'), e('@a:x', 'org.example.mute')]).length, 2);
|
||||
});
|
||||
|
||||
test('recommendationLabel', () => {
|
||||
assert.equal(recommendationLabel('m.ban'), 'Ban');
|
||||
assert.equal(recommendationLabel('org.matrix.mjolnir.ban'), 'Ban');
|
||||
assert.equal(recommendationLabel('org.example.mute'), 'org.example.mute');
|
||||
});
|
||||
@@ -1,35 +0,0 @@
|
||||
export type PolicyEntry = {
|
||||
entity: string;
|
||||
reason: string;
|
||||
recommendation: string;
|
||||
stateKey: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* `m.ban` is the stable value; `org.matrix.mjolnir.ban` is the legacy
|
||||
* (pre-stabilization) recommendation still emitted by older bots.
|
||||
*/
|
||||
export const normalizeRecommendation = (rec: string): string =>
|
||||
rec === 'org.matrix.mjolnir.ban' ? 'm.ban' : rec;
|
||||
|
||||
export function recommendationLabel(rec: string): string {
|
||||
if (normalizeRecommendation(rec) === 'm.ban') return 'Ban';
|
||||
return rec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge stable and legacy rule lists, one entry per entity + recommendation.
|
||||
* [Gitea #321] Keyed on the normalised recommendation: a bot publishing both
|
||||
* `m.ban` and its `org.matrix.mjolnir.ban` twin showed the rule twice.
|
||||
*/
|
||||
export function dedupePolicyEntries(entries: PolicyEntry[]): PolicyEntry[] {
|
||||
const seen = new Set<string>();
|
||||
const result: PolicyEntry[] = [];
|
||||
entries.forEach((entry) => {
|
||||
const key = `${entry.entity} ${normalizeRecommendation(entry.recommendation)}`;
|
||||
if (seen.has(key)) return;
|
||||
seen.add(key);
|
||||
result.push(entry);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user