apps/mobile is a Matrix client for Android on the famedly Matrix Dart SDK, with vodozemac (compiled from Rust during the build) for end-to-end encryption. It speaks the plain Client-Server API and uses the web client's design tokens, fonts and symbol. - Sign in by server name (.well-known), homeserver address or full user ID; sign up with the dummy and registration token stages. Sessions survive restarts: SQLite in private storage, credentials also in the Keystore, both excluded from backups and device transfers. - Room list with unread and mention counts, invites, search and filters. Timeline with grouping, day separators, notices, history on scroll, links, images and files (authenticated media). Sending text, photos, camera shots and files, with Sending/Sent/Read/Not sent and Retry. Typing, receipts, deleting. New rooms and DMs, encrypted by default; joining by address; room info with members, invite, rename, topic, notification level, leave. - Encryption: one-step setup behind a recovery key, verifying a new session with the recovery key (restoring the backup) or another session, emoji verification of people and sessions, reset. Undecryptable messages say why. Session list with verify and sign out. - Notifications while running, and push through UnifiedPush (no Firebase): the distributor's endpoint becomes an event_id_only pusher, the gateway is discovered, and a push starts the app headless to fetch, decrypt and show the event. Make targets: mobile (release APKs per ABI into bin/), mobile-run, mobile-test. Kotlin incremental compilation is off (Windows, project and pub cache on different drives), and Tink's JVM artifact is excluded in favour of tink-android. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
2.8 KiB
Dart
116 lines
2.8 KiB
Dart
import 'dart:typed_data';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../matrix/media.dart';
|
|
import '../state.dart';
|
|
import '../theme.dart';
|
|
|
|
/// A round avatar: the picture at [mxc] when there is one, else the first
|
|
/// letter of [name] on a colour picked from [seed] (the user or room ID), so
|
|
/// the same person always gets the same colour.
|
|
class Avatar extends ConsumerStatefulWidget {
|
|
const Avatar({
|
|
super.key,
|
|
required this.name,
|
|
required this.seed,
|
|
this.mxc,
|
|
this.size = 40,
|
|
});
|
|
|
|
final String name;
|
|
final String seed;
|
|
final Uri? mxc;
|
|
final double size;
|
|
|
|
@override
|
|
ConsumerState<Avatar> createState() => _AvatarState();
|
|
}
|
|
|
|
class _AvatarState extends ConsumerState<Avatar> {
|
|
Future<Uint8List?>? _bytes;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_load();
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(Avatar old) {
|
|
super.didUpdateWidget(old);
|
|
if (old.mxc != widget.mxc || old.size != widget.size) _load();
|
|
}
|
|
|
|
void _load() {
|
|
final mxc = widget.mxc;
|
|
_bytes = mxc == null || mxc.scheme != 'mxc'
|
|
? null
|
|
: Media.thumbnail(ref.read(clientProvider), mxc, widget.size.round());
|
|
}
|
|
|
|
static const _palette = [
|
|
Color(0xFF00A389),
|
|
Color(0xFF1D5FD1),
|
|
Color(0xFF8A5300),
|
|
Color(0xFFB42318),
|
|
Color(0xFF6D4AC2),
|
|
Color(0xFF00806A),
|
|
Color(0xFFC2410C),
|
|
Color(0xFF0E7490),
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final size = widget.size;
|
|
final hash = widget.seed.codeUnits.fold<int>(
|
|
0,
|
|
(h, c) => (h * 31 + c) & 0x7fffffff,
|
|
);
|
|
final colour = _palette[hash.abs() % _palette.length];
|
|
final letter = _initial(widget.name);
|
|
final fallback = Container(
|
|
width: size,
|
|
height: size,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(color: colour, shape: BoxShape.circle),
|
|
child: Text(
|
|
letter,
|
|
style: TextStyle(
|
|
fontFamily: fontDisplay,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: size * 0.42,
|
|
color: Colors.white,
|
|
height: 1,
|
|
),
|
|
),
|
|
);
|
|
final bytes = _bytes;
|
|
if (bytes == null) return fallback;
|
|
return FutureBuilder<Uint8List?>(
|
|
future: bytes,
|
|
builder: (context, snapshot) {
|
|
final data = snapshot.data;
|
|
if (data == null) return fallback;
|
|
return ClipOval(
|
|
child: Image.memory(
|
|
data,
|
|
width: size,
|
|
height: size,
|
|
fit: BoxFit.cover,
|
|
gaplessPlayback: true,
|
|
errorBuilder: (_, _, _) => fallback,
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
static String _initial(String name) {
|
|
final trimmed = name.replaceFirst(RegExp(r'^[@#!+]'), '').trim();
|
|
if (trimmed.isEmpty) return '?';
|
|
return String.fromCharCode(trimmed.runes.first).toUpperCase();
|
|
}
|
|
}
|