save full jid when sending in muc. check chat markers against 'sender'

This commit is contained in:
Daniel Gultsch 2017-11-21 15:42:46 +01:00
parent 79ea0713bb
commit 381fe82b01
4 changed files with 20 additions and 10 deletions

View File

@ -289,10 +289,11 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl
return null;
}
public Message findMessageWithRemoteId(String id) {
public Message findMessageWithRemoteId(String id, Jid counterpart) {
synchronized (this.messages) {
for(Message message : this.messages) {
if (id.equals(message.getRemoteMsgId()) || id.equals(message.getUuid())) {
if (counterpart.equals(message.getCounterpart())
&& (id.equals(message.getRemoteMsgId()) || id.equals(message.getUuid()))) {
return message;
}
}

View File

@ -173,13 +173,16 @@ public class MessageGenerator extends AbstractGenerator {
return packet;
}
public MessagePacket confirm(final Account account, final Jid to, final String id, final boolean groupChat) {
public MessagePacket confirm(final Account account, final Jid to, final String id, final Jid counterpart, final boolean groupChat) {
MessagePacket packet = new MessagePacket();
packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
packet.setTo(groupChat ? to.toBareJid() : to);
packet.setFrom(account.getJid());
Element received = packet.addChild("displayed","urn:xmpp:chat-markers:0");
received.setAttribute("id", id);
Element displayed = packet.addChild("displayed","urn:xmpp:chat-markers:0");
displayed.setAttribute("id", id);
if (groupChat && counterpart != null) {
displayed.setAttribute("sender",counterpart.toPreppedString());
}
packet.addChild("store", "urn:xmpp:hints");
return packet;
}

View File

@ -701,6 +701,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0");
if (displayed != null) {
final String id = displayed.getAttribute("id");
final Jid sender = displayed.getAttributeAsJid("sender");
if (packet.fromAccount(account)) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
if (conversation != null && (query == null || query.isCatchup())) {
@ -708,8 +709,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
}
} else if (isTypeGroupChat) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
if (conversation != null && id != null) {
Message message = conversation.findMessageWithRemoteId(id);
if (conversation != null && id != null && sender != null) {
Message message = conversation.findMessageWithRemoteId(id, sender);
if (message != null) {
if (conversation.getMucOptions().isSelf(counterpart)) {
if (!message.isRead() && (query == null || query.isCatchup())) { //checking if message is unread fixes race conditions with reflections

View File

@ -1278,10 +1278,15 @@ public class XmppConnectionService extends Service {
}
}
boolean mucMessage = conversation.getMode() == Conversation.MODE_MULTI && message.getType() != Message.TYPE_PRIVATE;
if (mucMessage) {
message.setCounterpart(conversation.getMucOptions().getSelf().getFullJid());
}
if (resend) {
if (packet != null && addToConversation) {
if (account.getXmppConnection().getFeatures().sm()
|| (conversation.getMode() == Conversation.MODE_MULTI && message.getCounterpart().isBareJid())) {
if (account.getXmppConnection().getFeatures().sm() || mucMessage) {
markMessage(message, Message.STATUS_UNSEND);
} else {
markMessage(message, Message.STATUS_SEND);
@ -3400,7 +3405,7 @@ public class XmppConnectionService extends Service {
Account account = conversation.getAccount();
final Jid to = markable.getCounterpart();
final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI;
MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId(), groupChat);
MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId(), markable.getCounterpart(), groupChat);
this.sendMessagePacket(conversation.getAccount(), packet);
}
}