Search in sources :

Example 1 with OTRUnencryptedException

use of com.xabber.android.data.extension.otr.OTRUnencryptedException in project xabber-android by redsolution.

the class RegularChat method onPacket.

@Override
protected boolean onPacket(String bareAddress, Stanza packet) {
    if (!super.onPacket(bareAddress, packet))
        return false;
    final String resource = Jid.getResource(packet.getFrom());
    if (packet instanceof Presence) {
        final Presence presence = (Presence) packet;
        if (this.resource != null && presence.getType() == Presence.Type.unavailable && this.resource.equals(resource)) {
            this.resource = null;
        }
        if (presence.getType() == Presence.Type.unavailable) {
            OTRManager.getInstance().onContactUnAvailable(account, user);
        }
    } else if (packet instanceof Message) {
        final Message message = (Message) packet;
        if (message.getType() == Message.Type.error)
            return true;
        MUCUser mucUser = MUC.getMUCUserExtension(message);
        if (mucUser != null && mucUser.getInvite() != null)
            return true;
        String text = message.getBody();
        if (text == null)
            return true;
        String thread = message.getThread();
        updateThreadId(thread);
        boolean unencrypted = false;
        try {
            text = OTRManager.getInstance().transformReceiving(account, user, text);
        } catch (OtrException e) {
            if (e.getCause() instanceof OTRUnencryptedException) {
                text = ((OTRUnencryptedException) e.getCause()).getText();
                unencrypted = true;
            } else {
                LogManager.exception(this, e);
                // Invalid message received.
                return true;
            }
        }
        // System message received.
        if (text == null || text.trim().equals(""))
            return true;
        if (!"".equals(resource))
            this.resource = resource;
        newMessage(resource, text, null, Delay.getDelay(message), true, true, unencrypted, Delay.isOfflineMessage(Jid.getServer(account), packet), MessageArchiveManager.getInstance().getSaveMode(account, user, getThreadId()) != SaveMode.fls);
    }
    return true;
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message) Presence(org.jivesoftware.smack.packet.Presence) OtrException(net.java.otr4j.OtrException) OTRUnencryptedException(com.xabber.android.data.extension.otr.OTRUnencryptedException)

Aggregations

OTRUnencryptedException (com.xabber.android.data.extension.otr.OTRUnencryptedException)1 OtrException (net.java.otr4j.OtrException)1 Message (org.jivesoftware.smack.packet.Message)1 Presence (org.jivesoftware.smack.packet.Presence)1 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)1