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:
222
lib/features/rooms/presentation/user_search_dialog.dart
Normal file
222
lib/features/rooms/presentation/user_search_dialog.dart
Normal file
@@ -0,0 +1,222 @@
|
||||
// Version: 1.1.0 | Created: 2026-04-01
|
||||
// User search dialog — search Matrix user directory and start a DM.
|
||||
// Triggered from the rooms screen "New message" button.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:matrix/matrix_api_lite.dart' show Profile;
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
|
||||
import '../../../core/network/matrix_client.dart';
|
||||
|
||||
part 'user_search_dialog.g.dart';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Provider
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@riverpod
|
||||
Future<List<Profile>> searchUsers(Ref ref, String term) async {
|
||||
if (term.trim().length < 2) return [];
|
||||
final client = ref.watch(matrixClientProvider);
|
||||
final result = await client.searchUserDirectory(term.trim(), limit: 20);
|
||||
return result.results;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Dialog
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Show user search as a modal dialog. On user selected, navigates to DM room.
|
||||
Future<void> showUserSearchDialog(BuildContext context) async {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (_) => const _UserSearchDialog(),
|
||||
);
|
||||
}
|
||||
|
||||
class _UserSearchDialog extends ConsumerStatefulWidget {
|
||||
const _UserSearchDialog();
|
||||
|
||||
@override
|
||||
ConsumerState<_UserSearchDialog> createState() => _UserSearchDialogState();
|
||||
}
|
||||
|
||||
class _UserSearchDialogState extends ConsumerState<_UserSearchDialog> {
|
||||
final _controller = TextEditingController();
|
||||
String _searchTerm = '';
|
||||
bool _isStartingDm = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _startDm(String userId) async {
|
||||
if (_isStartingDm) return;
|
||||
setState(() => _isStartingDm = true);
|
||||
|
||||
try {
|
||||
final client = ref.read(matrixClientProvider);
|
||||
final roomId = await client.startDirectChat(userId);
|
||||
if (!mounted) return;
|
||||
Navigator.of(context).pop(); // close the dialog
|
||||
context.push('/rooms/${Uri.encodeComponent(roomId)}');
|
||||
} on Exception catch (e) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Could not start conversation: $e')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) setState(() => _isStartingDm = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Dialog(
|
||||
insetPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 32),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 480, maxHeight: 520),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Header
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 4, 0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'New message',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Search field
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: TextField(
|
||||
controller: _controller,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Search by name or user ID…',
|
||||
prefixIcon: Icon(Icons.search),
|
||||
),
|
||||
onChanged: (val) => setState(() => _searchTerm = val),
|
||||
),
|
||||
),
|
||||
|
||||
// Results
|
||||
Flexible(
|
||||
child: _searchTerm.trim().length < 2
|
||||
? Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(
|
||||
'Type a name or @user:server to search.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withAlpha(102),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
)
|
||||
: _SearchResults(
|
||||
term: _searchTerm,
|
||||
isLoading: _isStartingDm,
|
||||
onSelect: _startDm,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SearchResults extends ConsumerWidget {
|
||||
const _SearchResults({
|
||||
required this.term,
|
||||
required this.isLoading,
|
||||
required this.onSelect,
|
||||
});
|
||||
|
||||
final String term;
|
||||
final bool isLoading;
|
||||
final Future<void> Function(String userId) onSelect;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final resultsAsync = ref.watch(searchUsersProvider(term));
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return resultsAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (err, _) => Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text('Search failed: $err'),
|
||||
),
|
||||
data: (profiles) {
|
||||
if (profiles.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text(
|
||||
'No users found.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withAlpha(102),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: profiles.length,
|
||||
itemBuilder: (context, index) {
|
||||
final profile = profiles[index];
|
||||
final displayName = profile.displayName ?? profile.userId;
|
||||
final initials = displayName.isNotEmpty
|
||||
? displayName[0].toUpperCase()
|
||||
: '?';
|
||||
|
||||
return ListTile(
|
||||
leading: profile.avatarUrl != null
|
||||
? CircleAvatar(
|
||||
backgroundImage: NetworkImage(
|
||||
profile.avatarUrl.toString(),
|
||||
),
|
||||
)
|
||||
: CircleAvatar(
|
||||
backgroundColor: theme.colorScheme.primary.withAlpha(51),
|
||||
child: Text(
|
||||
initials,
|
||||
style: TextStyle(color: theme.colorScheme.primary),
|
||||
),
|
||||
),
|
||||
title: Text(displayName),
|
||||
subtitle: Text(
|
||||
profile.userId,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface.withAlpha(153),
|
||||
),
|
||||
),
|
||||
enabled: !isLoading,
|
||||
onTap: () => onSelect(profile.userId),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user