Search in sources :

Example 31 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method fetchAvatarVcard.

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

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            synchronized (mInProgressAvatarFetches) {
                mInProgressAvatarFetches.remove(generateFetchKey(account, avatar));
            }
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                Element vCard = packet.findChild("vCard", "vcard-temp");
                Element photo = vCard != null ? vCard.findChild("PHOTO") : null;
                String image = photo != null ? photo.findChildContent("BINVAL") : null;
                if (image != null) {
                    avatar.image = image;
                    if (getFileBackend().save(avatar)) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched vCard avatar for " + avatar.owner);
                        if (avatar.owner.isBareJid()) {
                            if (account.getJid().toBareJid().equals(avatar.owner) && account.getAvatar() == null) {
                                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": had no avatar. replacing with vcard");
                                account.setAvatar(avatar.getFilename());
                                databaseBackend.updateAccount(account);
                                getAvatarService().clear(account);
                                updateAccountUi();
                            } else {
                                Contact contact = account.getRoster().getContact(avatar.owner);
                                contact.setAvatar(avatar);
                                getAvatarService().clear(contact);
                                updateRosterUi();
                            }
                            updateConversationUi();
                        } else {
                            Conversation conversation = find(account, avatar.owner.toBareJid());
                            if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
                                MucOptions.User user = conversation.getMucOptions().findUserByFullJid(avatar.owner);
                                if (user != null) {
                                    if (user.setAvatar(avatar)) {
                                        getAvatarService().clear(user);
                                        updateConversationUi();
                                        updateMucRosterUi();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket) Contact(de.pixart.messenger.entities.Contact)

Example 32 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class ChooseContactActivity method filterContacts.

protected void filterContacts(final String needle) {
    getListItems().clear();
    if (xmppConnectionService == null) {
        getListItemAdapter().notifyDataSetChanged();
        return;
    }
    for (final Account account : xmppConnectionService.getAccounts()) {
        if (account.getStatus() != Account.State.DISABLED) {
            for (final Contact contact : account.getRoster().getContacts()) {
                if (contact.showInRoster() && !filterContacts.contains(contact.getJid().toBareJid().toString()) && contact.match(this, needle)) {
                    getListItems().add(contact);
                }
            }
        }
    }
    Collections.sort(getListItems());
    getListItemAdapter().notifyDataSetChanged();
}
Also used : Account(de.pixart.messenger.entities.Account) Contact(de.pixart.messenger.entities.Contact)

Example 33 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class HttpUploadConnection method init.

public void init(Message message, boolean delay) {
    this.message = message;
    final Account account = message.getConversation().getAccount();
    this.file = mXmppConnectionService.getFileBackend().getFile(message, false);
    if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
        this.mime = "application/pgp-encrypted";
    } else {
        this.mime = this.file.getMimeType();
    }
    this.delayed = delay;
    if (Config.ENCRYPT_ON_HTTP_UPLOADED || message.getEncryption() == Message.ENCRYPTION_AXOLOTL || message.getEncryption() == Message.ENCRYPTION_OTR) {
        // todo: change this to 44 for 12-byte IV instead of 16-byte at some point in future
        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);
    message.resetFileParams();
    this.mFileInputStream = pair.first;
    Jid host = account.getXmppConnection().findDiscoItemByFeature(Namespace.HTTP_UPLOAD);
    IqPacket request = mXmppConnectionService.getIqGenerator().requestHttpUploadSlot(host, file, mime);
    mXmppConnectionService.sendIqPacket(account, request, (a, packet) -> {
        if (packet.getType() == IqPacket.TYPE.RESULT) {
            Element slot = packet.findChild("slot", Namespace.HTTP_UPLOAD);
            if (slot != null) {
                try {
                    final Element put = slot.findChild("put");
                    final Element get = slot.findChild("get");
                    final String putUrl = put == null ? null : put.getAttribute("url");
                    final String getUrl = get == null ? null : get.getAttribute("url");
                    if (getUrl != null && putUrl != null) {
                        this.mGetUrl = new URL(getUrl);
                        this.mPutUrl = new URL(putUrl);
                        this.mPutHeaders = new HashMap<>();
                        for (Element child : put.getChildren()) {
                            if ("header".equals(child.getName())) {
                                final String name = child.getAttribute("name");
                                final String value = child.getContent();
                                if (WHITE_LISTED_HEADERS.contains(name) && value != null && !value.trim().contains("\n")) {
                                    this.mPutHeaders.put(name, value.trim());
                                }
                            }
                        }
                        if (!canceled) {
                            new Thread(this::upload).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(de.pixart.messenger.entities.Account) MalformedURLException(java.net.MalformedURLException) Jid(de.pixart.messenger.xmpp.jid.Jid) InputStream(java.io.InputStream) Element(de.pixart.messenger.xml.Element) FileNotFoundException(java.io.FileNotFoundException) URL(java.net.URL) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 34 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class MessageParser method extractChatState.

private boolean extractChatState(Conversation c, final boolean isTypeGroupChat, final MessagePacket packet) {
    ChatState state = ChatState.parse(packet);
    if (state != null && c != null) {
        final Account account = c.getAccount();
        Jid from = packet.getFrom();
        if (from.toBareJid().equals(account.getJid().toBareJid())) {
            c.setOutgoingChatState(state);
            if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
                mXmppConnectionService.markRead(c);
                activateGracePeriod(account);
            }
            return false;
        } else {
            if (isTypeGroupChat) {
                MucOptions.User user = c.getMucOptions().findUserByFullJid(from);
                if (user != null) {
                    return user.setChatState(state);
                } else {
                    return false;
                }
            } else {
                return c.setIncomingChatState(state);
            }
        }
    }
    return false;
}
Also used : ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) Account(de.pixart.messenger.entities.Account) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid)

Example 35 with Account

use of de.pixart.messenger.entities.Account in project Pix-Art-Messenger by kriztan.

the class MessageGenerator method preparePacket.

private MessagePacket preparePacket(Message message) {
    Conversation conversation = message.getConversation();
    Account account = conversation.getAccount();
    MessagePacket packet = new MessagePacket();
    final boolean isWithSelf = conversation.getContact().isSelf();
    if (conversation.getMode() == Conversation.MODE_SINGLE) {
        packet.setTo(message.getCounterpart());
        packet.setType(MessagePacket.TYPE_CHAT);
        if (this.mXmppConnectionService.indicateReceived() && !isWithSelf) {
            packet.addChild("request", "urn:xmpp:receipts");
        }
    } else if (message.getType() == Message.TYPE_PRIVATE) {
        packet.setTo(message.getCounterpart());
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.addChild("x", "http://jabber.org/protocol/muc#user");
        if (this.mXmppConnectionService.indicateReceived()) {
            packet.addChild("request", "urn:xmpp:receipts");
        }
    } else {
        packet.setTo(message.getCounterpart().toBareJid());
        packet.setType(MessagePacket.TYPE_GROUPCHAT);
    }
    if (conversation.isSingleOrPrivateAndNonAnonymous() && message.getType() != Message.TYPE_PRIVATE) {
        packet.addChild("markable", "urn:xmpp:chat-markers:0");
    }
    packet.setFrom(account.getJid());
    packet.setId(message.getUuid());
    packet.addChild("origin-id", Namespace.STANZA_IDS).setAttribute("id", message.getUuid());
    if (message.edited()) {
        packet.addChild("replace", "urn:xmpp:message-correct:0").setAttribute("id", message.getEditedId());
    }
    return packet;
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Account(de.pixart.messenger.entities.Account) Conversation(de.pixart.messenger.entities.Conversation)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6