mirror of https://github.com/M66B/FairEmail.git
Auto fix broken threads
This commit is contained in:
parent
b84ab27882
commit
7546b50046
File diff suppressed because it is too large
Load Diff
|
@ -61,7 +61,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 155,
|
||||
version = 156,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -1552,6 +1552,13 @@ public abstract class DB extends RoomDatabase {
|
|||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("UPDATE `folder` SET `poll` = 1 WHERE `synchronize` = 0");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(155, 156) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("CREATE INDEX IF NOT EXISTS `index_message_inreplyto` ON `message` (`inreplyto`)");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -329,6 +329,11 @@ public interface DaoMessage {
|
|||
" AND msgid = :msgid")
|
||||
List<EntityMessage> getMessagesByMsgId(long account, String msgid);
|
||||
|
||||
@Query("SELECT * FROM message" +
|
||||
" WHERE account = :account" +
|
||||
" AND inreplyto = :inreplyto")
|
||||
List<EntityMessage> getMessagesByInReplyTo(long account, String inreplyto);
|
||||
|
||||
@Query("SELECT * FROM message" +
|
||||
" WHERE account = :account" +
|
||||
" AND (id = :id OR msgid = :msgid)")
|
||||
|
@ -515,8 +520,9 @@ public interface DaoMessage {
|
|||
@Update
|
||||
int updateMessage(EntityMessage message);
|
||||
|
||||
@Query("UPDATE message SET identity = :identity WHERE id = :id")
|
||||
int setMessageIdentity(long id, Long identity);
|
||||
@Query("UPDATE message SET thread = :thread" +
|
||||
" WHERE account = :account AND thread = :old")
|
||||
int updateMessageThread(long account, String old, String thread);
|
||||
|
||||
@Query("UPDATE message SET uid = :uid WHERE id = :id")
|
||||
int setMessageUid(long id, Long uid);
|
||||
|
|
|
@ -63,6 +63,7 @@ import static androidx.room.ForeignKey.SET_NULL;
|
|||
@Index(value = {"folder"}),
|
||||
@Index(value = {"identity"}),
|
||||
@Index(value = {"folder", "uid"}, unique = true),
|
||||
@Index(value = {"inreplyto"}),
|
||||
@Index(value = {"msgid"}),
|
||||
@Index(value = {"thread"}),
|
||||
@Index(value = {"sender"}),
|
||||
|
|
|
@ -863,8 +863,10 @@ public class MessageHelper {
|
|||
}
|
||||
|
||||
String getThreadId(Context context, long account, long uid) throws MessagingException {
|
||||
List<String> refs = new ArrayList<>();
|
||||
String thread = null;
|
||||
String msgid = getMessageID();
|
||||
|
||||
List<String> refs = new ArrayList<>();
|
||||
for (String ref : getReferences())
|
||||
if (!TextUtils.isEmpty(ref))
|
||||
refs.add(ref);
|
||||
|
@ -875,16 +877,37 @@ public class MessageHelper {
|
|||
|
||||
DB db = DB.getInstance(context);
|
||||
for (String ref : refs) {
|
||||
List<EntityMessage> messages = db.message().getMessagesByMsgId(account, ref);
|
||||
if (messages.size() > 0)
|
||||
return messages.get(0).thread;
|
||||
List<EntityMessage> before = db.message().getMessagesByMsgId(account, ref);
|
||||
for (EntityMessage message : before) {
|
||||
if (thread == null && !TextUtils.isEmpty(message.thread))
|
||||
thread = message.thread;
|
||||
if (thread != null &&
|
||||
!TextUtils.isEmpty(message.thread) && !thread.equals(message.thread)) {
|
||||
Log.w("Updating before thread from " + message.thread + " to " + thread);
|
||||
db.message().updateMessageThread(message.account, message.thread, thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (refs.size() > 0)
|
||||
return refs.get(0);
|
||||
if (thread == null && refs.size() > 0)
|
||||
thread = refs.get(0);
|
||||
|
||||
String msgid = getMessageID();
|
||||
return (TextUtils.isEmpty(msgid) ? Long.toString(uid) : msgid);
|
||||
if (thread != null) {
|
||||
List<EntityMessage> after = db.message().getMessagesByInReplyTo(account, msgid);
|
||||
for (EntityMessage message : after)
|
||||
if (!TextUtils.isEmpty(message.thread) && !thread.equals(message.thread)) {
|
||||
Log.w("Updating after thread from " + message.thread + " to " + thread);
|
||||
db.message().updateMessageThread(message.account, message.thread, thread);
|
||||
}
|
||||
}
|
||||
|
||||
if (thread == null)
|
||||
if (TextUtils.isEmpty(msgid))
|
||||
thread = Long.toString(uid);
|
||||
else
|
||||
thread = msgid;
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
Integer getPriority() throws MessagingException {
|
||||
|
|
Loading…
Reference in New Issue