diff --git a/lib/model.dart b/lib/model.dart index cb4fd9e..33dcf5b 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -98,7 +98,7 @@ class ContactListState extends ChangeNotifier { contact.lastMessageTime = newVal; _contacts.sort((ContactInfoState a, ContactInfoState b) { - if (a.lastMessageTime == null && b.lastMessageTime == null) return b.onion.compareTo(b.onion); + if (a.lastMessageTime == null && b.lastMessageTime == null) return b.onion.compareTo(a.onion); if (a.lastMessageTime == null) return 1; if (b.lastMessageTime == null) return -1; return b.lastMessageTime.compareTo(a.lastMessageTime); diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 090a52d..52b0959 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -39,20 +39,27 @@ class _MessageViewState extends State { @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text(Provider.of(context).nickname), - actions: [ - IconButton(icon: Icon(Icons.chat), onPressed: _pushContactSettings), - IconButton(icon: Icon(Icons.list), onPressed: _pushContactSettings), - IconButton(icon: Icon(Icons.push_pin), onPressed: _pushContactSettings), - IconButton(icon: Icon(Icons.settings), onPressed: _pushContactSettings), - IconButton(icon: Icon(Icons.bug_report_outlined), onPressed: _debugResetContact), - ], - ), - body: Padding(padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 108.0), child: MessageList()), - bottomSheet: _buildComposeBox(), - ); + return WillPopScope( + onWillPop: _onWillPop, + child: Scaffold( + appBar: AppBar( + title: Text(Provider.of(context).nickname), + actions: [ + IconButton(icon: Icon(Icons.chat), onPressed: _pushContactSettings), + IconButton(icon: Icon(Icons.list), onPressed: _pushContactSettings), + IconButton(icon: Icon(Icons.push_pin), onPressed: _pushContactSettings), + IconButton(icon: Icon(Icons.settings), onPressed: _pushContactSettings), + IconButton(icon: Icon(Icons.bug_report_outlined), onPressed: _debugResetContact), + ], + ), + body: Padding(padding: EdgeInsets.fromLTRB(8.0, 8.0, 8.0, 108.0), child: MessageList()), + bottomSheet: _buildComposeBox(), + )); + } + + Future _onWillPop() async { + Provider.of(context, listen: false).unreadMessages = 0; + return true; } void _debugResetContact() { diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index 20560ff..37ab97a 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -87,6 +87,7 @@ class _ContactRowState extends State { } void _pushMessageView(String handle) { + Provider.of(context).contactList.getContact(handle).unreadMessages = 0; Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext builderContext) {