From 8a9ee402bff4f1dabd300b5f53b361e1baa71d4e Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 3 Feb 2022 08:43:02 -0500 Subject: [PATCH] recalculate unrad count incases some not read --- lib/models/profile.dart | 5 +++++ lib/views/contactsview.dart | 1 + lib/widgets/profilerow.dart | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/models/profile.dart b/lib/models/profile.dart index 2c193865..ee10ec47 100644 --- a/lib/models/profile.dart +++ b/lib/models/profile.dart @@ -120,6 +120,10 @@ class ProfileInfoState extends ChangeNotifier { notifyListeners(); } + void recountUnread() { + this._unreadMessages = _contacts.contacts.fold(0, (i, c) => i + c.unreadMessages); + } + // Remove a contact from a list. Currently only used when rejecting a group invitation. // Eventually will also be used for other removals. void removeContact(String handle) { @@ -168,6 +172,7 @@ class ProfileInfoState extends ChangeNotifier { lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])), )); } + unreadMessages += int.parse(contact["numUnread"]); }); } this._contacts.resort(); diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index c7ab0271..24168764 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -81,6 +81,7 @@ class _ContactsViewState extends State { icon: Icon(Icons.arrow_back), tooltip: MaterialLocalizations.of(context).backButtonTooltip, onPressed: () { + Provider.of(context, listen: false).recountUnread(); Provider.of(context, listen: false).selectedProfile = ""; Navigator.of(context).pop(); }, diff --git a/lib/widgets/profilerow.dart b/lib/widgets/profilerow.dart index 2ddda6d9..0554373d 100644 --- a/lib/widgets/profilerow.dart +++ b/lib/widgets/profilerow.dart @@ -1,6 +1,7 @@ import 'package:cwtch/models/appstate.dart'; import 'package:cwtch/models/contactlist.dart'; import 'package:cwtch/models/profile.dart'; +import 'package:cwtch/models/profilelist.dart'; import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; import 'package:cwtch/views/addeditprofileview.dart'; @@ -83,7 +84,6 @@ class _ProfileRowState extends State { } void _pushContactList(ProfileInfoState profile, bool isLandscape) { - Provider.of(context, listen: false).unreadMessages = 0; Navigator.of(context).push( MaterialPageRoute( settings: RouteSettings(name: "conversations"),