aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2017-11-23 18:19:05 +0100
committerDaniel Gultsch <daniel@gultsch.de>2017-11-23 18:19:05 +0100
commit333e7a6510ccdd6b7575372541c8cb15bb2fb9fe (patch)
tree1867387a9974eb0b772f92a4366808ae5581678e
parent513427c8a8c567b2b90e2f86f9a33ae2252cecb1 (diff)
deduplicate read markers if one with real jid is found
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Message.java18
-rw-r--r--src/main/java/eu/siacs/conversations/entities/ReadByMarker.java2
-rw-r--r--src/main/java/eu/siacs/conversations/utils/UIHelper.java2
3 files changed, 17 insertions, 5 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java
index dcddb3e..fda02c3 100644
--- a/src/main/java/eu/siacs/conversations/entities/Message.java
+++ b/src/main/java/eu/siacs/conversations/entities/Message.java
@@ -12,6 +12,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -433,16 +434,27 @@ public class Message extends AbstractEntity {
public boolean addReadByMarker(ReadByMarker readByMarker) {
if (readByMarker.getRealJid() != null) {
if (readByMarker.getRealJid().toBareJid().equals(trueCounterpart)) {
- Log.d(Config.LOGTAG,"trying to add read marker by "+readByMarker.getRealJid()+" to "+body);
return false;
}
} else if (readByMarker.getFullJid() != null) {
if (readByMarker.getFullJid().equals(counterpart)) {
- Log.d(Config.LOGTAG,"trying to add read marker by "+readByMarker.getFullJid()+" to "+body);
return false;
}
}
- return this.readByMarkers.add(readByMarker);
+ if (this.readByMarkers.add(readByMarker)) {
+ if (readByMarker.getRealJid() != null && readByMarker.getFullJid() != null) {
+ Iterator<ReadByMarker> iterator = this.readByMarkers.iterator();
+ while (iterator.hasNext()) {
+ ReadByMarker marker = iterator.next();
+ if (marker.getRealJid() == null && readByMarker.getFullJid().equals(marker.getFullJid())) {
+ iterator.remove();
+ }
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
}
public Set<ReadByMarker> getReadByMarkers() {
diff --git a/src/main/java/eu/siacs/conversations/entities/ReadByMarker.java b/src/main/java/eu/siacs/conversations/entities/ReadByMarker.java
index 6767212..1a1c5ff 100644
--- a/src/main/java/eu/siacs/conversations/entities/ReadByMarker.java
+++ b/src/main/java/eu/siacs/conversations/entities/ReadByMarker.java
@@ -82,7 +82,7 @@ public class ReadByMarker {
public static ReadByMarker from(Jid fullJid, Jid realJid) {
final ReadByMarker marker = new ReadByMarker();
marker.fullJid = fullJid;
- marker.realJid = realJid;
+ marker.realJid = realJid == null ? null : realJid.toBareJid();
return marker;
}
diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
index 5d648c1..b24b809 100644
--- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java
@@ -375,7 +375,7 @@ public class UIHelper {
if (builder.length() != 0) {
builder.append(", ");
}
- final String name = UIHelper.getDisplayName(users.get(0));
+ final String name = UIHelper.getDisplayName(users.get(i));
builder.append(shortNames ? name.split("\\s+")[0] : name);
}
return builder.toString();