Search in sources :

Example 1 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class MessageArchiveService method processFin.

public void processFin(Element fin) {
    Query query = findQuery(fin.getAttribute("queryid"));
    if (query == null) {
        return;
    }
    boolean complete = fin.getAttributeAsBoolean("complete");
    Element set = fin.findChild("set", "http://jabber.org/protocol/rsm");
    Element last = set == null ? null : set.findChild("last");
    Element first = set == null ? null : set.findChild("first");
    Element relevant = query.getPagingOrder() == PagingOrder.NORMAL ? last : first;
    boolean abort = (!query.isCatchup() && query.getTotalCount() >= Config.PAGE_SIZE) || query.getTotalCount() >= Config.MAM_MAX_MESSAGES;
    if (query.getConversation() != null) {
        query.getConversation().setFirstMamReference(first == null ? null : first.getContent());
    }
    if (complete || relevant == null || abort) {
        final boolean done = (complete || query.getActualMessageCount() == 0) && !query.isCatchup();
        this.finalizeQuery(query, done);
        Log.d(Config.LOGTAG, query.getAccount().getJid().toBareJid() + ": finished mam after " + query.getTotalCount() + "(" + query.getActualMessageCount() + ") messages. messages left=" + Boolean.toString(!done));
        if (query.isCatchup() && query.getActualMessageCount() > 0) {
            mXmppConnectionService.getNotificationService().finishBacklog(true, query.getAccount());
        }
    } else {
        final Query nextQuery;
        if (query.getPagingOrder() == PagingOrder.NORMAL) {
            nextQuery = query.next(last == null ? null : last.getContent());
        } else {
            nextQuery = query.prev(first == null ? null : first.getContent());
        }
        this.execute(nextQuery);
        this.finalizeQuery(query, false);
        synchronized (this.queries) {
            this.queries.add(nextQuery);
        }
    }
}
Also used : Element(eu.siacs.conversations.xml.Element)

Example 2 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class XmppConnectionService method publishAvatar.

public void publishAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket result) {
            if (result.getType() == IqPacket.TYPE.RESULT) {
                final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
                sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket result) {
                        if (result.getType() == IqPacket.TYPE.RESULT) {
                            if (account.setAvatar(avatar.getFilename())) {
                                getAvatarService().clear(account);
                                databaseBackend.updateAccount(account);
                            }
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
                            if (callback != null) {
                                callback.success(avatar);
                            }
                        } else {
                            if (callback != null) {
                                callback.error(R.string.error_publish_avatar_server_reject, avatar);
                            }
                        }
                    }
                });
            } else {
                Element error = result.findChild("error");
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server rejected avatar " + (avatar.size / 1024) + "KiB " + (error != null ? error.toString() : ""));
                if (callback != null) {
                    callback.error(R.string.error_publish_avatar_server_reject, avatar);
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 3 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class MessageGenerator method confirm.

public MessagePacket confirm(final Account account, final Jid to, final String id) {
    MessagePacket packet = new MessagePacket();
    packet.setType(MessagePacket.TYPE_CHAT);
    packet.setTo(to);
    packet.setFrom(account.getJid());
    Element received = packet.addChild("displayed", "urn:xmpp:chat-markers:0");
    received.setAttribute("id", id);
    packet.addChild("store", "urn:xmpp:hints");
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Element(eu.siacs.conversations.xml.Element)

Example 4 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class MessageGenerator method generateOtrError.

public MessagePacket generateOtrError(Jid to, String id, String errorText) {
    MessagePacket packet = new MessagePacket();
    packet.setType(MessagePacket.TYPE_ERROR);
    packet.setAttribute("id", id);
    packet.setTo(to);
    Element error = packet.addChild("error");
    error.setAttribute("code", "406");
    error.setAttribute("type", "modify");
    error.addChild("not-acceptable", "urn:ietf:params:xml:ns:xmpp-stanzas");
    error.addChild("text").setContent("?OTR Error:" + errorText);
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Element(eu.siacs.conversations.xml.Element)

Example 5 with Element

use of eu.siacs.conversations.xml.Element in project Conversations by siacs.

the class HttpUploadConnection method init.

public void init(Message message, boolean delay) {
    this.message = message;
    this.account = message.getConversation().getAccount();
    this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
    this.mime = this.file.getMimeType();
    this.delayed = delay;
    if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
        this.key = new byte[48];
        mXmppConnectionService.getRNG().nextBytes(this.key);
        this.file.setKeyAndIv(this.key);
    }
    Pair<InputStream, Integer> pair;
    try {
        pair = AbstractConnectionManager.createInputStream(file, true);
    } catch (FileNotFoundException e) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not find file to upload - " + e.getMessage());
        fail(e.getMessage());
        return;
    }
    this.file.setExpectedSize(pair.second);
    this.mFileInputStream = pair.first;
    Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
    IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
    mXmppConnectionService.sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
                if (slot != null) {
                    try {
                        mGetUrl = new URL(slot.findChildContent("get"));
                        mPutUrl = new URL(slot.findChildContent("put"));
                        if (!canceled) {
                            new Thread(new FileUploader()).start();
                        }
                        return;
                    } catch (MalformedURLException e) {
                    //fall through
                    }
                }
            }
            Log.d(Config.LOGTAG, account.getJid().toString() + ": invalid response to slot request " + packet);
            fail(IqParser.extractErrorMessage(packet));
        }
    });
    message.setTransferable(this);
    mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
}
Also used : Account(eu.siacs.conversations.entities.Account) MalformedURLException(java.net.MalformedURLException) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) InputStream(java.io.InputStream) Element(eu.siacs.conversations.xml.Element) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Element (eu.siacs.conversations.xml.Element)166 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)72 Jid (eu.siacs.conversations.xmpp.Jid)24 Account (eu.siacs.conversations.entities.Account)21 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)17 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)15 Contact (eu.siacs.conversations.entities.Contact)13 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)11 Conversation (eu.siacs.conversations.entities.Conversation)10 Data (eu.siacs.conversations.xmpp.forms.Data)9 ArrayList (java.util.ArrayList)9 Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)8 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)8 Bookmark (eu.siacs.conversations.entities.Bookmark)6 S5BTransportInfo (eu.siacs.conversations.xmpp.jingle.stanzas.S5BTransportInfo)6 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)6 IOException (java.io.IOException)6 JabberIdContact (eu.siacs.conversations.android.JabberIdContact)5 Message (eu.siacs.conversations.entities.Message)5 HashSet (java.util.HashSet)5