~singpolyma/cheogram-android

1077dbc8969be5d7901406211b7f5ed18fea1188 — Stephen Paul Weber 9 months ago 4504953
Preserve filenames better
M src/main/java/eu/siacs/conversations/generator/IqGenerator.java => src/main/java/eu/siacs/conversations/generator/IqGenerator.java +2 -2
@@ 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;

M src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java => src/main/java/eu/siacs/conversations/http/HttpUploadConnection.java +2 -3
@@ 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<SlotRequester.Slot>() {
            @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
}

M src/main/java/eu/siacs/conversations/http/SlotRequester.java => src/main/java/eu/siacs/conversations/http/SlotRequester.java +4 -4
@@ 55,13 55,13 @@ public class SlotRequester {
        this.service = service;
    }

    public ListenableFuture<Slot> request(Method method, Account account, DownloadableFile file, String mime) {
    public ListenableFuture<Slot> 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<Slot> requestHttpUpload(Account account, Jid host, DownloadableFile file, String mime) {
    private ListenableFuture<Slot> requestHttpUpload(Account account, Jid host, DownloadableFile file, String fname, String mime) {
        final SettableFuture<Slot> 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);