From 1077dbc8969be5d7901406211b7f5ed18fea1188 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Sep 2023 20:14:01 -0500 Subject: [PATCH] Preserve filenames better --- .../eu/siacs/conversations/generator/IqGenerator.java | 4 ++-- .../eu/siacs/conversations/http/HttpUploadConnection.java | 5 ++--- .../java/eu/siacs/conversations/http/SlotRequester.java | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java index 38002849c..306589c1d 100644 --- a/src/main/java/eu/siacs/conversations/generator/IqGenerator.java +++ b/src/main/java/eu/siacs/conversations/generator/IqGenerator.java @@ -430,11 +430,11 @@ public class IqGenerator extends AbstractGenerator { return packet; } - public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String mime) { + public IqPacket requestHttpUploadSlot(Jid host, DownloadableFile file, String name, String mime) { IqPacket packet = new IqPacket(IqPacket.TYPE.GET); packet.setTo(host); Element request = packet.addChild("request", Namespace.HTTP_UPLOAD); - request.setAttribute("filename", convertFilename(file.getName())); + request.setAttribute("filename", name == null ? convertFilename(file.getName()) : name); request.setAttribute("size", file.getExpectedSize()); request.setAttribute("content-type", mime); return packet; diff --git a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java index e2366dd48..cb3532a35 100644 --- a/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +++ b/src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java @@ -130,8 +130,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan this.file.setKeyAndIv(this.key); } this.file.setExpectedSize(originalFileSize + (file.getKey() != null ? 16 : 0)); - message.resetFileParams(); - this.slotFuture = new SlotRequester(mXmppConnectionService).request(method, account, file, mime); + this.slotFuture = new SlotRequester(mXmppConnectionService).request(method, account, file, message.getFileParams().getName(), mime); Futures.addCallback(this.slotFuture, new FutureCallback() { @Override public void onSuccess(@Nullable SlotRequester.Slot result) { @@ -211,4 +210,4 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan this.transmitted = progress; mHttpConnectionManager.updateConversationUi(false); } -} \ No newline at end of file +} diff --git a/src/main/java/eu/siacs/conversations/http/SlotRequester.java b/src/main/java/eu/siacs/conversations/http/SlotRequester.java index 5a3558855..d0a39ca5d 100644 --- a/src/main/java/eu/siacs/conversations/http/SlotRequester.java +++ b/src/main/java/eu/siacs/conversations/http/SlotRequester.java @@ -55,13 +55,13 @@ public class SlotRequester { this.service = service; } - public ListenableFuture request(Method method, Account account, DownloadableFile file, String mime) { + public ListenableFuture request(Method method, Account account, DownloadableFile file, String name, String mime) { if (method == Method.HTTP_UPLOAD_LEGACY) { final Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD_LEGACY); return requestHttpUploadLegacy(account, host, file, mime); } else { final Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD); - return requestHttpUpload(account, host, file, mime); + return requestHttpUpload(account, host, file, name, mime); } } @@ -95,9 +95,9 @@ public class SlotRequester { return future; } - private ListenableFuture requestHttpUpload(Account account, Jid host, DownloadableFile file, String mime) { + private ListenableFuture requestHttpUpload(Account account, Jid host, DownloadableFile file, String fname, String mime) { final SettableFuture future = SettableFuture.create(); - final IqPacket request = service.getIqGenerator().requestHttpUploadSlot(host, file, mime); + final IqPacket request = service.getIqGenerator().requestHttpUploadSlot(host, file, fname, mime); service.sendIqPacket(account, request, (a, packet) -> { if (packet.getType() == IqPacket.TYPE.RESULT) { final Element slotElement = packet.findChild("slot", Namespace.HTTP_UPLOAD); -- 2.45.2