feat: Phase 2 complete — calls, media, spaces, persistence, chat improvements

- LiveKit/MatrixRTC voice+video calls with full call screen UI
- Incoming call overlay (accept/decline)
- Media upload/download — file picker, image rendering, file download
- Spaces navigation — space list + expandable child rooms
- Drift persistence — rooms + messages written on every sync
- Sync persistence auto-starts on login and session restore
- Chat: typing indicators, long-press menu, reply, emoji reactions
- User search dialog + start DM from rooms screen
- Android: INTERNET + CAMERA + RECORD_AUDIO permissions in main manifest
- Emoji picker for reactions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 06:48:03 +10:00
parent 8f13c725a4
commit f12a7ac1fd
20 changed files with 2458 additions and 191 deletions

View File

@@ -0,0 +1,71 @@
// Version: 1.1.0 | Created: 2026-04-01
// SpacesRepository — builds space list and child rooms from the Matrix SDK.
// A space is a room where isSpace == true.
import 'package:matrix/matrix.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../../../core/network/matrix_client.dart';
import '../domain/space_model.dart';
part 'spaces_repository.g.dart';
@riverpod
SpacesRepository spacesRepository(Ref ref) {
return SpacesRepository(client: ref.watch(matrixClientProvider));
}
class SpacesRepository {
SpacesRepository({required Client client}) : _client = client;
final Client _client;
/// Returns all rooms that are spaces.
List<SpaceModel> getSpaces() {
return _client.rooms.where((r) => r.isSpace).map(_toSpaceModel).toList();
}
/// Returns child rooms within [spaceId] that the client is a member of.
///
/// SpaceChild gives us the roomId only. We look up the Room from the client
/// to get display name and avatar. If the child room is not in the client's
/// room list (not joined), it is omitted.
List<SpaceRoomModel> getRoomsInSpace(String spaceId) {
final space = _client.getRoomById(spaceId);
if (space == null || !space.isSpace) return [];
final result = <SpaceRoomModel>[];
for (final child in space.spaceChildren) {
final childRoomId = child.roomId;
if (childRoomId == null) continue;
final room = _client.getRoomById(childRoomId);
if (room == null) continue; // not joined — skip
result.add(
SpaceRoomModel(
id: room.id,
displayName: room.getLocalizedDisplayname(),
avatarUrl: room.avatar?.toString(),
isDirect: room.isDirectChat,
),
);
}
return result;
}
/// Stream that emits on every sync so the UI stays current.
Stream<List<SpaceModel>> watchSpaces() async* {
yield getSpaces();
yield* _client.onSync.stream.map((_) => getSpaces());
}
SpaceModel _toSpaceModel(Room room) {
return SpaceModel(
id: room.id,
displayName: room.getLocalizedDisplayname(),
avatarUrl: room.avatar?.toString(),
roomCount: room.spaceChildren.length,
);
}
}

View File

@@ -0,0 +1,28 @@
// Version: 1.1.0 | Created: 2026-04-01
// Immutable Space and SpaceRoom models for the spaces navigation feature.
import 'package:freezed_annotation/freezed_annotation.dart';
part 'space_model.freezed.dart';
/// A Matrix space (a room with the m.space type).
@freezed
abstract class SpaceModel with _$SpaceModel {
const factory SpaceModel({
required String id,
required String displayName,
String? avatarUrl,
@Default(0) int roomCount,
}) = _SpaceModel;
}
/// A room that is a child of a Space.
@freezed
abstract class SpaceRoomModel with _$SpaceRoomModel {
const factory SpaceRoomModel({
required String id,
required String displayName,
String? avatarUrl,
@Default(false) bool isDirect,
}) = _SpaceRoomModel;
}

View File

@@ -1,44 +1,62 @@
// Version: 1.0.0 | Created: 2026-04-01
// Spaces screen stub — Phase 2 will implement full spaces navigation.
// Version: 1.1.0 | Created: 2026-04-01
// Spaces screen — list of Matrix spaces with expandable child room lists.
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
class SpacesScreen extends StatelessWidget {
import '../data/spaces_repository.dart';
import '../domain/space_model.dart';
part 'spaces_screen.g.dart';
// ---------------------------------------------------------------------------
// Providers
// ---------------------------------------------------------------------------
@riverpod
Stream<List<SpaceModel>> spacesStream(Ref ref) {
return ref.watch(spacesRepositoryProvider).watchSpaces();
}
@riverpod
List<SpaceRoomModel> spaceRooms(Ref ref, String spaceId) {
return ref.watch(spacesRepositoryProvider).getRoomsInSpace(spaceId);
}
// ---------------------------------------------------------------------------
// Screen
// ---------------------------------------------------------------------------
class SpacesScreen extends ConsumerWidget {
const SpacesScreen({super.key, this.embedded = false});
final bool embedded;
@override
Widget build(BuildContext context) {
final body = Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.dashboard_outlined,
size: 64,
color: Theme.of(context).colorScheme.onSurface.withAlpha(77),
),
const SizedBox(height: 16),
Text(
'Spaces',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withAlpha(153),
),
),
const SizedBox(height: 8),
Text(
'Space navigation is coming in Phase 2.',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface.withAlpha(102),
),
),
],
Widget build(BuildContext context, WidgetRef ref) {
final spacesAsync = ref.watch(spacesStreamProvider);
final body = spacesAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, _) => Center(
child: Padding(
padding: const EdgeInsets.all(24),
child: Text('Could not load spaces: $err'),
),
),
data: (spaces) {
if (spaces.isEmpty) {
return _EmptySpacesState();
}
return ListView.builder(
itemCount: spaces.length,
itemBuilder: (context, index) {
return _SpaceTile(space: spaces[index]);
},
);
},
);
if (embedded) return body;
@@ -49,3 +67,191 @@ class SpacesScreen extends StatelessWidget {
);
}
}
// ---------------------------------------------------------------------------
// Space tile with expandable child room list
// ---------------------------------------------------------------------------
class _SpaceTile extends ConsumerStatefulWidget {
const _SpaceTile({required this.space});
final SpaceModel space;
@override
ConsumerState<_SpaceTile> createState() => _SpaceTileState();
}
class _SpaceTileState extends ConsumerState<_SpaceTile> {
bool _expanded = false;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final space = widget.space;
return Column(
children: [
// Space header row
ListTile(
leading: _SpaceAvatar(
name: space.displayName,
avatarUrl: space.avatarUrl,
),
title: Text(
space.displayName,
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w600,
),
),
subtitle: Text(
'${space.roomCount} ${space.roomCount == 1 ? 'room' : 'rooms'}',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(153),
),
),
trailing: space.roomCount > 0
? IconButton(
icon: Icon(
_expanded ? Icons.expand_less : Icons.expand_more,
color: theme.colorScheme.onSurface.withAlpha(153),
),
onPressed: () => setState(() => _expanded = !_expanded),
)
: null,
onTap: () => setState(() => _expanded = !_expanded),
),
// Child rooms — shown when expanded
if (_expanded) _ChildRoomList(spaceId: space.id),
const Divider(height: 1),
],
);
}
}
// ---------------------------------------------------------------------------
// Child room list
// ---------------------------------------------------------------------------
class _ChildRoomList extends ConsumerWidget {
const _ChildRoomList({required this.spaceId});
final String spaceId;
@override
Widget build(BuildContext context, WidgetRef ref) {
final rooms = ref.watch(spaceRoomsProvider(spaceId));
final theme = Theme.of(context);
if (rooms.isEmpty) {
return Padding(
padding: const EdgeInsets.only(left: 56, right: 16, bottom: 8),
child: Text(
'No joined rooms in this space.',
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(102),
),
),
);
}
return Column(
children: rooms.map((room) {
return ListTile(
contentPadding: const EdgeInsets.only(left: 56, right: 16),
leading: _SpaceAvatar(
name: room.displayName,
avatarUrl: room.avatarUrl,
radius: 18,
),
title: Text(room.displayName, style: theme.textTheme.bodyMedium),
trailing: room.isDirect
? Icon(
Icons.person_outline,
size: 16,
color: theme.colorScheme.onSurface.withAlpha(102),
)
: null,
onTap: () => context.push('/rooms/${Uri.encodeComponent(room.id)}'),
);
}).toList(),
);
}
}
// ---------------------------------------------------------------------------
// Avatar widget
// ---------------------------------------------------------------------------
class _SpaceAvatar extends StatelessWidget {
const _SpaceAvatar({required this.name, this.avatarUrl, this.radius = 22});
final String name;
final String? avatarUrl;
final double radius;
@override
Widget build(BuildContext context) {
final initials = name.isNotEmpty ? name[0].toUpperCase() : '?';
if (avatarUrl != null) {
return CircleAvatar(
radius: radius,
backgroundImage: NetworkImage(avatarUrl!),
);
}
return CircleAvatar(
radius: radius,
backgroundColor: Theme.of(context).colorScheme.secondary.withAlpha(51),
child: Text(
initials,
style: TextStyle(
fontSize: radius * 0.7,
color: Theme.of(context).colorScheme.secondary,
fontWeight: FontWeight.bold,
),
),
);
}
}
// ---------------------------------------------------------------------------
// Empty state
// ---------------------------------------------------------------------------
class _EmptySpacesState extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.dashboard_outlined,
size: 64,
color: theme.colorScheme.onSurface.withAlpha(77),
),
const SizedBox(height: 16),
Text(
'No spaces yet',
style: theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(153),
),
),
const SizedBox(height: 8),
Text(
'Spaces you join will appear here.',
textAlign: TextAlign.center,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurface.withAlpha(102),
),
),
],
),
),
);
}
}