From 8af8641089fb0490871d71d1f17b4888e94e8dae Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 29 Apr 2020 19:29:13 +0200 Subject: [PATCH] Auto link broken threads --- app/src/main/java/eu/faircode/email/DaoMessage.java | 3 +++ .../main/java/eu/faircode/email/MessageHelper.java | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoMessage.java b/app/src/main/java/eu/faircode/email/DaoMessage.java index e77fc916f0..50a06947b2 100644 --- a/app/src/main/java/eu/faircode/email/DaoMessage.java +++ b/app/src/main/java/eu/faircode/email/DaoMessage.java @@ -587,6 +587,9 @@ public interface DaoMessage { @Query("UPDATE message SET revisions = :revisions WHERE id = :id") int setMessageRevisions(long id, Integer revisions); + @Query("UPDATE message SET thread = :thread WHERE id = :id") + int setMessageThread(long id, String thread); + @Query("UPDATE message" + " SET content = 0, fts = 0, language = NULL, plain_only = NULL, preview = NULL" + " WHERE id = :id") diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java index 9c1467ec46..161059fd6b 100644 --- a/app/src/main/java/eu/faircode/email/MessageHelper.java +++ b/app/src/main/java/eu/faircode/email/MessageHelper.java @@ -873,12 +873,19 @@ public class MessageHelper { if (!TextUtils.isEmpty(inreplyto) && !refs.contains(inreplyto)) refs.add(inreplyto); + String thread = null; DB db = DB.getInstance(context); for (String ref : refs) { List messages = db.message().getMessagesByMsgId(account, ref); - if (messages.size() > 0) - return messages.get(0).thread; + for (EntityMessage message : messages) { + if (thread == null) + thread = message.thread; + if (thread != null && !thread.equals(message.thread)) + db.message().setMessageThread(message.id, thread); + } } + if (thread != null) + return thread; if (refs.size() > 0) return refs.get(0);