From 589bc4c36cde956df74b333002f532a209ff1d11 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Thu, 20 Jan 2022 13:05:11 -0500 Subject: [PATCH] new lcg; cleanup --- LIBCWTCH-GO-MACOS.version | 2 +- LIBCWTCH-GO.version | 2 +- lib/models/contact.dart | 16 ++++++++-------- lib/models/message.dart | 18 +++++++++--------- lib/models/messagecache.dart | 5 ----- lib/views/messageview.dart | 2 +- 6 files changed, 20 insertions(+), 25 deletions(-) diff --git a/LIBCWTCH-GO-MACOS.version b/LIBCWTCH-GO-MACOS.version index c6c568fa..c0ed5239 100644 --- a/LIBCWTCH-GO-MACOS.version +++ b/LIBCWTCH-GO-MACOS.version @@ -1 +1 @@ -2022-01-19-16-16-v1.5.4-11-g84d451f \ No newline at end of file +2022-01-20-12-53-v1.5.4-14-g6865ec1 \ No newline at end of file diff --git a/LIBCWTCH-GO.version b/LIBCWTCH-GO.version index 8c390298..ee031103 100644 --- a/LIBCWTCH-GO.version +++ b/LIBCWTCH-GO.version @@ -1 +1 @@ -2022-01-19-21-15-v1.5.4-11-g84d451f \ No newline at end of file +2022-01-20-17-53-v1.5.4-14-g6865ec1 \ No newline at end of file diff --git a/lib/models/contact.dart b/lib/models/contact.dart index 3793fb91..6e432f1a 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -21,7 +21,6 @@ class ContactInfoState extends ChangeNotifier { late Map> keys; int _newMarker = 0; DateTime _newMarkerClearAt = DateTime.now(); - //late List messageCache; late MessageCache messageCache; // todo: a nicer way to model contacts, groups and other "entities" @@ -56,7 +55,6 @@ class ContactInfoState extends ChangeNotifier { this._lastMessageTime = lastMessageTime == null ? DateTime.fromMillisecondsSinceEpoch(0) : lastMessageTime; this._server = server; this._archived = archived; - //this.messageCache = List.empty(growable: true); this.messageCache = new MessageCache(); keys = Map>(); } @@ -66,6 +64,7 @@ class ContactInfoState extends ChangeNotifier { String get savePeerHistory => this._savePeerHistory; String? get acnCircuit => this._acnCircuit; + set acnCircuit(String? acnCircuit) { this._acnCircuit = acnCircuit; notifyListeners(); @@ -92,6 +91,7 @@ class ContactInfoState extends ChangeNotifier { } bool get isGroup => this._isGroup; + set isGroup(bool newVal) { this._isGroup = newVal; notifyListeners(); @@ -112,12 +112,14 @@ class ContactInfoState extends ChangeNotifier { } String get status => this._status; + set status(String newVal) { this._status = newVal; notifyListeners(); } int get unreadMessages => this._unreadMessages; + set unreadMessages(int newVal) { // don't reset newMarker position when unreadMessages is being cleared if (newVal > 0) { @@ -151,18 +153,21 @@ class ContactInfoState extends ChangeNotifier { } int get totalMessages => this._totalMessages; + set totalMessages(int newVal) { this._totalMessages = newVal; notifyListeners(); } String get imagePath => this._imagePath; + set imagePath(String newVal) { this._imagePath = newVal; notifyListeners(); } DateTime get lastMessageTime => this._lastMessageTime; + set lastMessageTime(DateTime newVal) { this._lastMessageTime = newVal; notifyListeners(); @@ -217,13 +222,8 @@ class ContactInfoState extends ChangeNotifier { } } - void bumpMessageCache() { - this.messageCache.bumpMessageCache(); - this.totalMessages += 1; - } - void ackCache(int messageID) { this.messageCache.ackCache(messageID); notifyListeners(); } -} \ No newline at end of file +} diff --git a/lib/models/message.dart b/lib/models/message.dart index 82fa7cd2..5ccfec23 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -141,15 +141,15 @@ Future fetchAndCacheMessageInfo(BuildContext context, String profi return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) { try { dynamic messageWrapper = jsonDecode(rawMessageEnvelope); -// There are 2 conditions in which this error condition can be met: -// 1. The application == nil, in which case this instance of the UI is already -// broken beyond repair, and will either be replaced by a new version, or requires a complete -// restart. -// 2. This index was incremented and we happened to fetch the timeline prior to the messages inclusion. -// This should be rare as Timeline addition/fetching is mutex protected and Dart itself will pipeline the -// calls to libCwtch-go - however because we use goroutines on the backend there is always a chance that one -// will find itself delayed. -// The second case is recoverable by tail-recursing this future. + // There are 2 conditions in which this error condition can be met: + // 1. The application == nil, in which case this instance of the UI is already + // broken beyond repair, and will either be replaced by a new version, or requires a complete + // restart. + // 2. This index was incremented and we happened to fetch the timeline prior to the messages inclusion. + // This should be rare as Timeline addition/fetching is mutex protected and Dart itself will pipeline the + // calls to libCwtch-go - however because we use goroutines on the backend there is always a chance that one + // will find itself delayed. + // The second case is recoverable by tail-recursing this future. if (messageWrapper['Message'] == null || messageWrapper['Message'] == '' || messageWrapper['Message'] == '{}') { return Future.delayed(Duration(seconds: 2), () { print("Tail recursive call to messageHandler called. This should be a rare event. If you see multiples of this log over a short period of time please log it as a bug."); diff --git a/lib/models/messagecache.dart b/lib/models/messagecache.dart index 3c11e526..d8eaa999 100644 --- a/lib/models/messagecache.dart +++ b/lib/models/messagecache.dart @@ -51,11 +51,6 @@ class MessageCache { } } - // TODO inserting nulls travel down list causing fails for all - void bumpMessageCache() { - this.cacheByIndex.insert(0, null); - } - void ackCache(int messageID) { cache[messageID]?.metadata.ackd = true; } diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index e2a22ba6..d1768161 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -227,9 +227,9 @@ class _MessageViewState extends State { Future.delayed(const Duration(milliseconds: 80), () { var profile = Provider.of(context, listen: false).profileOnion; var identifier = Provider.of(context, listen: false).identifier; - //Provider.of(context, listen: false).contactList.getContact(Provider.of(context, listen: false).identifier)?.bumpMessageCache(); fetchAndCacheMessageInfo(context, profile, identifier, byIndex: true, index: 0); Provider.of(context, listen: false).newMarker++; + Provider.of(context, listen: false).totalMessages += 1; // Resort the contact list... Provider.of(context, listen: false).contactList.updateLastMessageTime(Provider.of(context, listen: false).identifier, DateTime.now()); });