Search in sources :

Example 46 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class Message method fromCursor.

public static Message fromCursor(Cursor cursor) {
    Jid jid;
    try {
        String value = cursor.getString(cursor.getColumnIndex(COUNTERPART));
        if (value != null) {
            jid = Jid.fromString(value, true);
        } else {
            jid = null;
        }
    } catch (InvalidJidException e) {
        jid = null;
    } catch (IllegalStateException e) {
        // message too long?
        return null;
    }
    Jid trueCounterpart;
    try {
        String value = cursor.getString(cursor.getColumnIndex(TRUE_COUNTERPART));
        if (value != null) {
            trueCounterpart = Jid.fromString(value, true);
        } else {
            trueCounterpart = null;
        }
    } catch (InvalidJidException e) {
        trueCounterpart = null;
    }
    return new Message(cursor.getString(cursor.getColumnIndex(UUID)), cursor.getString(cursor.getColumnIndex(CONVERSATION)), jid, trueCounterpart, cursor.getString(cursor.getColumnIndex(BODY)), cursor.getLong(cursor.getColumnIndex(TIME_SENT)), cursor.getInt(cursor.getColumnIndex(ENCRYPTION)), cursor.getInt(cursor.getColumnIndex(STATUS)), cursor.getInt(cursor.getColumnIndex(TYPE)), cursor.getInt(cursor.getColumnIndex(CARBON)) > 0, cursor.getString(cursor.getColumnIndex(REMOTE_MSG_ID)), cursor.getString(cursor.getColumnIndex(RELATIVE_FILE_PATH)), cursor.getString(cursor.getColumnIndex(SERVER_MSG_ID)), cursor.getString(cursor.getColumnIndex(FINGERPRINT)), cursor.getInt(cursor.getColumnIndex(READ)) > 0, cursor.getString(cursor.getColumnIndex(EDITED)), cursor.getInt(cursor.getColumnIndex(OOB)) > 0, cursor.getString(cursor.getColumnIndex(ERROR_MESSAGE)));
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException)

Example 47 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class IqGenerator method changeAffiliation.

public IqPacket changeAffiliation(Conversation conference, List<Jid> jids, String affiliation) {
    IqPacket packet = new IqPacket(IqPacket.TYPE.SET);
    packet.setTo(conference.getJid().toBareJid());
    packet.setFrom(conference.getAccount().getJid());
    Element query = packet.query("http://jabber.org/protocol/muc#admin");
    for (Jid jid : jids) {
        Element item = query.addChild("item");
        item.setAttribute("jid", jid.toString());
        item.setAttribute("affiliation", affiliation);
    }
    return packet;
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 48 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class Account method setJid.

public boolean setJid(final Jid next) {
    final Jid prev = this.jid != null ? this.jid.toBareJid() : null;
    this.jid = next;
    return prev == null || (next != null && !prev.equals(next.toBareJid()));
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 49 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class Bookmark method match.

@Override
public boolean match(Context context, String needle) {
    if (needle == null) {
        return true;
    }
    needle = needle.toLowerCase(Locale.US);
    final Jid jid = getJid();
    return (jid != null && jid.toString().contains(needle)) || getDisplayName().toLowerCase(Locale.US).contains(needle) || matchInTag(context, needle);
}
Also used : Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 50 with Jid

use of eu.siacs.conversations.xmpp.jid.Jid in project Conversations by siacs.

the class AxolotlService method findDevicesWithoutSession.

public Set<AxolotlAddress> findDevicesWithoutSession(final Conversation conversation) {
    Set<AxolotlAddress> addresses = new HashSet<>();
    for (Jid jid : getCryptoTargets(conversation)) {
        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Finding devices without session for " + jid);
        if (deviceIds.get(jid) != null) {
            for (Integer foreignId : this.deviceIds.get(jid)) {
                AxolotlAddress address = new AxolotlAddress(jid.toPreppedString(), foreignId);
                if (sessions.get(address) == null) {
                    IdentityKey identityKey = axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
                    if (identityKey != null) {
                        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Already have session for " + address.toString() + ", adding to cache...");
                        XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, identityKey);
                        sessions.put(address, session);
                    } else {
                        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Found device " + jid + ":" + foreignId);
                        if (fetchStatusMap.get(address) != FetchStatus.ERROR) {
                            addresses.add(address);
                        } else {
                            Log.d(Config.LOGTAG, getLogprefix(account) + "skipping over " + address + " because it's broken");
                        }
                    }
                }
            }
        } else {
            Log.w(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Have no target devices in PEP!");
        }
    }
    if (deviceIds.get(account.getJid().toBareJid()) != null) {
        for (Integer ownId : this.deviceIds.get(account.getJid().toBareJid())) {
            AxolotlAddress address = new AxolotlAddress(account.getJid().toBareJid().toPreppedString(), ownId);
            if (sessions.get(address) == null) {
                IdentityKey identityKey = axolotlStore.loadSession(address).getSessionState().getRemoteIdentityKey();
                if (identityKey != null) {
                    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Already have session for " + address.toString() + ", adding to cache...");
                    XmppAxolotlSession session = new XmppAxolotlSession(account, axolotlStore, address, identityKey);
                    sessions.put(address, session);
                } else {
                    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Found device " + account.getJid().toBareJid() + ":" + ownId);
                    if (fetchStatusMap.get(address) != FetchStatus.ERROR) {
                        addresses.add(address);
                    } else {
                        Log.d(Config.LOGTAG, getLogprefix(account) + "skipping over " + address + " because it's broken");
                    }
                }
            }
        }
    }
    return addresses;
}
Also used : IdentityKey(org.whispersystems.libaxolotl.IdentityKey) Jid(eu.siacs.conversations.xmpp.jid.Jid) AxolotlAddress(org.whispersystems.libaxolotl.AxolotlAddress) HashSet(java.util.HashSet)

Aggregations

Jid (eu.siacs.conversations.xmpp.jid.Jid)59 Account (eu.siacs.conversations.entities.Account)22 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)19 Element (eu.siacs.conversations.xml.Element)17 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)14 Conversation (eu.siacs.conversations.entities.Conversation)13 Contact (eu.siacs.conversations.entities.Contact)9 MucOptions (eu.siacs.conversations.entities.MucOptions)9 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)9 Message (eu.siacs.conversations.entities.Message)7 ArrayList (java.util.ArrayList)6 Intent (android.content.Intent)5 SuppressLint (android.annotation.SuppressLint)4 AlertDialog (android.app.AlertDialog)4 TextView (android.widget.TextView)4 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)4 Bookmark (eu.siacs.conversations.entities.Bookmark)4 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)4 HashMap (java.util.HashMap)4 PendingIntent (android.app.PendingIntent)3