do not load conversations with null jid

This commit is contained in:
Daniel Gultsch 2018-05-09 11:09:01 +02:00
parent 18a8a6e5ac
commit e84a65bc86
4 changed files with 23 additions and 10 deletions

View file

@ -23,6 +23,8 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.OmemoSetting; import eu.siacs.conversations.crypto.OmemoSetting;
import eu.siacs.conversations.crypto.PgpDecryptionService; import eu.siacs.conversations.crypto.PgpDecryptionService;
import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.utils.JidHelper;
import eu.siacs.conversations.xmpp.InvalidJid;
import eu.siacs.conversations.xmpp.chatstate.ChatState; import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.mam.MamReference; import eu.siacs.conversations.xmpp.mam.MamReference;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
@ -104,18 +106,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
} }
public static Conversation fromCursor(Cursor cursor) { 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)), return new Conversation(cursor.getString(cursor.getColumnIndex(UUID)),
cursor.getString(cursor.getColumnIndex(NAME)), cursor.getString(cursor.getColumnIndex(NAME)),
cursor.getString(cursor.getColumnIndex(CONTACT)), cursor.getString(cursor.getColumnIndex(CONTACT)),
cursor.getString(cursor.getColumnIndex(ACCOUNT)), cursor.getString(cursor.getColumnIndex(ACCOUNT)),
jid, JidHelper.parseOrFallbackToInvalid(cursor.getString(cursor.getColumnIndex(CONTACTJID))),
cursor.getLong(cursor.getColumnIndex(CREATED)), cursor.getLong(cursor.getColumnIndex(CREATED)),
cursor.getInt(cursor.getColumnIndex(STATUS)), cursor.getInt(cursor.getColumnIndex(STATUS)),
cursor.getInt(cursor.getColumnIndex(MODE)), cursor.getInt(cursor.getColumnIndex(MODE)),

View file

@ -53,6 +53,7 @@ import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.FtsUtils; import eu.siacs.conversations.utils.FtsUtils;
import eu.siacs.conversations.utils.MimeUtils; import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.Resolver; import eu.siacs.conversations.utils.Resolver;
import eu.siacs.conversations.xmpp.InvalidJid;
import eu.siacs.conversations.xmpp.mam.MamReference; import eu.siacs.conversations.xmpp.mam.MamReference;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
@ -680,10 +681,14 @@ public class DatabaseBackend extends SQLiteOpenHelper {
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
String[] selectionArgs = {Integer.toString(status)}; String[] selectionArgs = {Integer.toString(status)};
Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME 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); + Conversation.CREATED + " desc", selectionArgs);
while (cursor.moveToNext()) { 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(); cursor.close();
return list; return list;
@ -780,6 +785,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
cursor.moveToFirst(); cursor.moveToFirst();
Conversation conversation = Conversation.fromCursor(cursor); Conversation conversation = Conversation.fromCursor(cursor);
cursor.close(); cursor.close();
if (conversation.getJid() instanceof InvalidJid) {
return null;
}
return conversation; return conversation;
} }

View file

@ -34,6 +34,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import eu.siacs.conversations.xmpp.InvalidJid;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class JidHelper { public class JidHelper {
@ -50,4 +51,12 @@ public class JidHelper {
} }
} }
public static Jid parseOrFallbackToInvalid(String jid) {
try {
return Jid.of(jid);
} catch (IllegalArgumentException e) {
return InvalidJid.of(jid, true);
}
}
} }

View file

@ -41,6 +41,7 @@ public class InvalidJid implements Jid {
private InvalidJid(String jid) { private InvalidJid(String jid) {
this.value = jid; this.value = jid;
} }
public static Jid of(String jid, boolean fallback) { public static Jid of(String jid, boolean fallback) {
final int pos = jid.indexOf('/'); final int pos = jid.indexOf('/');
if (fallback && pos >= 0 && jid.length() >= pos + 1) { if (fallback && pos >= 0 && jid.length() >= pos + 1) {