Skip to content

Commit 9a891b4

Browse files
committed
feat: synchronize user profile name with mesh identity
1 parent e775f4e commit 9a891b4

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

lib/src/features/onboarding/presentation/onboarding_controller.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:flutter_background_service/flutter_background_service.dart';
33
import 'package:riverpod_annotation/riverpod_annotation.dart';
44
import 'package:off_chat/src/features/profile/presentation/profile_controller.dart';
55
import 'package:off_chat/src/features/profile/domain/user_model.dart';
6+
import 'package:off_chat/src/features/discovery/presentation/advertising_state.dart';
67
import 'package:logging/logging.dart';
78

89
part 'onboarding_controller.g.dart';
@@ -44,6 +45,9 @@ class OnboardingController extends _$OnboardingController {
4445
_log.info('Saving user profile to SharedPreferences...');
4546
await user.save();
4647

48+
// Sync with Mesh Identity
49+
await ref.read(advertisingNameProvider.notifier).change(username);
50+
4751
// Initialize background service without blocking the state update
4852
_log.info('Initializing background service in background...');
4953
initializeBackgroundService().then((_) {

lib/src/features/profile/presentation/profile_controller.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:convert';
22
import 'package:riverpod_annotation/riverpod_annotation.dart';
33
import 'package:off_chat/src/core/database/database_provider.dart';
44
import 'package:off_chat/src/features/profile/domain/user_model.dart';
5+
import 'package:off_chat/src/features/discovery/presentation/advertising_state.dart';
56
import 'package:logging/logging.dart';
67

78
part 'profile_controller.g.dart';
@@ -37,7 +38,11 @@ class ProfileController extends _$ProfileController {
3738
Future<void> updateUsername(String name) async {
3839
final user = state.value;
3940
if (user != null) {
40-
await _saveProfile(user.copyWith(username: name));
41+
final trimmed = name.trim();
42+
await _saveProfile(user.copyWith(username: trimmed));
43+
44+
// Use existing advertisingNameProvider logic to sync with mesh
45+
await ref.read(advertisingNameProvider.notifier).change(trimmed);
4146
}
4247
}
4348

lib/src/features/profile/presentation/profile_screen.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
2222
@override
2323
void initState() {
2424
super.initState();
25-
// Initialize controller with current advertising name
25+
// Initialize controller with current profile name
2626
Future.microtask(() async {
27-
final currentName = await ref.read(advertisingNameProvider.future);
28-
_nameController.text = currentName;
27+
final profile = await ref.read(profileControllerProvider.future);
28+
if (profile != null) {
29+
setState(() {
30+
_nameController.text = profile.username;
31+
});
32+
}
2933
});
3034
}
3135

@@ -251,9 +255,9 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
251255
maxLength: BLEAdvertiser.maxNameLength,
252256
style: const TextStyle(color: AppTheme.onSurfaceVariant),
253257
decoration: InputDecoration(
254-
labelText: 'Display Alias',
258+
labelText: 'User Identity',
255259
labelStyle: TextStyle(color: AppTheme.onSurfaceVariant.withValues(alpha: 0.38)),
256-
hintText: 'Enter mesh name...',
260+
hintText: 'Enter your name...',
257261
border: OutlineInputBorder(
258262
borderRadius: BorderRadius.circular(16),
259263
borderSide: BorderSide(color: AppTheme.onSurfaceVariant.withValues(alpha: 0.1)),
@@ -272,14 +276,16 @@ class _ProfileScreenState extends ConsumerState<ProfileScreen> {
272276
onPressed: () {
273277
final newName = _nameController.text.trim();
274278
if (newName.isNotEmpty) {
275-
ref.read(advertisingNameProvider.notifier).change(newName);
279+
ref.read(profileControllerProvider.notifier).updateUsername(newName);
276280
ScaffoldMessenger.of(context).showSnackBar(
277-
const SnackBar(content: Text('Identity synchronized with mesh')),
281+
const SnackBar(content: Text('Profile identity updated')),
278282
);
283+
// Clear focus
284+
FocusScope.of(context).unfocus();
279285
}
280286
},
281-
icon: const Icon(Icons.sync, size: 18),
282-
label: const Text('SYNC NAME'),
287+
icon: const Icon(Icons.save, size: 18),
288+
label: const Text('UPDATE PROFILE'),
283289
style: ElevatedButton.styleFrom(
284290
padding: const EdgeInsets.symmetric(vertical: 12),
285291
),

0 commit comments

Comments
 (0)