aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/services/filetransfer/http/upload/HttpUploadSlotRequestReceived.java
blob: 022aedcf859aa10f1eddefcfdf059b19a096a3bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package de.thedevstack.conversationsplus.services.filetransfer.http.upload;

import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.entities.Account;
import de.thedevstack.conversationsplus.services.filetransfer.FileTransferFailureReason;
import de.thedevstack.conversationsplus.xmpp.OnIqPacketReceived;
import de.thedevstack.conversationsplus.xmpp.exceptions.XmppException;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUploadSlot;
import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.SlotPacketParser;
import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket;

/**
 *
 */
public class HttpUploadSlotRequestReceived implements OnIqPacketReceived {
    private final HttpUploadFileTransferEntity entity;

    public HttpUploadSlotRequestReceived(HttpUploadFileTransferEntity entity) {
        this.entity = entity;
    }

    @Override
    public void onIqPacketReceived(Account account, IqPacket packet) {
        try {
            HttpUploadSlot slot = SlotPacketParser.parseGetAndPutUrl(packet);
            this.entity.setSlot(slot);
            if (!this.entity.isCanceled()) {
                new Thread(new HttpFileUploader(this.entity)).start();
            }
        } catch (XmppException e) {
            Logging.e("httpupload", e.getMessage());
            this.entity.fail(FileTransferFailureReason.createNonRecoverableFailureReason(e));
        }
    }
}