don't parse body from muc status messages

This commit is contained in:
Daniel Gultsch 2015-06-28 22:14:40 +02:00
parent 46595b6d43
commit 0d01e51da5

View file

@ -233,13 +233,15 @@ public class MessageParser extends AbstractParser implements
} }
final String body = packet.getBody(); final String body = packet.getBody();
final String encrypted = packet.findChildContent("x", "jabber:x:encrypted"); final String encrypted = packet.findChildContent("x", "jabber:x:encrypted");
final Element mucUserElement = packet.findChild("x","http://jabber.org/protocol/muc#user");
int status; int status;
final Jid counterpart; final Jid counterpart;
final Jid to = packet.getTo(); final Jid to = packet.getTo();
final Jid from = packet.getFrom(); final Jid from = packet.getFrom();
final String remoteMsgId = packet.getId(); final String remoteMsgId = packet.getId();
boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT; boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT;
boolean properlyAddressed = !to.isBareJid() || account.countPresences() == 1; boolean isProperlyAddressed = !to.isBareJid() || account.countPresences() == 1;
boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status");
if (packet.fromAccount(account)) { if (packet.fromAccount(account)) {
status = Message.STATUS_SEND; status = Message.STATUS_SEND;
counterpart = to; counterpart = to;
@ -262,7 +264,7 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
} }
if (body != null || encrypted != null) { if ((body != null || encrypted != null) && !isMucStatusMessage) {
Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat); Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat);
if (isTypeGroupChat) { if (isTypeGroupChat) {
if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) { if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
@ -283,7 +285,7 @@ public class MessageParser extends AbstractParser implements
} }
Message message; Message message;
if (body != null && body.startsWith("?OTR")) { if (body != null && body.startsWith("?OTR")) {
if (!isForwarded && !isTypeGroupChat && properlyAddressed) { if (!isForwarded && !isTypeGroupChat && isProperlyAddressed) {
message = parseOtrChat(body, from, remoteMsgId, conversation); message = parseOtrChat(body, from, remoteMsgId, conversation);
if (message == null) { if (message == null) {
return; return;
@ -375,9 +377,8 @@ public class MessageParser extends AbstractParser implements
} }
} }
final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user"); if (conversation != null && isMucStatusMessage) {
if (conversation != null && x != null && from.isBareJid()) { for (Element child : mucUserElement.getChildren()) {
for (Element child : x.getChildren()) {
if (child.getName().equals("status") if (child.getName().equals("status")
&& MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED.equals(child.getAttribute("code"))) { && MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED.equals(child.getAttribute("code"))) {
mXmppConnectionService.fetchConferenceConfiguration(conversation); mXmppConnectionService.fetchConferenceConfiguration(conversation);