Search in sources :

Example 1 with InvalidJid

use of eu.siacs.conversations.xmpp.InvalidJid in project Conversations by siacs.

the class DatabaseBackend method getConversations.

public CopyOnWriteArrayList<Conversation> getConversations(int status) {
    CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<>();
    SQLiteDatabase db = this.getReadableDatabase();
    String[] selectionArgs = { Integer.toString(status) };
    Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME + " where " + Conversation.STATUS + " = ? and " + Conversation.CONTACTJID + " is not null order by " + Conversation.CREATED + " desc", selectionArgs);
    while (cursor.moveToNext()) {
        final Conversation conversation = Conversation.fromCursor(cursor);
        if (conversation.getJid() instanceof InvalidJid) {
            continue;
        }
        list.add(conversation);
    }
    cursor.close();
    return list;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Conversation(eu.siacs.conversations.entities.Conversation) Cursor(android.database.Cursor) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) InvalidJid(eu.siacs.conversations.xmpp.InvalidJid)

Example 2 with InvalidJid

use of eu.siacs.conversations.xmpp.InvalidJid in project Conversations by siacs.

the class DatabaseBackend method findConversation.

public Conversation findConversation(final Account account, final Jid contactJid) {
    SQLiteDatabase db = this.getReadableDatabase();
    String[] selectionArgs = { account.getUuid(), contactJid.asBareJid().toString() + "/%", contactJid.asBareJid().toString() };
    Cursor cursor = db.query(Conversation.TABLENAME, null, Conversation.ACCOUNT + "=? AND (" + Conversation.CONTACTJID + " like ? OR " + Conversation.CONTACTJID + "=?)", selectionArgs, null, null, null);
    if (cursor.getCount() == 0) {
        cursor.close();
        return null;
    }
    cursor.moveToFirst();
    Conversation conversation = Conversation.fromCursor(cursor);
    cursor.close();
    if (conversation.getJid() instanceof InvalidJid) {
        return null;
    }
    return conversation;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Conversation(eu.siacs.conversations.entities.Conversation) Cursor(android.database.Cursor) InvalidJid(eu.siacs.conversations.xmpp.InvalidJid)

Aggregations

Cursor (android.database.Cursor)2 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 Conversation (eu.siacs.conversations.entities.Conversation)2 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1