Search in sources :

Example 26 with Contact

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

the class MessageParser method parseEvent.

private void parseEvent(final Element event, final Jid from, final Account account) {
    Element items = event.findChild("items");
    String node = items == null ? null : items.getAttribute("node");
    if ("urn:xmpp:avatar:metadata".equals(node)) {
        Avatar avatar = Avatar.parseMetadata(items);
        if (avatar != null) {
            avatar.owner = from.toBareJid();
            if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
                if (account.getJid().toBareJid().equals(from)) {
                    if (account.setAvatar(avatar.getFilename())) {
                        mXmppConnectionService.databaseBackend.updateAccount(account);
                    }
                    mXmppConnectionService.getAvatarService().clear(account);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateAccountUi();
                } else {
                    Contact contact = account.getRoster().getContact(from);
                    contact.setAvatar(avatar);
                    mXmppConnectionService.getAvatarService().clear(contact);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateRosterUi();
                }
            } else if (mXmppConnectionService.isDataSaverDisabled()) {
                mXmppConnectionService.fetchAvatar(account, avatar);
            }
        }
    } else if ("http://jabber.org/protocol/nick".equals(node)) {
        final Element i = items.findChild("item");
        final String nick = i == null ? null : i.findChildContent("nick", Namespace.NICK);
        if (nick != null) {
            Contact contact = account.getRoster().getContact(from);
            if (contact.setPresenceName(nick)) {
                mXmppConnectionService.getAvatarService().clear(contact);
            }
            mXmppConnectionService.updateConversationUi();
            mXmppConnectionService.updateAccountUi();
        }
    } else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
        Element item = items.findChild("item");
        Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Received PEP device list " + deviceIds + " update from " + from + ", processing... ");
        AxolotlService axolotlService = account.getAxolotlService();
        axolotlService.registerDevices(from, deviceIds);
        mXmppConnectionService.updateAccountUi();
    }
}
Also used : AxolotlService(de.pixart.messenger.crypto.axolotl.AxolotlService) Element(de.pixart.messenger.xml.Element) Avatar(de.pixart.messenger.xmpp.pep.Avatar) Contact(de.pixart.messenger.entities.Contact)

Example 27 with Contact

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

the class PresenceParser method parseContactPresence.

public void parseContactPresence(final PresencePacket packet, final Account account) {
    final PresenceGenerator mPresenceGenerator = mXmppConnectionService.getPresenceGenerator();
    final Jid from = packet.getFrom();
    if (from == null || from.equals(account.getJid())) {
        return;
    }
    final String type = packet.getAttribute("type");
    final Contact contact = account.getRoster().getContact(from);
    if (type == null) {
        final String resource = from.isBareJid() ? "" : from.getResourcepart();
        if (contact.setPresenceName(packet.findChildContent("nick", Namespace.NICK))) {
            mXmppConnectionService.getAvatarService().clear(contact);
        }
        Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
        if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) {
            avatar.owner = from.toBareJid();
            if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
                if (avatar.owner.equals(account.getJid().toBareJid())) {
                    account.setAvatar(avatar.getFilename());
                    mXmppConnectionService.databaseBackend.updateAccount(account);
                    mXmppConnectionService.getAvatarService().clear(account);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateAccountUi();
                } else if (contact.setAvatar(avatar)) {
                    mXmppConnectionService.getAvatarService().clear(contact);
                    mXmppConnectionService.updateConversationUi();
                    mXmppConnectionService.updateRosterUi();
                }
            } else if (mXmppConnectionService.isDataSaverDisabled()) {
                mXmppConnectionService.fetchAvatar(account, avatar);
            }
        }
        int sizeBefore = contact.getPresences().size();
        final String show = packet.findChildContent("show");
        final Element caps = packet.findChild("c", "http://jabber.org/protocol/caps");
        final String message = packet.findChildContent("status");
        final Presence presence = Presence.parse(show, caps, message);
        contact.updatePresence(resource, presence);
        if (presence.hasCaps()) {
            mXmppConnectionService.fetchCaps(account, from, presence);
        }
        final Element idle = packet.findChild("idle", Namespace.IDLE);
        if (idle != null) {
            try {
                final String since = idle.getAttribute("since");
                contact.setLastseen(AbstractParser.parseTimestamp(since));
                contact.flagInactive();
            } catch (Throwable throwable) {
                if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) {
                    contact.flagActive();
                }
            }
        } else {
            if (contact.setLastseen(AbstractParser.parseTimestamp(packet))) {
                contact.flagActive();
            }
        }
        PgpEngine pgp = mXmppConnectionService.getPgpEngine();
        Element x = packet.findChild("x", "jabber:x:signed");
        if (pgp != null && x != null) {
            Element status = packet.findChild("status");
            String msg = status != null ? status.getContent() : "";
            contact.setPgpKeyId(pgp.fetchKeyId(account, msg, x.getContent()));
        }
        boolean online = sizeBefore < contact.getPresences().size();
        mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, online);
    } else if (type.equals("unavailable")) {
        if (contact.setLastseen(AbstractParser.parseTimestamp(packet, 0L, true))) {
            contact.flagInactive();
        }
        if (from.isBareJid()) {
            contact.clearPresences();
        } else {
            contact.removePresence(from.getResourcepart());
        }
        mXmppConnectionService.onContactStatusChanged.onContactStatusChanged(contact, false);
    } else if (type.equals("subscribe")) {
        if (contact.getOption(Contact.Options.PREEMPTIVE_GRANT)) {
            mXmppConnectionService.sendPresencePacket(account, mPresenceGenerator.sendPresenceUpdatesTo(contact));
        } else {
            contact.setOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
            final Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, contact.getJid().toBareJid(), false, false);
            final String statusMessage = packet.findChildContent("status");
            if (statusMessage != null && !statusMessage.isEmpty() && conversation.countMessages() == 0) {
                conversation.add(new Message(conversation, statusMessage, Message.ENCRYPTION_NONE, Message.STATUS_RECEIVED));
            }
        }
    }
    mXmppConnectionService.updateRosterUi();
}
Also used : PresenceGenerator(de.pixart.messenger.generator.PresenceGenerator) Jid(de.pixart.messenger.xmpp.jid.Jid) Message(de.pixart.messenger.entities.Message) Element(de.pixart.messenger.xml.Element) PgpEngine(de.pixart.messenger.crypto.PgpEngine) Conversation(de.pixart.messenger.entities.Conversation) Avatar(de.pixart.messenger.xmpp.pep.Avatar) Contact(de.pixart.messenger.entities.Contact) Presence(de.pixart.messenger.entities.Presence)

Example 28 with Contact

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

the class ShortcutService method refreshImpl.

@TargetApi(25)
private void refreshImpl(boolean forceUpdate) {
    List<FrequentContact> frequentContacts = xmppConnectionService.databaseBackend.getFrequentContacts(30);
    HashMap<String, Account> accounts = new HashMap<>();
    for (Account account : xmppConnectionService.getAccounts()) {
        accounts.put(account.getUuid(), account);
    }
    List<Contact> contacts = new ArrayList<>();
    for (FrequentContact frequentContact : frequentContacts) {
        Account account = accounts.get(frequentContact.account);
        if (account != null) {
            contacts.add(account.getRoster().getContact(frequentContact.contact));
        }
    }
    ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
    boolean needsUpdate = forceUpdate || contactsChanged(contacts, shortcutManager.getDynamicShortcuts());
    if (!needsUpdate) {
        Log.d(Config.LOGTAG, "skipping shortcut update");
        return;
    }
    List<ShortcutInfo> newDynamicShortCuts = new ArrayList<>();
    for (Contact contact : contacts) {
        ShortcutInfo shortcut = new ShortcutInfo.Builder(xmppConnectionService, getShortcutId(contact)).setShortLabel(contact.getDisplayName()).setIntent(getShortcutIntent(contact)).setIcon(Icon.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact))).build();
        newDynamicShortCuts.add(shortcut);
    }
    if (shortcutManager.setDynamicShortcuts(newDynamicShortCuts)) {
        Log.d(Config.LOGTAG, "updated dynamic shortcuts");
    } else {
        Log.d(Config.LOGTAG, "unable to update dynamic shortcuts");
    }
}
Also used : Account(de.pixart.messenger.entities.Account) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Contact(de.pixart.messenger.entities.Contact) TargetApi(android.annotation.TargetApi)

Example 29 with Contact

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

the class StartConversationActivity method deleteContact.

protected void deleteContact() {
    final int position = contact_context_id;
    final Contact contact = (Contact) contacts.get(position);
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setTitle(R.string.action_delete_contact);
    builder.setMessage(getString(R.string.remove_contact_text, contact.getJid()));
    builder.setPositiveButton(R.string.delete, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            xmppConnectionService.deleteContactOnServer(contact);
            filter(mSearchEditText.getText().toString());
        }
    });
    builder.create().show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) SuppressLint(android.annotation.SuppressLint) Contact(de.pixart.messenger.entities.Contact)

Example 30 with Contact

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

the class StartConversationActivity method showCreateContactDialog.

@SuppressLint("InflateParams")
protected void showCreateContactDialog(final String prefilledJid, final Invite invite) {
    EnterJidDialog dialog = new EnterJidDialog(this, mKnownHosts, mActivatedAccounts, getString(R.string.create_contact), getString(R.string.create), prefilledJid, null, invite == null || !invite.hasFingerprints(), xmppConnectionService.multipleAccounts());
    dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
        if (!xmppConnectionServiceBound) {
            return false;
        }
        final Account account = xmppConnectionService.findAccountByJid(accountJid);
        if (account == null) {
            return true;
        }
        final Contact contact = account.getRoster().getContact(contactJid);
        if (invite != null && invite.getName() != null) {
            contact.setServerName(invite.getName());
        }
        if (contact.isSelf()) {
            switchToConversation(contact, null);
            return true;
        } else if (contact.showInRoster()) {
            throw new EnterJidDialog.JidError(getString(R.string.contact_already_exists));
        } else {
            xmppConnectionService.createContact(contact, true);
            if (invite != null && invite.hasFingerprints()) {
                xmppConnectionService.verifyFingerprints(contact, invite.getFingerprints());
            }
            switchToConversation(contact, invite == null ? null : invite.getBody());
            return true;
        }
    });
    mCurrentDialog = dialog.show();
}
Also used : Account(de.pixart.messenger.entities.Account) Contact(de.pixart.messenger.entities.Contact) SuppressLint(android.annotation.SuppressLint)

Aggregations

Contact (de.pixart.messenger.entities.Contact)39 Jid (de.pixart.messenger.xmpp.jid.Jid)16 Account (de.pixart.messenger.entities.Account)12 Conversation (de.pixart.messenger.entities.Conversation)11 Element (de.pixart.messenger.xml.Element)9 SuppressLint (android.annotation.SuppressLint)7 MucOptions (de.pixart.messenger.entities.MucOptions)6 AxolotlService (de.pixart.messenger.crypto.axolotl.AxolotlService)5 ArrayList (java.util.ArrayList)5 PendingIntent (android.app.PendingIntent)4 Intent (android.content.Intent)4 AlertDialog (android.support.v7.app.AlertDialog)4 MenuItem (android.view.MenuItem)4 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)4 DialogInterface (android.content.DialogInterface)3 Bitmap (android.graphics.Bitmap)3 Uri (android.net.Uri)3 Bundle (android.os.Bundle)3 Message (de.pixart.messenger.entities.Message)3 Presence (de.pixart.messenger.entities.Presence)3