diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index 74f395ab..ea93c064 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -146,7 +146,17 @@ class CwtchNotifier { String? contenthash = data['ContentHash']; var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier; - profileCN.getProfile(data["ProfileOnion"])?.contactList.newMessage(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data["Data"], contenthash, selectedConversation, ); + profileCN.getProfile(data["ProfileOnion"])?.contactList.newMessage( + identifier, + messageID, + timestamp, + senderHandle, + senderImage, + isAuto, + data["Data"], + contenthash, + selectedConversation, + ); break; case "PeerAcknowledgement": @@ -188,7 +198,6 @@ class CwtchNotifier { String? contenthash = data['ContentHash']; var selectedConversation = appState.selectedProfile == data["ProfileOnion"] && appState.selectedConversation == identifier; - // Only bother to do anything if we know about the group and the provided index is greater than our current total... if (currentTotal != null && idx >= currentTotal) { // TODO: There are 2 timestamps associated with a new group message - time sent and time received. diff --git a/lib/models/appstate.dart b/lib/models/appstate.dart index 39ae8454..8386b8dd 100644 --- a/lib/models/appstate.dart +++ b/lib/models/appstate.dart @@ -68,4 +68,4 @@ class AppState extends ChangeNotifier { } bool isLandscape(BuildContext c) => MediaQuery.of(c).size.width > MediaQuery.of(c).size.height; -} \ No newline at end of file +} diff --git a/lib/models/contact.dart b/lib/models/contact.dart index 6e432f1a..d39aa193 100644 --- a/lib/models/contact.dart +++ b/lib/models/contact.dart @@ -220,6 +220,7 @@ class ContactInfoState extends ChangeNotifier { if (isOnline() == false) { status = "Authenticated"; } + notifyListeners(); } void ackCache(int messageID) { diff --git a/lib/models/contactlist.dart b/lib/models/contactlist.dart index d54dfdf3..f4aaadcf 100644 --- a/lib/models/contactlist.dart +++ b/lib/models/contactlist.dart @@ -127,4 +127,4 @@ class ContactListState extends ChangeNotifier { getContact(identifier)?.newMessage(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data, contenthash, selectedConversation); updateLastMessageTime(identifier, DateTime.now()); } -} \ No newline at end of file +} diff --git a/lib/models/message.dart b/lib/models/message.dart index 5ccfec23..52070666 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -74,14 +74,14 @@ Future messageHandler(BuildContext context, String profileOnion, int co } // Hit cache - MessageInfo? messageInfo = getMessageInfoFromCache(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash); + MessageInfo? messageInfo = getMessageInfoFromCache(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash); if (messageInfo != null) { return Future.value(compileOverlay(messageInfo.metadata, messageInfo.wrapper)); } // Fetch and Cache - var messageInfoFuture = fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash); - return messageInfoFuture.then( (MessageInfo? messageInfo) { + var messageInfoFuture = fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash); + return messageInfoFuture.then((MessageInfo? messageInfo) { if (messageInfo != null) { return compileOverlay(messageInfo.metadata, messageInfo.wrapper); } else { @@ -91,7 +91,7 @@ Future messageHandler(BuildContext context, String profileOnion, int co } MessageInfo? getMessageInfoFromCache(BuildContext context, String profileOnion, int conversationIdentifier, -{bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) { + {bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) { // Hit cache try { var cache = Provider.of(context, listen: false).contactList.getContact(conversationIdentifier)?.messageCache; @@ -116,26 +116,17 @@ MessageInfo? getMessageInfoFromCache(BuildContext context, String profileOnion, } Future fetchAndCacheMessageInfo(BuildContext context, String profileOnion, int conversationIdentifier, -{bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) { + {bool byIndex = false, int? index, bool byID = false, int? id, bool byHash = false, String? hash}) { // Load and cache try { Future rawMessageEnvelopeFuture; if (byID) { - rawMessageEnvelopeFuture = Provider - .of(context, listen: false) - .cwtch - .GetMessageByID(profileOnion, conversationIdentifier, id!); + rawMessageEnvelopeFuture = Provider.of(context, listen: false).cwtch.GetMessageByID(profileOnion, conversationIdentifier, id!); } else if (byHash) { - rawMessageEnvelopeFuture = Provider - .of(context, listen: false) - .cwtch - .GetMessageByContentHash(profileOnion, conversationIdentifier, hash!); + rawMessageEnvelopeFuture = Provider.of(context, listen: false).cwtch.GetMessageByContentHash(profileOnion, conversationIdentifier, hash!); } else { - rawMessageEnvelopeFuture = Provider - .of(context, listen: false) - .cwtch - .GetMessage(profileOnion, conversationIdentifier, index!); + rawMessageEnvelopeFuture = Provider.of(context, listen: false).cwtch.GetMessage(profileOnion, conversationIdentifier, index!); } return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) { @@ -153,12 +144,7 @@ Future fetchAndCacheMessageInfo(BuildContext context, String profi 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."); - return fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, - index: index, - byID: byID, - id: id, - byHash: byHash, - hash: hash).then((value) => value); + return fetchAndCacheMessageInfo(context, profileOnion, conversationIdentifier, byIndex: byIndex, index: index, byID: byID, id: id, byHash: byHash, hash: hash).then((value) => value); }); } @@ -173,25 +159,10 @@ Future fetchAndCacheMessageInfo(BuildContext context, String profi var signature = messageWrapper['Signature']; var contenthash = messageWrapper['ContentHash']; var localIndex = messageWrapper['LocalIndex']; - var metadata = MessageMetadata( - profileOnion, - conversationIdentifier, - messageID, - timestamp, - senderHandle, - senderImage, - signature, - attributes, - ackd, - error, - false); + var metadata = MessageMetadata(profileOnion, conversationIdentifier, messageID, timestamp, senderHandle, senderImage, signature, attributes, ackd, error, false); var messageInfo = new MessageInfo(metadata, messageWrapper['Message']); - var cache = Provider - .of(context, listen: false) - .contactList - .getContact(conversationIdentifier) - ?.messageCache; + var cache = Provider.of(context, listen: false).contactList.getContact(conversationIdentifier)?.messageCache; if (cache != null) { if (byID) { diff --git a/lib/models/messagecache.dart b/lib/models/messagecache.dart index d8eaa999..a2deae4e 100644 --- a/lib/models/messagecache.dart +++ b/lib/models/messagecache.dart @@ -26,6 +26,7 @@ class MessageCache { } return cache[cacheByIndex[index]]; } + MessageInfo? getByContentHash(String contenthash) => cache[cacheByHash[contenthash]]; void addNew(String profileOnion, int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data, String? contenthash) { @@ -54,4 +55,4 @@ class MessageCache { void ackCache(int messageID) { cache[messageID]?.metadata.ackd = true; } -} \ No newline at end of file +} diff --git a/lib/models/messages/quotedmessage.dart b/lib/models/messages/quotedmessage.dart index 68615f18..7f5053d9 100644 --- a/lib/models/messages/quotedmessage.dart +++ b/lib/models/messages/quotedmessage.dart @@ -59,8 +59,7 @@ class QuotedMessage extends Message { return ChangeNotifierProvider.value( value: this.metadata, builder: (bcontext, child) { - return MessageRow( - QuotedMessageBubble(message["body"], messageHandler(bcontext, metadata.profileOnion, metadata.conversationIdentifier, byHash: true, hash: message["quotedHash"])), + return MessageRow(QuotedMessageBubble(message["body"], messageHandler(bcontext, metadata.profileOnion, metadata.conversationIdentifier, byHash: true, hash: message["quotedHash"])), key: key); }); } catch (e) { diff --git a/lib/views/messageview.dart b/lib/views/messageview.dart index d1768161..bc811f67 100644 --- a/lib/views/messageview.dart +++ b/lib/views/messageview.dart @@ -284,8 +284,8 @@ class _MessageViewState extends State { var children; if (Provider.of(context).selectedConversation != null && Provider.of(context).selectedIndex != null) { var quoted = FutureBuilder( - future: - messageHandler(context, Provider.of(context).selectedProfile!, Provider.of(context).selectedConversation!, id: Provider.of(context).selectedIndex!, byID: true), + future: messageHandler(context, Provider.of(context).selectedProfile!, Provider.of(context).selectedConversation!, + id: Provider.of(context).selectedIndex!, byID: true), builder: (context, snapshot) { if (snapshot.hasData) { var message = snapshot.data! as Message;