recalculate unrad count incases some not read

This commit is contained in:
Dan Ballard 2022-02-03 08:43:02 -05:00
parent 1a9f0763d7
commit 8a9ee402bf
3 changed files with 7 additions and 1 deletions

View File

@ -120,6 +120,10 @@ class ProfileInfoState extends ChangeNotifier {
notifyListeners(); 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. // Remove a contact from a list. Currently only used when rejecting a group invitation.
// Eventually will also be used for other removals. // Eventually will also be used for other removals.
void removeContact(String handle) { void removeContact(String handle) {
@ -168,6 +172,7 @@ class ProfileInfoState extends ChangeNotifier {
lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])), lastMessageTime: DateTime.fromMillisecondsSinceEpoch(1000 * int.parse(contact["lastMsgTime"])),
)); ));
} }
unreadMessages += int.parse(contact["numUnread"]);
}); });
} }
this._contacts.resort(); this._contacts.resort();

View File

@ -81,6 +81,7 @@ class _ContactsViewState extends State<ContactsView> {
icon: Icon(Icons.arrow_back), icon: Icon(Icons.arrow_back),
tooltip: MaterialLocalizations.of(context).backButtonTooltip, tooltip: MaterialLocalizations.of(context).backButtonTooltip,
onPressed: () { onPressed: () {
Provider.of<ProfileInfoState>(context, listen: false).recountUnread();
Provider.of<AppState>(context, listen: false).selectedProfile = ""; Provider.of<AppState>(context, listen: false).selectedProfile = "";
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },

View File

@ -1,6 +1,7 @@
import 'package:cwtch/models/appstate.dart'; import 'package:cwtch/models/appstate.dart';
import 'package:cwtch/models/contactlist.dart'; import 'package:cwtch/models/contactlist.dart';
import 'package:cwtch/models/profile.dart'; import 'package:cwtch/models/profile.dart';
import 'package:cwtch/models/profilelist.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:cwtch/views/addeditprofileview.dart'; import 'package:cwtch/views/addeditprofileview.dart';
@ -83,7 +84,6 @@ class _ProfileRowState extends State<ProfileRow> {
} }
void _pushContactList(ProfileInfoState profile, bool isLandscape) { void _pushContactList(ProfileInfoState profile, bool isLandscape) {
Provider.of<ProfileInfoState>(context, listen: false).unreadMessages = 0;
Navigator.of(context).push( Navigator.of(context).push(
MaterialPageRoute<void>( MaterialPageRoute<void>(
settings: RouteSettings(name: "conversations"), settings: RouteSettings(name: "conversations"),