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; return null;
} }
public Message findMessageWithRemoteId(String id) { public Message findMessageWithRemoteId(String id, Jid counterpart) {
synchronized (this.messages) { synchronized (this.messages) {
for(Message message : 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; return message;
} }
} }

View File

@ -173,13 +173,16 @@ public class MessageGenerator extends AbstractGenerator {
return packet; 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(); MessagePacket packet = new MessagePacket();
packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT); packet.setType(groupChat ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
packet.setTo(groupChat ? to.toBareJid() : to); packet.setTo(groupChat ? to.toBareJid() : to);
packet.setFrom(account.getJid()); packet.setFrom(account.getJid());
Element received = packet.addChild("displayed","urn:xmpp:chat-markers:0"); Element displayed = packet.addChild("displayed","urn:xmpp:chat-markers:0");
received.setAttribute("id", id); displayed.setAttribute("id", id);
if (groupChat && counterpart != null) {
displayed.setAttribute("sender",counterpart.toPreppedString());
}
packet.addChild("store", "urn:xmpp:hints"); packet.addChild("store", "urn:xmpp:hints");
return packet; 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"); Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0");
if (displayed != null) { if (displayed != null) {
final String id = displayed.getAttribute("id"); final String id = displayed.getAttribute("id");
final Jid sender = displayed.getAttributeAsJid("sender");
if (packet.fromAccount(account)) { if (packet.fromAccount(account)) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
if (conversation != null && (query == null || query.isCatchup())) { if (conversation != null && (query == null || query.isCatchup())) {
@ -708,8 +709,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} }
} else if (isTypeGroupChat) { } else if (isTypeGroupChat) {
Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid()); Conversation conversation = mXmppConnectionService.find(account, counterpart.toBareJid());
if (conversation != null && id != null) { if (conversation != null && id != null && sender != null) {
Message message = conversation.findMessageWithRemoteId(id); Message message = conversation.findMessageWithRemoteId(id, sender);
if (message != null) { if (message != null) {
if (conversation.getMucOptions().isSelf(counterpart)) { if (conversation.getMucOptions().isSelf(counterpart)) {
if (!message.isRead() && (query == null || query.isCatchup())) { //checking if message is unread fixes race conditions with reflections 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 (resend) {
if (packet != null && addToConversation) { if (packet != null && addToConversation) {
if (account.getXmppConnection().getFeatures().sm() if (account.getXmppConnection().getFeatures().sm() || mucMessage) {
|| (conversation.getMode() == Conversation.MODE_MULTI && message.getCounterpart().isBareJid())) {
markMessage(message, Message.STATUS_UNSEND); markMessage(message, Message.STATUS_UNSEND);
} else { } else {
markMessage(message, Message.STATUS_SEND); markMessage(message, Message.STATUS_SEND);
@ -3400,7 +3405,7 @@ public class XmppConnectionService extends Service {
Account account = conversation.getAccount(); Account account = conversation.getAccount();
final Jid to = markable.getCounterpart(); final Jid to = markable.getCounterpart();
final boolean groupChat = conversation.getMode() == Conversation.MODE_MULTI; 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); this.sendMessagePacket(conversation.getAccount(), packet);
} }
} }