Improved duplicate marking

pull/147/head
M66B 6 years ago
parent dc8c09baf0
commit 0a84a6c6f8

@ -54,7 +54,6 @@ public interface DaoMessage {
", " + unflagged_unified + " AS unflagged" +
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", SUM(CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END) AS drafts" +
", 0 AS duplicate" +
", COUNT(DISTINCT message.msgid) AS visible" +
", MAX(CASE WHEN :found OR folder.unified THEN message.received ELSE 0 END) AS dummy" +
" FROM message" +
@ -95,7 +94,6 @@ public interface DaoMessage {
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", SUM(CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END) AS drafts" +
", COUNT(DISTINCT message.msgid) AS visible" +
", 0 AS duplicate" +
", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" +
" FROM message" +
" JOIN account ON account.id = message.account" +
@ -127,17 +125,6 @@ public interface DaoMessage {
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END AS drafts" +
", 1 AS visible" +
", (folder.type = '" + EntityFolder.ARCHIVE + "'" +
" AND EXISTS (" +
" SELECT * FROM message m1" +
" JOIN folder f1 ON f1.id = m1.folder" +
" WHERE m1.id <> message.id" +
" AND m1.msgid = message.msgid" +
" AND f1.type <> folder.type" +
" AND f1.type <> '" + EntityFolder.ARCHIVE + "'" +
" )) AS duplicate" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +
@ -220,7 +207,6 @@ public interface DaoMessage {
", (SELECT COUNT(a.id) FROM attachment a WHERE a.message = message.id) AS attachments" +
", CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END AS drafts" +
", 1 AS visible" +
", 0 AS duplicate" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +
@ -237,7 +223,6 @@ public interface DaoMessage {
", 0 AS attachments" +
", 0 AS drafts" +
", 1 AS visible" +
", 0 AS duplicate" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +

@ -57,6 +57,7 @@ import com.google.android.material.snackbar.Snackbar;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
@ -1839,6 +1840,42 @@ public class FragmentMessages extends FragmentBase {
}
if (viewType == AdapterMessage.ViewType.THREAD) {
// Mark duplicates
Map<String, List<TupleMessageEx>> duplicates = new HashMap<>();
for (TupleMessageEx message : messages)
if (message != null && message.msgid != null) {
if (!duplicates.containsKey(message.msgid))
duplicates.put(message.msgid, new ArrayList<TupleMessageEx>());
duplicates.get(message.msgid).add(message);
}
for (String msgid : duplicates.keySet()) {
List<TupleMessageEx> dups = duplicates.get(msgid);
if (dups.size() > 1) {
Collections.sort(dups, new Comparator<TupleMessageEx>() {
final List<String> ORDER = Arrays.asList(
EntityFolder.INBOX,
EntityFolder.OUTBOX,
EntityFolder.DRAFTS,
EntityFolder.SENT,
EntityFolder.TRASH,
EntityFolder.JUNK,
EntityFolder.SYSTEM,
EntityFolder.USER,
EntityFolder.ARCHIVE
);
@Override
public int compare(TupleMessageEx d1, TupleMessageEx d2) {
int o1 = ORDER.indexOf(d1.folderType);
int o2 = ORDER.indexOf(d2.folderType);
return ((Integer) o1).compareTo(o2);
}
});
for (int i = 1; i < dups.size(); i++)
dups.get(i).duplicate = true;
}
}
if (autoExpand) {
autoExpand = false;
@ -1855,6 +1892,9 @@ public class FragmentMessages extends FragmentBase {
TupleMessageEx single = null;
TupleMessageEx see = null;
for (TupleMessageEx message : messages) {
if (message == null)
continue;
if (!message.duplicate &&
!EntityFolder.DRAFTS.equals(message.folderType) &&
!EntityFolder.TRASH.equals(message.folderType)) {
@ -1898,7 +1938,8 @@ public class FragmentMessages extends FragmentBase {
int count = 0;
for (int i = 0; i < messages.size(); i++) {
TupleMessageEx message = messages.get(i);
if (!EntityFolder.ARCHIVE.equals(message.folderType) &&
if (message != null &&
!EntityFolder.ARCHIVE.equals(message.folderType) &&
!EntityFolder.SENT.equals(message.folderType) &&
!EntityFolder.TRASH.equals(message.folderType) &&
!EntityFolder.JUNK.equals(message.folderType))

@ -19,6 +19,8 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import androidx.room.Ignore;
public class TupleMessageEx extends EntityMessage {
public String accountName;
public Integer accountColor;
@ -32,6 +34,7 @@ public class TupleMessageEx extends EntityMessage {
public int attachments;
public int drafts;
public int visible;
@Ignore
public boolean duplicate;
@Override

Loading…
Cancel
Save