feat(bridge): Discord badge on bridged users and a header chip on bridged rooms
CI / Build & Quality Checks (push) Skipped
CI / Secret scan (gitleaks) (push) Skipped
CI / Playwright smoke (e2e) (push) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 10s
CI / Build & Quality Checks (pull_request) Successful in 2m44s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Playwright smoke (e2e) (pull_request) Successful in 17m26s

People who come in from Discord through mautrix-discord now carry a
Discord icon next to their name in the timeline, member list and profile,
and a room bridged to a Discord channel shows a "Discord" chip in its
header that names the channel and server and opens it in Discord.

Ghosts are recognised by mautrix-discord's @discord_<snowflake> user IDs;
rooms by their m.bridge / uk.half-shot.bridge state (protocol discordgo).
Only http(s) channel links are made clickable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
This commit is contained in:
Lotus CI
2026-10-28 22:07:03 -04:00
co-authored by Claude Opus 5.5
parent 3163829c57
commit 3c33169297
10 changed files with 320 additions and 0 deletions
+109
View File
@@ -0,0 +1,109 @@
import React from 'react';
import { Room } from 'matrix-js-sdk';
import { Chip, Icon, IconSrc, Text, Tooltip, TooltipProvider } from 'folds';
import {
BRIDGE_NETWORK_NAME,
BridgeNetwork,
describeRoomBridge,
getBridgedUserNetwork,
} from '../../utils/bridge';
import { useRoomBridges } from '../../hooks/useRoomBridges';
// Discord glyph (simple-icons, 24x24 viewBox like the folds icons).
const DiscordIcon: IconSrc = () => (
<path
fill="currentColor"
d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z"
/>
);
const BRIDGE_ICON: Record<BridgeNetwork, IconSrc> = {
discord: DiscordIcon,
};
const BRIDGE_COLOR: Record<BridgeNetwork, string> = {
discord: '#5865F2',
};
type UserBridgeBadgeProps = {
userId: string;
size?: '50' | '100' | '200';
};
/** Network icon for a user who is bridged in from another chat network, else nothing. */
export function UserBridgeBadge({ userId, size = '100' }: UserBridgeBadgeProps) {
const network = getBridgedUserNetwork(userId);
if (!network) return null;
const label = `On ${BRIDGE_NETWORK_NAME[network]} (bridged)`;
return (
<TooltipProvider
position="Top"
tooltip={
<Tooltip>
<Text size="T200">{label}</Text>
</Tooltip>
}
>
{(ref) => (
<span
ref={ref}
role="img"
aria-label={label}
style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0 }}
>
<Icon size={size} src={BRIDGE_ICON[network]} style={{ color: BRIDGE_COLOR[network] }} />
</span>
)}
</TooltipProvider>
);
}
type RoomBridgeChipProps = {
room: Room;
};
/** Header chip for a room bridged to another network; links to the channel when known. */
export function RoomBridgeChip({ room }: RoomBridgeChipProps) {
const bridges = useRoomBridges(room);
const bridge = bridges[0];
if (!bridge) return null;
const description = describeRoomBridge(bridge);
const linkProps = bridge.externalUrl
? { as: 'a' as const, href: bridge.externalUrl, target: '_blank', rel: 'noreferrer noopener' }
: {};
return (
<TooltipProvider
position="Bottom"
offset={4}
tooltip={
<Tooltip>
<Text>
{bridge.externalUrl
? `${description}. Open in ${BRIDGE_NETWORK_NAME[bridge.network]}.`
: description}
</Text>
</Tooltip>
}
>
{(triggerRef) => (
<Chip
ref={triggerRef}
size="400"
variant="Secondary"
radii="300"
aria-label={description}
before={
<Icon
size="50"
src={BRIDGE_ICON[bridge.network]}
style={{ color: BRIDGE_COLOR[bridge.network] }}
/>
}
{...linkProps}
>
<Text size="T200">{BRIDGE_NETWORK_NAME[bridge.network]}</Text>
</Chip>
)}
</TooltipProvider>
);
}
+1
View File
@@ -0,0 +1 @@
export * from './BridgeBadge';