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.text.SpannableStringBuilder;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
@ -102,6 +103,7 @@ public class Message extends AbstractEntity {
private Boolean treatAsDownloadable = null;
private FileParams fileParams = null;
private List<MucOptions.User> counterparts;
private WeakReference<MucOptions.User> user;
private Message(Conversation conversation) {
this.conversation = conversation;
@ -313,6 +315,16 @@ public class Message extends AbstractEntity {
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() {
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");
if (conversationMultiMode) {
message.setMucUser(conversation.getMucOptions().findUserByFullJid(message.getCounterpart()));
final Jid fallback = conversation.getMucOptions().getTrueCounterpart(counterpart);
Jid trueCounterpart;
if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
@ -461,8 +462,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
|| replacedMessage.getFingerprint().equals(message.getFingerprint());
final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null
&& 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);
if (fingerprintsMatch && (trueCountersMatch || !conversationMultiMode) && !duplicate) {
if (fingerprintsMatch && (trueCountersMatch || !conversationMultiMode || !mucUserMatches) && !duplicate) {
Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'");
synchronized (replacedMessage) {
final String uuid = replacedMessage.getUuid();