diff options
Diffstat (limited to 'src/main/java/de')
3 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Conversation.java b/src/main/java/de/pixart/messenger/entities/Conversation.java index 3aaa89529..98a847b09 100644 --- a/src/main/java/de/pixart/messenger/entities/Conversation.java +++ b/src/main/java/de/pixart/messenger/entities/Conversation.java @@ -29,6 +29,7 @@ import de.pixart.messenger.Config; import de.pixart.messenger.crypto.OmemoSetting; import de.pixart.messenger.crypto.PgpDecryptionService; import de.pixart.messenger.crypto.axolotl.AxolotlService; +import de.pixart.messenger.utils.JidHelper; import de.pixart.messenger.xmpp.chatstate.ChatState; import de.pixart.messenger.xmpp.mam.MamReference; import rocks.xmpp.addr.Jid; @@ -115,18 +116,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl } public static Conversation fromCursor(Cursor cursor) { - Jid jid; - try { - jid = Jid.of(cursor.getString(cursor.getColumnIndex(CONTACTJID))); - } catch (final IllegalArgumentException e) { - // Borked DB.. - jid = null; - } return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)), cursor.getString(cursor.getColumnIndex(NAME)), cursor.getString(cursor.getColumnIndex(CONTACT)), cursor.getString(cursor.getColumnIndex(ACCOUNT)), - jid, + JidHelper.parseOrFallbackToInvalid(cursor.getString(cursor.getColumnIndex(CONTACTJID))), cursor.getLong(cursor.getColumnIndex(CREATED)), cursor.getInt(cursor.getColumnIndex(STATUS)), cursor.getInt(cursor.getColumnIndex(MODE)), diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index 7d9c38718..dab6dde5d 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -52,6 +52,7 @@ import de.pixart.messenger.services.ShortcutService; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.FtsUtils; import de.pixart.messenger.utils.Resolver; +import de.pixart.messenger.xmpp.InvalidJid; import de.pixart.messenger.xmpp.mam.MamReference; import rocks.xmpp.addr.Jid; @@ -692,10 +693,14 @@ public class DatabaseBackend extends SQLiteOpenHelper { SQLiteDatabase db = this.getReadableDatabase(); String[] selectionArgs = {Integer.toString(status)}; Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME - + " where " + Conversation.STATUS + " = ? order by " + + " where " + Conversation.STATUS + " = ? and "+Conversation.CONTACTJID+" is not null order by " + Conversation.CREATED + " desc", selectionArgs); while (cursor.moveToNext()) { - list.add(Conversation.fromCursor(cursor)); + final Conversation conversation = Conversation.fromCursor(cursor); + if (conversation.getJid() instanceof InvalidJid) { + continue; + } + list.add(conversation); } cursor.close(); return list; @@ -793,6 +798,9 @@ public class DatabaseBackend extends SQLiteOpenHelper { cursor.moveToFirst(); Conversation conversation = Conversation.fromCursor(cursor); cursor.close(); + if (conversation.getJid() instanceof InvalidJid) { + return null; + } return conversation; } diff --git a/src/main/java/de/pixart/messenger/utils/JidHelper.java b/src/main/java/de/pixart/messenger/utils/JidHelper.java index a569c5960..6b0dc0122 100644 --- a/src/main/java/de/pixart/messenger/utils/JidHelper.java +++ b/src/main/java/de/pixart/messenger/utils/JidHelper.java @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; +import de.pixart.messenger.xmpp.InvalidJid; import rocks.xmpp.addr.Jid; public class JidHelper { @@ -50,4 +51,11 @@ public class JidHelper { } } + public static Jid parseOrFallbackToInvalid(String jid) { + try { + return Jid.of(jid); + } catch (IllegalArgumentException e) { + return InvalidJid.of(jid, true); + } + } }
\ No newline at end of file |