aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2017-11-21 15:42:46 +0100
committerDaniel Gultsch <daniel@gultsch.de>2017-11-21 15:42:46 +0100
commit381fe82b01a38f7bbfd39c2c991af950839fe2b4 (patch)
tree098e543c273037ae361c230379f2a34ff1884887
parent79ea0713bb8c59d97e6ddaf5a4341d4918f9c8aa (diff)
save full jid when sending in muc. check chat markers against 'sender'
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Conversation.java5
-rw-r--r--src/main/java/eu/siacs/conversations/generator/MessageGenerator.java9
-rw-r--r--src/main/java/eu/siacs/conversations/parser/MessageParser.java5
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java11
4 files changed, 20 insertions, 10 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java
index 44aea69..ce048c6 100644
--- a/src/main/java/eu/siacs/conversations/entities/Conversation.java
+++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java
@@ -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;
}
}
diff --git a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
index 49355b1..d82706a 100644
--- a/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
+++ b/src/main/java/eu/siacs/conversations/generator/MessageGenerator.java
@@ -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;
}
diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
index 0f7c3ce..606fbff 100644
--- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java
@@ -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
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 74472fa..6f34269 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -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);
}
}