message previews

This commit is contained in:
erinn 2021-12-16 17:04:29 -08:00
parent 8a8c5fc3e2
commit 6e9fb6810e
6 changed files with 21 additions and 17 deletions

View File

@ -135,6 +135,7 @@ class CwtchNotifier {
var timestamp = DateTime.tryParse(data['TimestampReceived'])!; var timestamp = DateTime.tryParse(data['TimestampReceived'])!;
var senderHandle = data['RemotePeer']; var senderHandle = data['RemotePeer'];
var senderImage = data['Picture']; var senderImage = data['Picture'];
var isAuto = data['Auto'] == "true";
// We might not have received a contact created for this contact yet... // 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... // 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.getContact(identifier)!.newMarker++;
} }
profileCN.getProfile(data["ProfileOnion"])?.contactList.updateLastMessageTime(identifier, DateTime.now()); 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. // 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 // 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 senderImage = data['Picture'];
var timestampSent = DateTime.tryParse(data['TimestampSent'])!; var timestampSent = DateTime.tryParse(data['TimestampSent'])!;
var currentTotal = profileCN.getProfile(data["ProfileOnion"])?.contactList.getContact(identifier)!.totalMessages; 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... // 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) { 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 not currently open
if (appState.selectedProfile != data["ProfileOnion"] || appState.selectedConversation != identifier) { if (appState.selectedProfile != data["ProfileOnion"] || appState.selectedConversation != identifier) {

View File

@ -706,8 +706,8 @@ class ContactInfoState extends ChangeNotifier {
return ret; return ret;
} }
void updateMessageCache(int conversation, int messageID, DateTime timestamp, String senderHandle, String senderImage, String 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), data)); this.messageCache.insert(0, MessageCache(MessageMetadata(profileOnion, conversation, messageID, timestamp, senderHandle, senderImage, "", {}, false, false, isAuto), data));
this.totalMessages += 1; this.totalMessages += 1;
} }

View File

@ -79,7 +79,7 @@ Future<Message> messageHandler(BuildContext context, String profileOnion, int co
} }
return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) { return rawMessageEnvelopeFuture.then((dynamic rawMessageEnvelope) {
var metadata = MessageMetadata(profileOnion, conversationIdentifier, index, DateTime.now(), "", "", "", <String, String>{}, false, true); var metadata = MessageMetadata(profileOnion, conversationIdentifier, index, DateTime.now(), "", "", "", <String, String>{}, false, true, false);
try { try {
dynamic messageWrapper = jsonDecode(rawMessageEnvelope); dynamic messageWrapper = jsonDecode(rawMessageEnvelope);
// There are 2 conditions in which this error condition can be met: // There are 2 conditions in which this error condition can be met:
@ -107,7 +107,7 @@ Future<Message> messageHandler(BuildContext context, String profileOnion, int co
var ackd = messageWrapper['Acknowledged']; var ackd = messageWrapper['Acknowledged'];
var error = messageWrapper['Error'] != null; var error = messageWrapper['Error'] != null;
var signature = messageWrapper['Signature']; 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']); return compileOverlay(metadata, messageWrapper['Message']);
} catch (e) { } catch (e) {
@ -116,7 +116,7 @@ Future<Message> messageHandler(BuildContext context, String profileOnion, int co
} }
}); });
} catch (e) { } catch (e) {
return Future.value(MalformedMessage(MessageMetadata(profileOnion, conversationIdentifier, -1, DateTime.now(), "", "", "", <String, String>{}, false, true))); return Future.value(MalformedMessage(MessageMetadata(profileOnion, conversationIdentifier, -1, DateTime.now(), "", "", "", <String, String>{}, false, true, false)));
} }
} }
@ -132,6 +132,7 @@ class MessageMetadata extends ChangeNotifier {
final dynamic _attributes; final dynamic _attributes;
bool _ackd; bool _ackd;
bool _error; bool _error;
final bool isAuto;
final String? signature; final String? signature;
@ -149,5 +150,5 @@ class MessageMetadata extends ChangeNotifier {
notifyListeners(); 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);
} }

View File

@ -34,7 +34,7 @@ class FileMessage extends Message {
return MessageRow(MalformedBubble()); 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, rootHash,
nonce, nonce,
fileSize, fileSize,
isAuto: metadata.isAuto,
interactive: false, interactive: false,
); );
}); });

View File

@ -93,11 +93,7 @@ class Settings extends ChangeNotifier {
_uiColumnModePortrait = uiColumnModeFromString(settings["UIColumnModePortrait"]); _uiColumnModePortrait = uiColumnModeFromString(settings["UIColumnModePortrait"]);
_uiColumnModeLandscape = uiColumnModeFromString(settings["UIColumnModeLandscape"]); _uiColumnModeLandscape = uiColumnModeFromString(settings["UIColumnModeLandscape"]);
// image previews/profile pic storage path // auto-download folder
for (var i = 0; i < 30; i++) {
print("|");
}
print("setting DownloadPath to " + settings["DownloadPath"]);
_downloadPath = settings["DownloadPath"] ?? ""; _downloadPath = settings["DownloadPath"] ?? "";
// Push the experimental settings to Consumers of Settings // Push the experimental settings to Consumers of Settings

View File

@ -23,8 +23,9 @@ class FileBubble extends StatefulWidget {
final String nonce; final String nonce;
final int fileSize; final int fileSize;
final bool interactive; 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 @override
FileBubbleState createState() => FileBubbleState(); FileBubbleState createState() => FileBubbleState();
@ -52,9 +53,10 @@ class FileBubbleState extends State<FileBubble> {
var downloadComplete = Provider.of<ProfileInfoState>(context).downloadComplete(widget.fileKey()); var downloadComplete = Provider.of<ProfileInfoState>(context).downloadComplete(widget.fileKey());
var downloadInterrupted = Provider.of<ProfileInfoState>(context).downloadInterrupted(widget.fileKey()); var downloadInterrupted = Provider.of<ProfileInfoState>(context).downloadInterrupted(widget.fileKey());
if (downloadInterrupted) { if (flagStarted && !downloadInterrupted) {
Provider.of<FlwtchState>(context, listen: false).cwtch.CheckDownloadStatus(Provider.of<ProfileInfoState>(context, listen: false).onion, widget.fileKey()); Provider.of<FlwtchState>(context, listen: false).cwtch.CheckDownloadStatus(Provider.of<ProfileInfoState>(context, listen: false).onion, widget.fileKey());
} }
var path = Provider.of<ProfileInfoState>(context).downloadFinalPath(widget.fileKey()); var path = Provider.of<ProfileInfoState>(context).downloadFinalPath(widget.fileKey());
if (downloadComplete) { if (downloadComplete) {
var lpath = path!.toLowerCase(); var lpath = path!.toLowerCase();
@ -144,12 +146,14 @@ class FileBubbleState extends State<FileBubble> {
ElevatedButton(onPressed: _btnResume, child: Text(AppLocalizations.of(context)!.verfiyResumeButton)) ElevatedButton(onPressed: _btnResume, child: Text(AppLocalizations.of(context)!.verfiyResumeButton))
]); ]);
} }
} else { } else if (!widget.isAuto) {
wdgDecorations = Center( wdgDecorations = Center(
widthFactor: 1, widthFactor: 1,
child: Wrap(children: [ child: Wrap(children: [
Padding(padding: EdgeInsets.all(5), child: ElevatedButton(child: Text(AppLocalizations.of(context)!.downloadFileButton + '\u202F'), onPressed: _btnAccept)), Padding(padding: EdgeInsets.all(5), child: ElevatedButton(child: Text(AppLocalizations.of(context)!.downloadFileButton + '\u202F'), onPressed: _btnAccept)),
])); ]));
} else {
wdgDecorations = Container();
} }
return Container( return Container(