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"),