diff options
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java index 4b0a956c..db455b7a 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/filetransfer/http/upload/HttpUploadRequestSlotPacketGenerator.java @@ -1,5 +1,7 @@ package de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload; +import de.thedevstack.conversationsplus.entities.Account; +import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; @@ -24,17 +26,38 @@ public final class HttpUploadRequestSlotPacketGenerator { * </request> * </iq> * </pre> - * @param host the jid of the host to request a slot from + * @param account the account requesting a slot * @param filename the filename of the file which will be transferred * @param filesize the filesize of the file which will be transferred * @param mime the mime type of the file which will be transferred - <code>optional</code> and therefore nullable * @return the IqPacket */ - public static IqPacket generate(Jid host, String filename, long filesize, String mime) { - SlotRequestPacket packet = new SlotRequestPacket(filename, filesize); - packet.setTo(host); - packet.setMime((mime == null || mime.isEmpty()) ? HttpUpload.DEFAULT_MIME_TYPE : mime); - return packet; + public static IqPacket generate(Account account, Jid recipient, String filename, long filesize, String mime) { + String namespace = getNamespace(account); + Jid host = getHost(account, namespace); + IqPacket requestPacket; + switch (namespace) { + case HttpUpload.NAMESPACE: + requestPacket = new HttpUploadSlotRequestPacket(filename, filesize, mime); + break; + case FileTransferHttp.NAMESPACE: + default: + requestPacket = new FileTransferHttpUploadSlotRequestPacket(recipient.toString(), filename, filesize, mime); + } + requestPacket.setTo(host); + return requestPacket; + } + + private static String getNamespace(Account account) { + if (null != account.getXmppConnection().findDiscoItemByFeature(FileTransferHttp.NAMESPACE)) { + return FileTransferHttp.NAMESPACE; + } else { + return HttpUpload.NAMESPACE; + } + } + + private static Jid getHost(Account account, String namespace) { + return account.getXmppConnection().findDiscoItemByFeature(namespace); } /** |