keep track of user object in messages

This commit is contained in:
Daniel Gultsch 2018-04-12 09:50:33 +02:00
parent 7fd25abea2
commit c61be89262
2 changed files with 15 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import android.content.ContentValues;
import android.database.Cursor; import android.database.Cursor;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Collections; import java.util.Collections;
@ -102,6 +103,7 @@ public class Message extends AbstractEntity {
private Boolean treatAsDownloadable = null; private Boolean treatAsDownloadable = null;
private FileParams fileParams = null; private FileParams fileParams = null;
private List<MucOptions.User> counterparts; private List<MucOptions.User> counterparts;
private WeakReference<MucOptions.User> user;
private Message(Conversation conversation) { private Message(Conversation conversation) {
this.conversation = conversation; this.conversation = conversation;
@ -313,6 +315,16 @@ public class Message extends AbstractEntity {
this.fileParams = null; this.fileParams = null;
} }
public void setMucUser(MucOptions.User user) {
this.user = new WeakReference<>(user);
}
public boolean sameMucUser(Message otherMessage) {
final MucOptions.User thisUser = this.user == null ? null : this.user.get();
final MucOptions.User otherUser = otherMessage.user == null ? null : otherMessage.user.get();
return thisUser != null && thisUser == otherUser;
}
public String getErrorMessage() { public String getErrorMessage() {
return errorMessage; return errorMessage;
} }

View File

@ -430,6 +430,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} }
message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0"); message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
if (conversationMultiMode) { if (conversationMultiMode) {
message.setMucUser(conversation.getMucOptions().findUserByFullJid(message.getCounterpart()));
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart); final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
Jid trueCounterpart; Jid trueCounterpart;
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) { if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
@ -461,8 +462,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|| replacedMessage.getFingerprint().equals(message.getFingerprint()); || replacedMessage.getFingerprint().equals(message.getFingerprint());
final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null
&& replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart()); && replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart());
final boolean mucUserMatches = query == null && replacedMessage.sameMucUser(message); //can not be checked when using mam
final boolean duplicate = conversation.hasDuplicateMessage(message); final boolean duplicate = conversation.hasDuplicateMessage(message);
if (fingerprintsMatch && (trueCountersMatch || !conversationMultiMode) && !duplicate) { if (fingerprintsMatch && (trueCountersMatch || !conversationMultiMode || !mucUserMatches) && !duplicate) {
Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'"); Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'");
synchronized (replacedMessage) { synchronized (replacedMessage) {
final String uuid = replacedMessage.getUuid(); final String uuid = replacedMessage.getUuid();