Search in sources :

Example 31 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

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(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket) Contact(eu.siacs.conversations.entities.Contact)

Example 32 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method sendBlockRequest.

public boolean sendBlockRequest(final Blockable blockable, boolean reportSpam) {
    if (blockable != null && blockable.getBlockedJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetBlockRequest(jid, reportSpam), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().add(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.BLOCKED);
                }
            }
        });
        if (removeBlockedConversations(blockable.getAccount(), jid)) {
            updateConversationUi();
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 33 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method fetchConferenceConfiguration.

public void fetchConferenceConfiguration(final Conversation conversation, final OnConferenceConfigurationFetched callback) {
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.setTo(conversation.getJid().toBareJid());
    request.query("http://jabber.org/protocol/disco#info");
    sendIqPacket(conversation.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element query = packet.findChild("query", "http://jabber.org/protocol/disco#info");
            if (packet.getType() == IqPacket.TYPE.RESULT && query != null) {
                ArrayList<String> features = new ArrayList<>();
                for (Element child : query.getChildren()) {
                    if (child != null && child.getName().equals("feature")) {
                        String var = child.getAttribute("var");
                        if (var != null) {
                            features.add(var);
                        }
                    }
                }
                Element form = query.findChild("x", "jabber:x:data");
                if (form != null) {
                    conversation.getMucOptions().updateFormData(Data.parse(form));
                }
                conversation.getMucOptions().updateFeatures(features);
                if (callback != null) {
                    callback.onConferenceConfigurationFetched(conversation);
                }
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": fetched muc configuration for " + conversation.getJid().toBareJid() + " - " + features.toString());
                updateConversationUi();
            } else if (packet.getType() == IqPacket.TYPE.ERROR) {
                if (callback != null) {
                    callback.onFetchFailed(conversation, packet.getError());
                }
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 34 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class XmppConnectionService method onCreate.

@SuppressLint("TrulyRandom")
@Override
public void onCreate() {
    ExceptionHelper.init(getApplicationContext());
    PRNGFixes.apply();
    this.mRandom = new SecureRandom();
    updateMemorizingTrustmanager();
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int cacheSize = maxMemory / 8;
    this.mBitmapCache = new LruCache<String, Bitmap>(cacheSize) {

        @Override
        protected int sizeOf(final String key, final Bitmap bitmap) {
            return bitmap.getByteCount() / 1024;
        }
    };
    this.databaseBackend = DatabaseBackend.getInstance(getApplicationContext());
    this.accounts = databaseBackend.getAccounts();
    if (Config.FREQUENT_RESTARTS_THRESHOLD != 0 && Config.FREQUENT_RESTARTS_DETECTION_WINDOW != 0 && !keepForegroundService() && databaseBackend.startTimeCountExceedsThreshold()) {
        getPreferences().edit().putBoolean(SettingsActivity.KEEP_FOREGROUND_SERVICE, true).commit();
        Log.d(Config.LOGTAG, "number of restarts exceeds threshold. enabling foreground service");
    }
    restoreFromDatabase();
    getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true, contactObserver);
    new Thread(new Runnable() {

        @Override
        public void run() {
            fileObserver.startWatching();
        }
    }).start();
    if (Config.supportOpenPgp()) {
        this.pgpServiceConnection = new OpenPgpServiceConnection(getApplicationContext(), "org.sufficientlysecure.keychain", new OpenPgpServiceConnection.OnBound() {

            @Override
            public void onBound(IOpenPgpService2 service) {
                for (Account account : accounts) {
                    final PgpDecryptionService pgp = account.getPgpDecryptionService();
                    if (pgp != null) {
                        pgp.continueDecryption(true);
                    }
                }
            }

            @Override
            public void onError(Exception e) {
            }
        });
        this.pgpServiceConnection.bindToService();
    }
    this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "XmppConnectionService");
    toggleForegroundService();
    updateUnreadCountBadge();
    toggleScreenEventReceiver();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        scheduleNextIdlePing();
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        registerReceiver(this.mEventReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) IntentFilter(android.content.IntentFilter) IOpenPgpService2(org.openintents.openpgp.IOpenPgpService2) SecureRandom(java.security.SecureRandom) OpenPgpServiceConnection(org.openintents.openpgp.util.OpenPgpServiceConnection) PgpDecryptionService(eu.siacs.conversations.crypto.PgpDecryptionService) SuppressLint(android.annotation.SuppressLint) OtrException(net.java.otr4j.OtrException) FileNotFoundException(java.io.FileNotFoundException) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) CertificateException(java.security.cert.CertificateException) Bitmap(android.graphics.Bitmap) SuppressLint(android.annotation.SuppressLint)

Example 35 with Account

use of eu.siacs.conversations.entities.Account in project Conversations by siacs.

the class NotificationService method createForegroundNotification.

public Notification createForegroundNotification() {
    final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
    mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
    if (Config.SHOW_CONNECTED_ACCOUNTS) {
        List<Account> accounts = mXmppConnectionService.getAccounts();
        int enabled = 0;
        int connected = 0;
        for (Account account : accounts) {
            if (account.isOnlineAndConnected()) {
                connected++;
                enabled++;
            } else if (!account.isOptionSet(Account.OPTION_DISABLED)) {
                enabled++;
            }
        }
        mBuilder.setContentText(mXmppConnectionService.getString(R.string.connected_accounts, connected, enabled));
    } else {
        mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_open_conversations));
    }
    mBuilder.setContentIntent(createOpenConversationsIntent());
    mBuilder.setWhen(0);
    mBuilder.setPriority(Config.SHOW_CONNECTED_ACCOUNTS ? NotificationCompat.PRIORITY_DEFAULT : NotificationCompat.PRIORITY_MIN);
    mBuilder.setSmallIcon(R.drawable.ic_link_white_24dp);
    if (Config.SHOW_DISABLE_FOREGROUND) {
        final int cancelIcon;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBuilder.setCategory(Notification.CATEGORY_SERVICE);
            cancelIcon = R.drawable.ic_cancel_white_24dp;
        } else {
            cancelIcon = R.drawable.ic_action_cancel;
        }
        mBuilder.addAction(cancelIcon, mXmppConnectionService.getString(R.string.disable_foreground_service), createDisableForeground());
    }
    return mBuilder.build();
}
Also used : Account(eu.siacs.conversations.entities.Account) Builder(android.support.v4.app.NotificationCompat.Builder) Builder(android.support.v4.app.NotificationCompat.Builder) NotificationCompat(android.support.v4.app.NotificationCompat)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5