diff --git a/lib/models/contact.dart b/lib/models/contact.dart index 064950c6..5ac0edd4 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -26,7 +26,6 @@ class ContactInfoState extends ChangeNotifier { // todo: a nicer way to model contacts, groups and other "entities" late bool _isGroup; String? _server; - double _serverSyncProgress = 0.0; late bool _archived; String? _acnCircuit; @@ -177,12 +176,6 @@ class ContactInfoState extends ChangeNotifier { // we only allow callers to fetch the server get server => this._server; - double get serverSyncProgress => this._serverSyncProgress; - set serverSyncProgress(double newProgress) { - _serverSyncProgress = newProgress; - notifyListeners(); - } - bool isOnline() { if (this.isGroup == true) { // We now have an out of sync warning so we will mark these as online... diff --git a/lib/models/remoteserver.dart b/lib/models/remoteserver.dart index b83a8844..f9e658dd 100644 --- a/lib/models/remoteserver.dart +++ b/lib/models/remoteserver.dart @@ -42,11 +42,12 @@ class RemoteServerInfoState extends ChangeNotifier { notifyListeners(); } + // updateSyncProgressFor point takes a message's time, and updates the server sync progress, + // based on that point in time between the precalculated lastPreSyncMessagTime and Now void updateSyncProgressFor(DateTime point) { var range = lastPreSyncMessagTime.difference(DateTime.now()); var pointFromStart = lastPreSyncMessagTime.difference(point); - syncProgress = pointFromStart.inSeconds / range.inSeconds * 100; - groups.forEach((g) { g.serverSyncProgress = syncProgress;}); + syncProgress = pointFromStart.inSeconds / range.inSeconds; notifyListeners(); } diff --git a/lib/views/contactsview.dart b/lib/views/contactsview.dart index 4e7b6ade..7f6b2236 100644 --- a/lib/views/contactsview.dart +++ b/lib/views/contactsview.dart @@ -3,6 +3,7 @@ import 'package:cwtch/models/appstate.dart'; import 'package:cwtch/models/contact.dart'; import 'package:cwtch/models/contactlist.dart'; import 'package:cwtch/models/profile.dart'; +import 'package:cwtch/models/profilelist.dart'; import 'package:cwtch/views/profileserversview.dart'; import 'package:flutter/material.dart'; import 'package:cwtch/widgets/contactrow.dart'; @@ -154,8 +155,15 @@ class _ContactsViewState extends State { Widget _buildContactList() { final tiles = Provider.of(context).filteredList().map((ContactInfoState contact) { - return ChangeNotifierProvider.value(key: ValueKey(contact.profileOnion + "" + contact.onion), value: contact, builder: (_, __) => RepaintBoundary(child: ContactRow())); + return MultiProvider( + providers: [ + ChangeNotifierProvider.value(value: contact), + ChangeNotifierProvider.value(value: Provider.of(context).serverList), + ], + builder: (context, child) => RepaintBoundary(child: ContactRow()), + ); }); + final divided = ListTile.divideTiles( context: context, tiles: tiles, diff --git a/lib/widgets/contactrow.dart b/lib/widgets/contactrow.dart index ef53d95a..b61b8ffa 100644 --- a/lib/widgets/contactrow.dart +++ b/lib/widgets/contactrow.dart @@ -67,7 +67,7 @@ class _ContactRowState extends State { visible: contact.isGroup && contact.status == "Authenticated", child: LinearProgressIndicator( color: Provider.of(context).theme.defaultButtonActiveColor, - value: contact.serverSyncProgress, + value: Provider.of(context).serverList.getServer(contact.server)?.syncProgress, )), Visibility( visible: !Provider.of(context).streamerMode, diff --git a/lib/widgets/profilerow.dart b/lib/widgets/profilerow.dart index 6d2c8e8e..acbdce0a 100644 --- a/lib/widgets/profilerow.dart +++ b/lib/widgets/profilerow.dart @@ -91,7 +91,7 @@ class _ProfileRowState extends State { return MultiProvider( providers: [ ChangeNotifierProvider.value(value: profile), - ChangeNotifierProvider.value(value: profile.contactList), + ChangeNotifierProvider.value(value: profile.contactList) ], builder: (innercontext, widget) { var appState = Provider.of(context);