do not load conversations with null jid
This commit is contained in:
parent
18a8a6e5ac
commit
e84a65bc86
|
@ -23,6 +23,8 @@ import eu.siacs.conversations.Config;
|
|||
import eu.siacs.conversations.crypto.OmemoSetting;
|
||||
import eu.siacs.conversations.crypto.PgpDecryptionService;
|
||||
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.mam.MamReference;
|
||||
import rocks.xmpp.addr.Jid;
|
||||
|
@ -104,18 +106,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)),
|
||||
|
|
|
@ -53,6 +53,7 @@ import eu.siacs.conversations.utils.CryptoHelper;
|
|||
import eu.siacs.conversations.utils.FtsUtils;
|
||||
import eu.siacs.conversations.utils.MimeUtils;
|
||||
import eu.siacs.conversations.utils.Resolver;
|
||||
import eu.siacs.conversations.xmpp.InvalidJid;
|
||||
import eu.siacs.conversations.xmpp.mam.MamReference;
|
||||
import rocks.xmpp.addr.Jid;
|
||||
|
||||
|
@ -680,10 +681,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;
|
||||
|
@ -780,6 +785,9 @@ public class DatabaseBackend extends SQLiteOpenHelper {
|
|||
cursor.moveToFirst();
|
||||
Conversation conversation = Conversation.fromCursor(cursor);
|
||||
cursor.close();
|
||||
if (conversation.getJid() instanceof InvalidJid) {
|
||||
return null;
|
||||
}
|
||||
return conversation;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import eu.siacs.conversations.xmpp.InvalidJid;
|
||||
import rocks.xmpp.addr.Jid;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ public class InvalidJid implements Jid {
|
|||
private InvalidJid(String jid) {
|
||||
this.value = jid;
|
||||
}
|
||||
|
||||
public static Jid of(String jid, boolean fallback) {
|
||||
final int pos = jid.indexOf('/');
|
||||
if (fallback && pos >= 0 && jid.length() >= pos + 1) {
|
||||
|
|
Loading…
Reference in New Issue