Merge pull request 'Enable Sender Side Image Previews' (#327) from sender_size into trunk
continuous-integration/drone/push Build is pending Details

Reviewed-on: #327
Reviewed-by: erinn <erinn@openprivacy.ca>
This commit is contained in:
erinn 2022-01-20 22:44:19 +00:00
commit 7dcc1c863a
5 changed files with 38 additions and 12 deletions

View File

@ -1 +1 @@
2022-01-20-12-53-v1.5.4-14-g6865ec1
2022-01-20-17-22-v1.5.4-16-ge0e1a4b

View File

@ -1 +1 @@
2022-01-20-17-53-v1.5.4-14-g6865ec1
2022-01-20-22-22-v1.5.4-16-ge0e1a4b

View File

@ -244,6 +244,13 @@ class CwtchNotifier {
case "UpdatedProfileAttribute":
if (data["Key"] == "public.profile.name") {
profileCN.getProfile(data["ProfileOnion"])?.nickname = data["Data"];
} else if (data["Key"].toString().startsWith("local.filesharing.") && data["Key"].toString().endsWith(".path")) {
// local.conversation.filekey.path
List<String> keyparts = data["Key"].toString().split(".");
if (keyparts.length == 5) {
String filekey = keyparts[2] + "." + keyparts[3];
profileCN.getProfile(data["ProfileOnion"])?.downloadSetPathForSender(filekey, data["Data"]);
}
} else {
EnvironmentConfig.debugLog("unhandled set attribute event: ${data['Key']}");
}

View File

@ -253,6 +253,20 @@ class ProfileInfoState extends ChangeNotifier {
}
}
// set the download path for the sender
void downloadSetPathForSender(String fileKey, String path) {
// only allow this override if we are the sender...
if (this._downloads.containsKey(fileKey) == false) {
this._downloads[fileKey] = FileDownloadProgress(1, DateTime.now());
this._downloads[fileKey]!.timeEnd = DateTime.now();
this._downloads[fileKey]!.chunksDownloaded = 1;
this._downloads[fileKey]!.gotManifest = true;
this._downloads[fileKey]!.complete = true;
this._downloads[fileKey]!.downloadedTo = path;
notifyListeners();
}
}
String? downloadFinalPath(String fileKey) {
return this._downloads.containsKey(fileKey) ? this._downloads[fileKey]!.downloadedTo : null;
}

View File

@ -52,16 +52,25 @@ class FileBubbleState extends State<FileBubble> {
var borderRadiousEh = 15.0;
var showFileSharing = Provider.of<Settings>(context, listen: false).isExperimentEnabled(FileSharingExperiment);
var prettyDate = DateFormat.yMd(Platform.localeName).add_jm().format(Provider.of<MessageMetadata>(context).timestamp);
var downloadComplete = Provider.of<ProfileInfoState>(context).downloadComplete(widget.fileKey());
var metadata = Provider.of<MessageMetadata>(context);
var downloadComplete = metadata.attributes["filepath"] != null || Provider.of<ProfileInfoState>(context).downloadComplete(widget.fileKey());
var downloadInterrupted = Provider.of<ProfileInfoState>(context).downloadInterrupted(widget.fileKey());
var path = Provider.of<ProfileInfoState>(context).downloadFinalPath(widget.fileKey());
if (downloadComplete) {
var lpath = path!.toLowerCase();
// If we haven't stored the filepath in message attributes then save it
if (downloadComplete && path == null && metadata.attributes["filepath"] != null) {
path = metadata.attributes["filepath"];
} else if (downloadComplete && path != null && metadata.attributes["filepath"] == null) {
Provider.of<FlwtchState>(context).cwtch.SetMessageAttribute(metadata.profileOnion, metadata.conversationIdentifier, 0, metadata.messageID, "filepath", path);
}
if (downloadComplete && path != null) {
var lpath = path.toLowerCase();
if (lpath.endsWith(".jpg") || lpath.endsWith(".jpeg") || lpath.endsWith(".png") || lpath.endsWith(".gif") || lpath.endsWith(".webp") || lpath.endsWith(".bmp")) {
if (myFile == null) {
setState(() {
myFile = new File(path);
myFile = new File(path!);
});
}
}
@ -98,13 +107,9 @@ class FileBubbleState extends State<FileBubble> {
if (!showFileSharing) {
wdgDecorations = Text('\u202F');
} else if (fromMe) {
wdgDecorations = Visibility(
visible: widget.interactive,
child: MessageBubbleDecoration(ackd: Provider.of<MessageMetadata>(context).ackd, errored: Provider.of<MessageMetadata>(context).error, fromMe: fromMe, prettyDate: prettyDate));
} else if (downloadComplete) {
} else if (downloadComplete && path != null) {
// in this case, whatever marked download.complete would have also set the path
if (Provider.of<Settings>(context).shouldPreview(path!)) {
if (Provider.of<Settings>(context).shouldPreview(path)) {
isPreview = true;
wdgDecorations = Center(
child: MouseRegion(