refactor: conditionalize profile fields, update chat navigation transitions, and fix provider state management during widget lifecycle
This commit is contained in:
@@ -75,7 +75,8 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
MessagingNotifier(this._repository, this._ref)
|
||||
: super(const MessagingState()) {
|
||||
_initSocketListeners();
|
||||
loadUnreadCount();
|
||||
// Defer to avoid modifying provider during widget tree build
|
||||
Future.microtask(() => loadUnreadCount());
|
||||
}
|
||||
|
||||
String? get _currentUserId => _ref.read(authProvider).user?.id;
|
||||
@@ -529,6 +530,7 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
Future<void> markAsRead(String conversationId) async {
|
||||
try {
|
||||
await _repository.markAsRead(conversationId);
|
||||
if (!mounted) return;
|
||||
|
||||
final updatedConversations = state.conversations.map((c) {
|
||||
if (c.id == conversationId) {
|
||||
@@ -550,6 +552,7 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
}
|
||||
|
||||
void setActiveConversation(String? conversationId) {
|
||||
if (!mounted) return;
|
||||
if (conversationId == null) {
|
||||
state = state.copyWith(clearActiveConversation: true);
|
||||
} else {
|
||||
@@ -560,7 +563,7 @@ class MessagingNotifier extends StateNotifier<MessagingState> {
|
||||
Future<void> loadUnreadCount() async {
|
||||
try {
|
||||
final count = await _repository.getUnreadCount();
|
||||
state = state.copyWith(unreadCount: count);
|
||||
if (mounted) state = state.copyWith(unreadCount: count);
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user