From 6e9fb6810e57eab1040ded5227a18ec8b3d6a78d Mon Sep 17 00:00:00 2001 From: erinn Date: Thu, 16 Dec 2021 17:04:29 -0800 Subject: [PATCH] message previews --- lib/cwtch/cwtchNotifier.dart | 6 ++++-- lib/model.dart | 4 ++-- lib/models/message.dart | 9 +++++---- lib/models/messages/filemessage.dart | 3 ++- lib/settings.dart | 6 +----- lib/widgets/filebubble.dart | 10 +++++++--- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/cwtch/cwtchNotifier.dart b/lib/cwtch/cwtchNotifier.dart index be5429bf..67add61d 100644 --- a/lib/cwtch/cwtchNotifier.dart +++ b/lib/cwtch/cwtchNotifier.dart @@ -135,6 +135,7 @@ class CwtchNotifier { var timestamp = DateTime.tryParse(data['TimestampReceived'])!; var senderHandle = data['RemotePeer']; var senderImage = data['Picture']; + var isAuto = data['Auto'] == "true"; // We might not have received a contact created for this contact yet... // In that case the **next** event we receive will actually update these values... @@ -145,7 +146,7 @@ class CwtchNotifier { profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.newMarker++; } profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(identifier, DateTime.now()); - profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, messageID, timestamp, senderHandle, senderImage, data["Data"]); + profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, messageID, timestamp, senderHandle, senderImage, isAuto, data["Data"]); // We only ever see messages from authenticated peers. // If the contact is marked as offline then override this - can happen when the contact is removed from the front @@ -191,10 +192,11 @@ class CwtchNotifier { var senderImage = data['Picture']; var timestampSent = DateTime.tryParse(data['TimestampSent'])!; var currentTotal = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages; + var isAuto = data['Auto'] == "true"; // 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) { - profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, idx, timestampSent, senderHandle, senderImage, data["Data"]); + profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.updateMessageCache(identifier, idx, timestampSent, senderHandle, senderImage, isAuto, data["Data"]); //if not currently open if (appState.selectedProfile != data["ProfileOnion"] || appState.selectedConversation != identifier) { diff --git a/lib/model.dart b/lib/model.dart index c72a45d2..fe95d93f 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -706,8 +706,8 @@ class ContactInfoState extends ChangeNotifier { return ret; } - void updateMessageCache(int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, String data) { - this.messageCache.insert(0, MessageCache(MessageMetadata(profileOnion, conversation, messageID, timestamp, senderHandle, senderImage, "", {}, false, false), data)); + void updateMessageCache(int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, bool isAuto, String data) { + this.messageCache.insert(0, MessageCache(MessageMetadata(profileOnion, conversation, messageID, timestamp, senderHandle, senderImage, "", {}, false, false, isAuto), data)); this.totalMessages += 1; } diff --git a/lib/models/message.dart b/lib/models/message.dart index 6fb1028b..5c3b322c 100644 --- a/lib/models/message.dart +++ b/lib/models/message.dart @@ -79,7 +79,7 @@ Future messageHandler(BuildContext context, String profileOnion, int co } return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) { - var metadata = MessageMetadata(profileOnion, conversationIdentifier, index, DateTime.now(), "", "", "", {}, false, true); + var metadata = MessageMetadata(profileOnion, conversationIdentifier, index, DateTime.now(), "", "", "", {}, false, true, false); try { dynamic messageWrapper = jsonDecode(rawMessageEnvelope); // There are 2 conditions in which this error condition can be met: @@ -107,7 +107,7 @@ Future messageHandler(BuildContext context, String profileOnion, int co var ackd = messageWrapper['Acknowledged']; var error = messageWrapper['Error'] != null; var signature = messageWrapper['Signature']; - metadata = MessageMetadata(profileOnion, conversationIdentifier, messageID, timestamp, senderHandle, senderImage, signature, attributes, ackd, error); + metadata = MessageMetadata(profileOnion, conversationIdentifier, messageID, timestamp, senderHandle, senderImage, signature, attributes, ackd, error, false); return compileOverlay(metadata, messageWrapper['Message']); } catch (e) { @@ -116,7 +116,7 @@ Future messageHandler(BuildContext context, String profileOnion, int co } }); } catch (e) { - return Future.value(MalformedMessage(MessageMetadata(profileOnion, conversationIdentifier, -1, DateTime.now(), "", "", "", {}, false, true))); + return Future.value(MalformedMessage(MessageMetadata(profileOnion, conversationIdentifier, -1, DateTime.now(), "", "", "", {}, false, true, false))); } } @@ -132,6 +132,7 @@ class MessageMetadata extends ChangeNotifier { final dynamic _attributes; bool _ackd; bool _error; + final bool isAuto; final String? signature; @@ -149,5 +150,5 @@ class MessageMetadata extends ChangeNotifier { notifyListeners(); } - MessageMetadata(this.profileOnion, this.conversationIdentifier, this.messageID, this.timestamp, this.senderHandle, this.senderImage, this.signature, this._attributes, this._ackd, this._error); + MessageMetadata(this.profileOnion, this.conversationIdentifier, this.messageID, this.timestamp, this.senderHandle, this.senderImage, this.signature, this._attributes, this._ackd, this._error, this.isAuto); } diff --git a/lib/models/messages/filemessage.dart b/lib/models/messages/filemessage.dart index a0eba982..52e455fc 100644 --- a/lib/models/messages/filemessage.dart +++ b/lib/models/messages/filemessage.dart @@ -34,7 +34,7 @@ class FileMessage extends Message { return MessageRow(MalformedBubble()); } - return MessageRow(FileBubble(nameSuggestion, rootHash, nonce, fileSize), key: key); + return MessageRow(FileBubble(nameSuggestion, rootHash, nonce, fileSize, isAuto: metadata.isAuto), key: key); }); } @@ -59,6 +59,7 @@ class FileMessage extends Message { rootHash, nonce, fileSize, + isAuto: metadata.isAuto, interactive: false, ); }); diff --git a/lib/settings.dart b/lib/settings.dart index 7d46ab3f..329871d2 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -93,11 +93,7 @@ class Settings extends ChangeNotifier { _uiColumnModePortrait = uiColumnModeFromString(settings["UIColumnModePortrait"]); _uiColumnModeLandscape = uiColumnModeFromString(settings["UIColumnModeLandscape"]); - // image previews/profile pic storage path - for (var i = 0; i < 30; i++) { - print("|"); - } - print("setting DownloadPath to " + settings["DownloadPath"]); + // auto-download folder _downloadPath = settings["DownloadPath"] ?? ""; // Push the experimental settings to Consumers of Settings diff --git a/lib/widgets/filebubble.dart b/lib/widgets/filebubble.dart index a6e7c999..2f093f08 100644 --- a/lib/widgets/filebubble.dart +++ b/lib/widgets/filebubble.dart @@ -23,8 +23,9 @@ class FileBubble extends StatefulWidget { final String nonce; final int fileSize; final bool interactive; + final bool isAuto; - FileBubble(this.nameSuggestion, this.rootHash, this.nonce, this.fileSize, {this.interactive = true}); + FileBubble(this.nameSuggestion, this.rootHash, this.nonce, this.fileSize, {this.isAuto = false, this.interactive = true}); @override FileBubbleState createState() => FileBubbleState(); @@ -52,9 +53,10 @@ class FileBubbleState extends State { var downloadComplete = Provider.of(context).downloadComplete(widget.fileKey()); var downloadInterrupted = Provider.of(context).downloadInterrupted(widget.fileKey()); - if (downloadInterrupted) { + if (flagStarted && !downloadInterrupted) { Provider.of(context, listen: false).cwtch.CheckDownloadStatus(Provider.of(context, listen: false).onion, widget.fileKey()); } + var path = Provider.of(context).downloadFinalPath(widget.fileKey()); if (downloadComplete) { var lpath = path!.toLowerCase(); @@ -144,12 +146,14 @@ class FileBubbleState extends State { ElevatedButton(onPressed: _btnResume, child: Text(AppLocalizations.of(context)!.verfiyResumeButton)) ]); } - } else { + } else if (!widget.isAuto) { wdgDecorations = Center( widthFactor: 1, child: Wrap(children: [ Padding(padding: EdgeInsets.all(5), child: ElevatedButton(child: Text(AppLocalizations.of(context)!.downloadFileButton + '\u202F'), onPressed: _btnAccept)), ])); + } else { + wdgDecorations = Container(); } return Container(