Refactoring

pull/194/merge
M66B 3 years ago
parent fdcf20dcd0
commit 8cead67e07

@ -1291,7 +1291,7 @@ public class MessageHelper {
List<String> refs = new ArrayList<>(); List<String> refs = new ArrayList<>();
for (String ref : getReferences()) for (String ref : getReferences())
if (!TextUtils.isEmpty(ref)) if (!TextUtils.isEmpty(ref) && !refs.contains(ref))
refs.add(ref); refs.add(ref);
String inreplyto = getInReplyTo(); String inreplyto = getInReplyTo();
@ -1299,18 +1299,15 @@ public class MessageHelper {
refs.add(inreplyto); refs.add(inreplyto);
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
for (String ref : refs) { List<EntityMessage> before = new ArrayList<>();
List<EntityMessage> before = db.message().getMessagesByMsgId(account, ref); for (String ref : refs)
for (EntityMessage message : before) { before.addAll(db.message().getMessagesByMsgId(account, ref));
if (thread == null && !TextUtils.isEmpty(message.thread))
thread = message.thread; for (EntityMessage message : before)
if (thread != null && if (!TextUtils.isEmpty(message.thread)) {
!TextUtils.isEmpty(message.thread) && !thread.equals(message.thread)) { thread = message.thread;
Log.w("Updating before thread from " + message.thread + " to " + thread); break;
db.message().updateMessageThread(message.account, message.thread, thread);
}
} }
}
if (thread == null) { if (thread == null) {
List<EntityMessage> similar = db.message().getMessagesByMsgId(account, msgid); List<EntityMessage> similar = db.message().getMessagesByMsgId(account, msgid);
@ -1324,9 +1321,15 @@ public class MessageHelper {
if (thread == null) if (thread == null)
thread = getHash() + ":" + uid; thread = getHash() + ":" + uid;
for (EntityMessage message : before)
if (!thread.equals(message.thread)) {
Log.w("Updating before thread from " + message.thread + " to " + thread);
db.message().updateMessageThread(message.account, message.thread, thread);
}
List<EntityMessage> after = db.message().getMessagesByInReplyTo(account, msgid); List<EntityMessage> after = db.message().getMessagesByInReplyTo(account, msgid);
for (EntityMessage message : after) for (EntityMessage message : after)
if (!TextUtils.isEmpty(message.thread) && !thread.equals(message.thread)) { if (!thread.equals(message.thread)) {
Log.w("Updating after thread from " + message.thread + " to " + thread); Log.w("Updating after thread from " + message.thread + " to " + thread);
db.message().updateMessageThread(message.account, message.thread, thread); db.message().updateMessageThread(message.account, message.thread, thread);
} }

Loading…
Cancel
Save