diff --git a/lib/main.dart b/lib/main.dart index fe9b83d..05d2bfd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -63,7 +63,7 @@ class FlwtchState extends State { appStatus = AppModel(cwtch: cwtch); } - ChangeNotifierProvider getSettingsProvider() => ChangeNotifierProvider(create: (context) => globalSettings); + ChangeNotifierProvider getSettingsProvider() => ChangeNotifierProvider.value(value: globalSettings); Provider getFlwtchStateProvider() => Provider(create: (_) => this); ChangeNotifierProvider getProfileListProvider() => ChangeNotifierProvider(create: (context) => profs); diff --git a/lib/model.dart b/lib/model.dart index e6ceed3..a5c54a6 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -145,7 +145,9 @@ class ProfileInfoState extends ChangeNotifier { status: contact["status"], imagePath: contact["picture"], isBlocked: contact["authorization"] == "blocked", - savePeerHistory: contact["saveConversationHistory"]); + savePeerHistory: contact["saveConversationHistory"], + numMessages: contact["numMessages"], + numUnread: contact["numUnread"]); })); } } @@ -188,14 +190,17 @@ class ContactInfoState extends ChangeNotifier { String _imagePath; String _savePeerHistory; int _unreadMessages = 0; + int _totalMessages = 0; - ContactInfoState({this.profileOnion, this.onion, nickname = "", isGroup = false, isInvitation = false, isBlocked = false, status = "", imagePath = "", savePeerHistory = "DeleteHistoryConfirmed"}) { + ContactInfoState({this.profileOnion, this.onion, nickname = "", isGroup = false, isInvitation = false, isBlocked = false, status = "", imagePath = "", savePeerHistory = "DeleteHistoryConfirmed", numMessages = 0, numUnread = 0,}) { this._nickname = nickname; this._isGroup = isGroup; this._isInvitation = isInvitation; this._isBlocked = isBlocked; this._status = status; this._imagePath = imagePath; + this._totalMessages = numMessages; + this._unreadMessages = numUnread; this._savePeerHistory = savePeerHistory; } @@ -236,6 +241,12 @@ class ContactInfoState extends ChangeNotifier { notifyListeners(); } + get totalMessages => this._totalMessages; + set totalMessages(int newVal) { + this._totalMessages = newVal; + notifyListeners(); + } + get imagePath => this._imagePath; set imagePath(String newVal) { this._imagePath = newVal; diff --git a/lib/views/doublecolview.dart b/lib/views/doublecolview.dart index 04249ac..ef632e7 100644 --- a/lib/views/doublecolview.dart +++ b/lib/views/doublecolview.dart @@ -26,7 +26,7 @@ class _DoubleColumnViewState extends State { child: flwtch.selectedConversation == "" ? Center(child: Text("pick a contact")) : //dev - Container(child: MessageView(profile: flwtch.selectedProfile, conversationHandle: flwtch.selectedConversation)), + Container(child: MessageView()), ), ], ); diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index 53eab3d..f1de90b 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -8,10 +8,6 @@ import '../opaque.dart'; import '../widgets/messagelist.dart'; class MessageView extends StatefulWidget { - const MessageView({Key key, this.profile, this.conversationHandle}) : super(key: key); - final ProfileInfoState profile; - final String conversationHandle; - @override _MessageViewState createState() => _MessageViewState(); } @@ -29,7 +25,7 @@ class _MessageViewState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(widget.conversationHandle), + title: Text(Provider.of(context).onion), actions: [ IconButton(icon: Icon(Icons.chat), onPressed: _pushContactSettings), IconButton(icon: Icon(Icons.list), onPressed: _pushContactSettings), @@ -37,7 +33,7 @@ class _MessageViewState extends State { IconButton(icon: Icon(Icons.settings), onPressed: _pushContactSettings), ], ), - body: MessageList(profile: widget.profile, conversationHandle: widget.conversationHandle), + body: MessageList(), bottomSheet: _buildComposeBox(), ); } diff --git a/lib/views/triplecolview.dart b/lib/views/triplecolview.dart index ff5e475..2388bd3 100644 --- a/lib/views/triplecolview.dart +++ b/lib/views/triplecolview.dart @@ -29,7 +29,7 @@ class _TripleColumnViewState extends State { child: flwtch.selectedConversation == "" ? Center(child: Text("pick a contact")) : //dev - Container(child: MessageView(profile: flwtch.selectedProfile, conversationHandle: flwtch.selectedConversation)), + Container(child: MessageView()), ), ]); } diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index 3857a64..0de405d 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -63,7 +63,7 @@ class _ContactRowState extends State { ChangeNotifierProvider.value(value: Provider.of(context)), ChangeNotifierProvider.value(value: Provider.of(context)), ], - child: MessageView(conversationHandle: handle), + child: MessageView(), ); }, ), diff --git a/lib/widgets/messagelist.dart b/lib/widgets/messagelist.dart index 5b7d245..be7d09d 100644 --- a/lib/widgets/messagelist.dart +++ b/lib/widgets/messagelist.dart @@ -1,61 +1,26 @@ -import 'dart:async'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import '../main.dart'; import '../model.dart'; import 'messagebubble.dart'; class MessageList extends StatefulWidget { - final ProfileInfoState profile; - final String conversationHandle; - - const MessageList({Key key, this.profile, this.conversationHandle}) : super(key: key); - @override _MessageListState createState() => _MessageListState(); } class _MessageListState extends State { - int conversationNumMessages = 0; - Timer timer; - @override - Widget build(BuildContext context) { - _updateMessageCount(context); - if (timer == null) { - timer = Timer.periodic(Duration(seconds: 1), (Timer t) { - _updateMessageCount(context); - }); - } - - return ProxyProvider0( - update: (_, __) => MessageCounter(conversationNumMessages), - child: ListView.builder( - itemCount: conversationNumMessages, - itemBuilder: (context, index) { - return MessageBubble( - profile: Provider.of(context), - contactOnion: widget.conversationHandle, - messageIndex: index, - ); - }, - )); + Widget build(BuildContext outerContext) { + return ListView.builder( + itemCount: Provider.of(context).totalMessages, + itemBuilder: (context, index) { + return MessageBubble( + profile: Provider.of(outerContext), + contactOnion: Provider.of(outerContext).onion, + messageIndex: index, + ); + }, + ); } - - Future _updateMessageCount(BuildContext context) async { - if (!mounted) { - if (timer != null && timer.isActive) timer.cancel(); - return; - } - - Provider.of(context, listen: false).cwtch.NumMessages(Provider.of(context, listen: false).onion, widget.conversationHandle).then((n) { - if (n != conversationNumMessages) setState(() => conversationNumMessages = n); - }); - } -} - -class MessageCounter { - MessageCounter(this.x); - int x = 0; -} +} \ No newline at end of file