aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-05-16 21:45:29 +0200
committerChristian Schneppe <christian@pix-art.de>2018-05-16 21:45:29 +0200
commitf8ec77ab9689193e366eb3aed51cb17d1ccbd986 (patch)
tree6c95907b7c1ccd27d6d18461dfc7ad7357fe89aa /src/main/java/de/pixart
parent0525b1f960f4d7b45940bfe4a88beac99e571363 (diff)
do not load conversations with null jid
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Conversation.java10
-rw-r--r--src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java12
-rw-r--r--src/main/java/de/pixart/messenger/utils/JidHelper.java8
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