Search in sources :

Example 61 with Account

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

the class NotificationService method pushNow.

private void pushNow(final Message message) {
    mXmppConnectionService.updateUnreadCountBadge();
    if (!notify(message)) {
        Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().toBareJid() + ": suppressing notification because turned off");
        return;
    }
    final boolean isScreenOn = mXmppConnectionService.isInteractive();
    if (this.mIsInForeground && isScreenOn && this.mOpenConversation == message.getConversation()) {
        Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().toBareJid() + ": suppressing notification because conversation is open");
        mXmppConnectionService.vibrate();
        return;
    }
    if (this.mIsInForeground && isScreenOn) {
        mXmppConnectionService.vibrate();
    }
    synchronized (notifications) {
        pushToStack(message);
        final Account account = message.getConversation().getAccount();
        final boolean doNotify = (!(this.mIsInForeground && this.mOpenConversation == null) || !isScreenOn) && !account.inGracePeriod() && !this.inMiniGracePeriod(account);
        updateNotification(doNotify);
    }
}
Also used : Account(de.pixart.messenger.entities.Account)

Example 62 with Account

use of de.pixart.messenger.entities.Account 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 63 with Account

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

the class XmppConnectionService method changeRoleInConference.

public void changeRoleInConference(final Conversation conference, final String nick, MucOptions.Role role, final OnRoleChanged callback) {
    IqPacket request = this.mIqGenerator.changeRole(conference, nick, role.toString());
    Log.d(Config.LOGTAG, request.toString());
    sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Log.d(Config.LOGTAG, packet.toString());
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                callback.onRoleChangedSuccessful(nick);
            } else {
                callback.onRoleChangeFailed(nick, R.string.could_not_change_role);
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 64 with Account

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

the class XmppConnectionService method sendMessage.

private void sendMessage(final Message message, final boolean resend, final boolean delay) {
    final Account account = message.getConversation().getAccount();
    if (account.setShowErrorNotification(true)) {
        databaseBackend.updateAccount(account);
        mNotificationService.updateErrorNotification();
    }
    final Conversation conversation = message.getConversation();
    account.deactivateGracePeriod();
    MessagePacket packet = null;
    final boolean addToConversation = (conversation.getMode() != Conversation.MODE_MULTI || !Patches.BAD_MUC_REFLECTION.contains(account.getServerIdentity())) && !message.edited();
    boolean saveInDb = addToConversation;
    message.setStatus(Message.STATUS_WAITING);
    if (!resend && message.getEncryption() != Message.ENCRYPTION_OTR) {
        message.getConversation().endOtrIfNeeded();
        message.getConversation().findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {

            @Override
            public void onMessageFound(Message message) {
                markMessage(message, Message.STATUS_SEND_FAILED);
            }
        });
    }
    if (account.isOnlineAndConnected()) {
        switch(message.getEncryption()) {
            case Message.ENCRYPTION_NONE:
                if (message.needsUploading()) {
                    if (account.httpUploadAvailable(fileBackend.getFile(message, false).getSize()) || conversation.getMode() == Conversation.MODE_MULTI || message.fixCounterpart()) {
                        this.sendFileMessage(message, delay);
                    } else {
                        break;
                    }
                } else {
                    packet = mMessageGenerator.generateChat(message);
                }
                break;
            case Message.ENCRYPTION_PGP:
            case Message.ENCRYPTION_DECRYPTED:
                if (message.needsUploading()) {
                    if (account.httpUploadAvailable(fileBackend.getFile(message, false).getSize()) || conversation.getMode() == Conversation.MODE_MULTI || message.fixCounterpart()) {
                        this.sendFileMessage(message, delay);
                    } else {
                        break;
                    }
                } else {
                    packet = mMessageGenerator.generatePgpChat(message);
                }
                break;
            case Message.ENCRYPTION_OTR:
                SessionImpl otrSession = conversation.getOtrSession();
                if (otrSession != null && otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
                    try {
                        message.setCounterpart(Jid.fromSessionID(otrSession.getSessionID()));
                    } catch (InvalidJidException e) {
                        break;
                    }
                    if (message.needsUploading()) {
                        mJingleConnectionManager.createNewConnection(message);
                    } else {
                        packet = mMessageGenerator.generateOtrChat(message);
                    }
                } else if (otrSession == null) {
                    if (message.fixCounterpart()) {
                        conversation.startOtrSession(message.getCounterpart().getResourcepart(), true);
                    } else {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not fix counterpart for OTR message to contact " + message.getCounterpart());
                        break;
                    }
                } else {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " OTR session with " + message.getContact() + " is in wrong state: " + otrSession.getSessionStatus().toString());
                }
                break;
            case Message.ENCRYPTION_AXOLOTL:
                message.setFingerprint(account.getAxolotlService().getOwnFingerprint());
                if (message.needsUploading()) {
                    if (account.httpUploadAvailable(fileBackend.getFile(message, false).getSize()) || conversation.getMode() == Conversation.MODE_MULTI || message.fixCounterpart()) {
                        this.sendFileMessage(message, delay);
                    } else {
                        break;
                    }
                } else {
                    XmppAxolotlMessage axolotlMessage = account.getAxolotlService().fetchAxolotlMessageFromCache(message);
                    if (axolotlMessage == null) {
                        account.getAxolotlService().preparePayloadMessage(message, delay);
                    } else {
                        packet = mMessageGenerator.generateAxolotlChat(message, axolotlMessage);
                    }
                }
                break;
        }
        if (packet != null) {
            if (account.getXmppConnection().getFeatures().sm() || (conversation.getMode() == Conversation.MODE_MULTI && message.getCounterpart().isBareJid())) {
                message.setStatus(Message.STATUS_UNSEND);
            } else {
                message.setStatus(Message.STATUS_SEND);
            }
        }
    } else {
        switch(message.getEncryption()) {
            case Message.ENCRYPTION_DECRYPTED:
                if (!message.needsUploading()) {
                    String pgpBody = message.getEncryptedBody();
                    String decryptedBody = message.getBody();
                    // TODO might throw NPE
                    message.setBody(pgpBody);
                    message.setEncryption(Message.ENCRYPTION_PGP);
                    if (message.edited()) {
                        message.setBody(decryptedBody);
                        message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                        databaseBackend.updateMessage(message, message.getEditedId());
                        updateConversationUi();
                        return;
                    } else {
                        databaseBackend.createMessage(message);
                        saveInDb = false;
                        message.setBody(decryptedBody);
                        message.setEncryption(Message.ENCRYPTION_DECRYPTED);
                    }
                }
                break;
            case Message.ENCRYPTION_OTR:
                if (!conversation.hasValidOtrSession() && message.getCounterpart() != null) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": create otr session without starting for " + message.getContact().getJid());
                    conversation.startOtrSession(message.getCounterpart().getResourcepart(), false);
                }
                break;
            case Message.ENCRYPTION_AXOLOTL:
                message.setFingerprint(account.getAxolotlService().getOwnFingerprint());
                break;
        }
    }
    boolean mucMessage = conversation.getMode() == Conversation.MODE_MULTI && message.getType() != Message.TYPE_PRIVATE;
    if (mucMessage) {
        message.setCounterpart(conversation.getMucOptions().getSelf().getFullJid());
    }
    if (resend) {
        if (packet != null && addToConversation) {
            if (account.getXmppConnection().getFeatures().sm() || mucMessage) {
                markMessage(message, Message.STATUS_UNSEND);
            } else {
                markMessage(message, Message.STATUS_SEND);
            }
        }
    } else {
        if (addToConversation) {
            conversation.add(message);
        }
        if (saveInDb) {
            databaseBackend.createMessage(message);
        } else if (message.edited()) {
            databaseBackend.updateMessage(message, message.getEditedId());
        }
        updateConversationUi();
    }
    if (packet != null) {
        if (delay) {
            mMessageGenerator.addDelay(packet, message.getTimeSent());
        }
        if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
            if (this.sendChatStates()) {
                packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
            }
        }
        sendMessagePacket(account, packet);
    }
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) Account(de.pixart.messenger.entities.Account) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) Message(de.pixart.messenger.entities.Message) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) XmppAxolotlMessage(de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage) SessionImpl(net.java.otr4j.session.SessionImpl)

Example 65 with Account

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

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(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

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