Files
m8chat-app2/lib/shared/utils/mxc_url.dart
help4bis b95471b0b4 feat: Phase 3 — E2EE calls, Jitsi conferencing, help tab, web security model
- LiveKit call E2EE: CallE2EEManager exchanges encryption keys via Matrix
  to-device events (m.rtc.encryption_keys) for interop with Element X
- Olm bootstrapped in index.html before Flutter init; main.dart logs result
- Encrypted messages shown with lock icon and informative fallback text
- Profile screen: key restore dialog + security setup (cross-signing/backup)
- Jitsi feature: welcome screen (public, no login), conference tab, full-screen
  embed via JitsiMeetExternalAPI, JitsiLink parser for all common link formats
- Help tab: expandable cards for encryption, video calls, account management
- Web security model: no session persistence — device ID only across visits
- Media auth: MSC3916 authenticated endpoint for avatars (Synapse 1.120+)
- Router: welcome route as public landing page; jitsi route as public
- Manifest/index.html: M8Chat branding, dark theme colours

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 05:28:14 +10:00

33 lines
1.3 KiB
Dart

// Version: 2.0.0 | Created: 2026-04-02 | Updated: 2026-04-11
// Synchronous MXC URI to HTTP URL resolution.
//
// Synapse 1.120+ requires authenticated media downloads. The old
// /_matrix/media/v3/download/ endpoint is frozen and returns 404.
// We use /_matrix/client/v1/media/download/ with the access token.
import 'package:matrix/matrix.dart';
/// Resolves an `mxc://` [Uri] to an authenticated HTTP download URL.
/// Returns `null` if the URI is not mxc:// or the client is not connected.
String? resolveMxcUrl(Client client, Uri? mxcUri) {
if (mxcUri == null || !mxcUri.isScheme('mxc')) return null;
final homeserver = client.homeserver;
if (homeserver == null) return null;
final serverName = mxcUri.host;
final port = mxcUri.hasPort ? ':${mxcUri.port}' : '';
final mediaId = mxcUri.path; // includes leading /
// Use the authenticated media endpoint (MSC3916).
final base = homeserver
.resolve('_matrix/client/v1/media/download/$serverName$port$mediaId')
.toString();
// Append the access token so CachedNetworkImage / Image.network can
// fetch without custom headers. The token is already in the browser's
// JS memory so this doesn't expand the attack surface.
final token = client.accessToken;
if (token == null) return base;
return '$base?access_token=$token';
}