1package eu.siacs.conversations.parser;
2
3import android.util.Log;
4import android.util.Pair;
5
6import net.java.otr4j.session.Session;
7import net.java.otr4j.session.SessionStatus;
8
9import java.util.ArrayList;
10import java.util.Set;
11import java.util.UUID;
12
13import eu.siacs.conversations.Config;
14import eu.siacs.conversations.crypto.OtrService;
15import eu.siacs.conversations.crypto.axolotl.AxolotlService;
16import eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage;
17import eu.siacs.conversations.entities.Account;
18import eu.siacs.conversations.entities.Bookmark;
19import eu.siacs.conversations.entities.Contact;
20import eu.siacs.conversations.entities.Conversation;
21import eu.siacs.conversations.entities.Message;
22import eu.siacs.conversations.entities.MucOptions;
23import eu.siacs.conversations.http.HttpConnectionManager;
24import eu.siacs.conversations.services.MessageArchiveService;
25import eu.siacs.conversations.services.XmppConnectionService;
26import eu.siacs.conversations.utils.CryptoHelper;
27import eu.siacs.conversations.xml.Element;
28import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
29import eu.siacs.conversations.xmpp.chatstate.ChatState;
30import eu.siacs.conversations.xmpp.jid.Jid;
31import eu.siacs.conversations.xmpp.pep.Avatar;
32import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
33
34public class MessageParser extends AbstractParser implements
35 OnMessagePacketReceived {
36 public MessageParser(XmppConnectionService service) {
37 super(service);
38 }
39
40 private boolean extractChatState(Conversation conversation, final MessagePacket packet) {
41 ChatState state = ChatState.parse(packet);
42 if (state != null && conversation != null) {
43 final Account account = conversation.getAccount();
44 Jid from = packet.getFrom();
45 if (from.toBareJid().equals(account.getJid().toBareJid())) {
46 conversation.setOutgoingChatState(state);
47 if (state == ChatState.ACTIVE || state == ChatState.COMPOSING) {
48 mXmppConnectionService.markRead(conversation);
49 account.activateGracePeriod();
50 }
51 return false;
52 } else {
53 return conversation.setIncomingChatState(state);
54 }
55 }
56 return false;
57 }
58
59 private Message parseOtrChat(String body, Jid from, String id, Conversation conversation) {
60 String presence;
61 if (from.isBareJid()) {
62 presence = "";
63 } else {
64 presence = from.getResourcepart();
65 }
66 if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {
67 conversation.endOtrIfNeeded();
68 }
69 if (!conversation.hasValidOtrSession()) {
70 conversation.startOtrSession(presence,false);
71 } else {
72 String foreignPresence = conversation.getOtrSession().getSessionID().getUserID();
73 if (!foreignPresence.equals(presence)) {
74 conversation.endOtrIfNeeded();
75 conversation.startOtrSession(presence, false);
76 }
77 }
78 try {
79 conversation.setLastReceivedOtrMessageId(id);
80 Session otrSession = conversation.getOtrSession();
81 body = otrSession.transformReceiving(body);
82 SessionStatus status = otrSession.getSessionStatus();
83 if (body == null && status == SessionStatus.ENCRYPTED) {
84 mXmppConnectionService.onOtrSessionEstablished(conversation);
85 return null;
86 } else if (body == null && status == SessionStatus.FINISHED) {
87 conversation.resetOtrSession();
88 mXmppConnectionService.updateConversationUi();
89 return null;
90 } else if (body == null || (body.isEmpty())) {
91 return null;
92 }
93 if (body.startsWith(CryptoHelper.FILETRANSFER)) {
94 String key = body.substring(CryptoHelper.FILETRANSFER.length());
95 conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
96 return null;
97 }
98 final OtrService otrService = conversation.getAccount().getOtrService();
99 Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR, Message.STATUS_RECEIVED);
100 finishedMessage.setFingerprint(otrService.getFingerprint(otrSession.getRemotePublicKey()));
101 conversation.setLastReceivedOtrMessageId(null);
102
103 return finishedMessage;
104 } catch (Exception e) {
105 conversation.resetOtrSession();
106 return null;
107 }
108 }
109
110 private Message parseAxolotlChat(Element axolotlMessage, Jid from, Conversation conversation, int status) {
111 Message finishedMessage = null;
112 AxolotlService service = conversation.getAccount().getAxolotlService();
113 XmppAxolotlMessage xmppAxolotlMessage = XmppAxolotlMessage.fromElement(axolotlMessage, from.toBareJid());
114 XmppAxolotlMessage.XmppAxolotlPlaintextMessage plaintextMessage = service.processReceivingPayloadMessage(xmppAxolotlMessage);
115 if(plaintextMessage != null) {
116 finishedMessage = new Message(conversation, plaintextMessage.getPlaintext(), Message.ENCRYPTION_AXOLOTL, status);
117 finishedMessage.setFingerprint(plaintextMessage.getFingerprint());
118 Log.d(Config.LOGTAG, AxolotlService.getLogprefix(finishedMessage.getConversation().getAccount())+" Received Message with session fingerprint: "+plaintextMessage.getFingerprint());
119 }
120
121 return finishedMessage;
122 }
123
124 private class Invite {
125 Jid jid;
126 String password;
127 Invite(Jid jid, String password) {
128 this.jid = jid;
129 this.password = password;
130 }
131
132 public boolean execute(Account account) {
133 if (jid != null) {
134 Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid, true);
135 if (!conversation.getMucOptions().online()) {
136 conversation.getMucOptions().setPassword(password);
137 mXmppConnectionService.databaseBackend.updateConversation(conversation);
138 mXmppConnectionService.joinMuc(conversation);
139 mXmppConnectionService.updateConversationUi();
140 }
141 return true;
142 }
143 return false;
144 }
145 }
146
147 private Invite extractInvite(Element message) {
148 Element x = message.findChild("x", "http://jabber.org/protocol/muc#user");
149 if (x != null) {
150 Element invite = x.findChild("invite");
151 if (invite != null) {
152 Element pw = x.findChild("password");
153 return new Invite(message.getAttributeAsJid("from"), pw != null ? pw.getContent(): null);
154 }
155 } else {
156 x = message.findChild("x","jabber:x:conference");
157 if (x != null) {
158 return new Invite(x.getAttributeAsJid("jid"),x.getAttribute("password"));
159 }
160 }
161 return null;
162 }
163
164 private static String extractStanzaId(Element packet, Jid by) {
165 for(Element child : packet.getChildren()) {
166 if (child.getName().equals("stanza-id")
167 && "urn:xmpp:sid:0".equals(child.getNamespace())
168 && by.equals(child.getAttributeAsJid("by"))) {
169 return child.getAttribute("id");
170 }
171 }
172 return null;
173 }
174
175 private void parseEvent(final Element event, final Jid from, final Account account) {
176 Element items = event.findChild("items");
177 String node = items == null ? null : items.getAttribute("node");
178 if ("urn:xmpp:avatar:metadata".equals(node)) {
179 Avatar avatar = Avatar.parseMetadata(items);
180 if (avatar != null) {
181 avatar.owner = from.toBareJid();
182 if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
183 if (account.getJid().toBareJid().equals(from)) {
184 if (account.setAvatar(avatar.getFilename())) {
185 mXmppConnectionService.databaseBackend.updateAccount(account);
186 }
187 mXmppConnectionService.getAvatarService().clear(account);
188 mXmppConnectionService.updateConversationUi();
189 mXmppConnectionService.updateAccountUi();
190 } else {
191 Contact contact = account.getRoster().getContact(from);
192 contact.setAvatar(avatar);
193 mXmppConnectionService.getAvatarService().clear(contact);
194 mXmppConnectionService.updateConversationUi();
195 mXmppConnectionService.updateRosterUi();
196 }
197 } else {
198 mXmppConnectionService.fetchAvatar(account, avatar);
199 }
200 }
201 } else if ("http://jabber.org/protocol/nick".equals(node)) {
202 Element i = items.findChild("item");
203 Element nick = i == null ? null : i.findChild("nick", "http://jabber.org/protocol/nick");
204 if (nick != null && nick.getContent() != null) {
205 Contact contact = account.getRoster().getContact(from);
206 contact.setPresenceName(nick.getContent());
207 mXmppConnectionService.getAvatarService().clear(account);
208 mXmppConnectionService.updateConversationUi();
209 mXmppConnectionService.updateAccountUi();
210 }
211 } else if (AxolotlService.PEP_DEVICE_LIST.equals(node)) {
212 Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account)+"Received PEP device list update from "+ from + ", processing...");
213 Element item = items.findChild("item");
214 Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
215 AxolotlService axolotlService = account.getAxolotlService();
216 axolotlService.registerDevices(from, deviceIds);
217 mXmppConnectionService.updateAccountUi();
218 }
219 }
220
221 private boolean handleErrorMessage(Account account, MessagePacket packet) {
222 if (packet.getType() == MessagePacket.TYPE_ERROR) {
223 Jid from = packet.getFrom();
224 if (from != null) {
225 Element error = packet.findChild("error");
226 String text = error == null ? null : error.findChildContent("text");
227 if (text != null) {
228 Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending message to "+ from+ " failed - " + text);
229 } else if (error != null) {
230 Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending message to "+ from+ " failed - " + error);
231 }
232 Message message = mXmppConnectionService.markMessage(account,
233 from.toBareJid(),
234 packet.getId(),
235 Message.STATUS_SEND_FAILED);
236 if (message != null && message.getEncryption() == Message.ENCRYPTION_OTR) {
237 message.getConversation().endOtrIfNeeded();
238 }
239 }
240 return true;
241 }
242 return false;
243 }
244
245 @Override
246 public void onMessagePacketReceived(Account account, MessagePacket original) {
247 if (handleErrorMessage(account, original)) {
248 return;
249 }
250 final MessagePacket packet;
251 Long timestamp = null;
252 final boolean isForwarded;
253 boolean isCarbon = false;
254 String serverMsgId = null;
255 final Element fin = original.findChild("fin", "urn:xmpp:mam:0");
256 if (fin != null) {
257 mXmppConnectionService.getMessageArchiveService().processFin(fin,original.getFrom());
258 return;
259 }
260 final Element result = original.findChild("result","urn:xmpp:mam:0");
261 final MessageArchiveService.Query query = result == null ? null : mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid"));
262 if (query != null && query.validFrom(original.getFrom())) {
263 Pair<MessagePacket, Long> f = original.getForwardedMessagePacket("result", "urn:xmpp:mam:0");
264 if (f == null) {
265 return;
266 }
267 timestamp = f.second;
268 packet = f.first;
269 isForwarded = true;
270 serverMsgId = result.getAttribute("id");
271 query.incrementMessageCount();
272 } else if (query != null) {
273 Log.d(Config.LOGTAG,account.getJid().toBareJid()+": received mam result from invalid sender");
274 return;
275 } else if (original.fromServer(account)) {
276 Pair<MessagePacket, Long> f;
277 f = original.getForwardedMessagePacket("received", "urn:xmpp:carbons:2");
278 f = f == null ? original.getForwardedMessagePacket("sent", "urn:xmpp:carbons:2") : f;
279 packet = f != null ? f.first : original;
280 if (handleErrorMessage(account, packet)) {
281 return;
282 }
283 timestamp = f != null ? f.second : null;
284 isCarbon = f != null;
285 isForwarded = isCarbon;
286 } else {
287 packet = original;
288 isForwarded = false;
289 }
290
291 if (timestamp == null) {
292 timestamp = AbstractParser.getTimestamp(packet, System.currentTimeMillis());
293 }
294 final String body = packet.getBody();
295 final Element mucUserElement = packet.findChild("x", "http://jabber.org/protocol/muc#user");
296 final String pgpEncrypted = packet.findChildContent("x", "jabber:x:encrypted");
297 final Element replaceElement = packet.findChild("replace", "urn:xmpp:message-correct:0");
298 final Element oob = packet.findChild("x", "jabber:x:oob");
299 final boolean isOob = oob!= null && body != null && body.equals(oob.findChildContent("url"));
300 final String replacementId = replaceElement == null ? null : replaceElement.getAttribute("id");
301 final Element axolotlEncrypted = packet.findChild(XmppAxolotlMessage.CONTAINERTAG, AxolotlService.PEP_PREFIX);
302 int status;
303 final Jid counterpart;
304 final Jid to = packet.getTo();
305 final Jid from = packet.getFrom();
306 final String remoteMsgId = packet.getId();
307
308 if (from == null) {
309 Log.d(Config.LOGTAG,"no from in: "+packet.toString());
310 return;
311 }
312
313 boolean isTypeGroupChat = packet.getType() == MessagePacket.TYPE_GROUPCHAT;
314 boolean isProperlyAddressed = (to != null ) && (!to.isBareJid() || account.countPresences() <= 1);
315 boolean isMucStatusMessage = from.isBareJid() && mucUserElement != null && mucUserElement.hasChild("status");
316 if (packet.fromAccount(account)) {
317 status = Message.STATUS_SEND;
318 counterpart = to != null ? to : account.getJid();
319 } else {
320 status = Message.STATUS_RECEIVED;
321 counterpart = from;
322 }
323
324 Invite invite = extractInvite(packet);
325 if (invite != null && invite.execute(account)) {
326 return;
327 }
328
329 if (extractChatState(mXmppConnectionService.find(account, counterpart.toBareJid()), packet)) {
330 mXmppConnectionService.updateConversationUi();
331 }
332
333 if ((body != null || pgpEncrypted != null || axolotlEncrypted != null) && !isMucStatusMessage) {
334 Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, counterpart.toBareJid(), isTypeGroupChat, query);
335 if (isTypeGroupChat) {
336 if (counterpart.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
337 status = Message.STATUS_SEND_RECEIVED;
338 isCarbon = true; //not really carbon but received from another resource
339 if (mXmppConnectionService.markMessage(conversation, remoteMsgId, status)) {
340 return;
341 } else if (remoteMsgId == null || Config.IGNORE_ID_REWRITE_IN_MUC) {
342 Message message = conversation.findSentMessageWithBody(packet.getBody());
343 if (message != null) {
344 mXmppConnectionService.markMessage(message, status);
345 return;
346 }
347 }
348 } else {
349 status = Message.STATUS_RECEIVED;
350 }
351 }
352 Message message;
353 if (body != null && body.startsWith("?OTR") && Config.supportOtr()) {
354 if (!isForwarded && !isTypeGroupChat && isProperlyAddressed) {
355 message = parseOtrChat(body, from, remoteMsgId, conversation);
356 if (message == null) {
357 return;
358 }
359 } else {
360 Log.d(Config.LOGTAG,account.getJid().toBareJid()+": ignoring OTR message from "+from+" isForwarded="+Boolean.toString(isForwarded)+", isProperlyAddressed="+Boolean.valueOf(isProperlyAddressed));
361 message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
362 }
363 } else if (pgpEncrypted != null && Config.supportOpenPgp()) {
364 message = new Message(conversation, pgpEncrypted, Message.ENCRYPTION_PGP, status);
365 } else if (axolotlEncrypted != null && Config.supportOmemo()) {
366 Jid origin;
367 if (conversation.getMode() == Conversation.MODE_MULTI) {
368 origin = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
369 if (origin == null) {
370 Log.d(Config.LOGTAG,"axolotl message in non anonymous conference received");
371 return;
372 }
373 } else {
374 origin = from;
375 }
376 message = parseAxolotlChat(axolotlEncrypted, origin, conversation, status);
377 if (message == null) {
378 return;
379 }
380 } else {
381 message = new Message(conversation, body, Message.ENCRYPTION_NONE, status);
382 }
383
384 if (serverMsgId == null) {
385 serverMsgId = extractStanzaId(packet, isTypeGroupChat ? conversation.getJid().toBareJid() : account.getServer());
386 }
387
388 message.setCounterpart(counterpart);
389 message.setRemoteMsgId(remoteMsgId);
390 message.setServerMsgId(serverMsgId);
391 message.setCarbon(isCarbon);
392 message.setTime(timestamp);
393 message.setOob(isOob);
394 message.markable = packet.hasChild("markable", "urn:xmpp:chat-markers:0");
395 if (conversation.getMode() == Conversation.MODE_MULTI) {
396 Jid trueCounterpart = conversation.getMucOptions().getTrueCounterpart(counterpart.getResourcepart());
397 message.setTrueCounterpart(trueCounterpart);
398 if (trueCounterpart != null) {
399 updateLastseen(timestamp, account, trueCounterpart, false);
400 }
401 if (!isTypeGroupChat) {
402 message.setType(Message.TYPE_PRIVATE);
403 }
404 } else {
405 updateLastseen(timestamp, account, packet.getFrom(), true);
406 }
407
408 if (replacementId != null && mXmppConnectionService.allowMessageCorrection()) {
409 Message replacedMessage = conversation.findMessageWithRemoteIdAndCounterpart(replacementId,
410 counterpart,
411 message.getStatus() == Message.STATUS_RECEIVED,
412 message.isCarbon());
413 if (replacedMessage != null) {
414 final boolean fingerprintsMatch = replacedMessage.getFingerprint() == null
415 || replacedMessage.getFingerprint().equals(message.getFingerprint());
416 final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null
417 && replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart());
418 if (fingerprintsMatch && (trueCountersMatch || conversation.getMode() == Conversation.MODE_SINGLE)) {
419 Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'");
420 final String uuid = replacedMessage.getUuid();
421 replacedMessage.setUuid(UUID.randomUUID().toString());
422 replacedMessage.setBody(message.getBody());
423 replacedMessage.setEdited(replacedMessage.getRemoteMsgId());
424 replacedMessage.setRemoteMsgId(remoteMsgId);
425 replacedMessage.setEncryption(message.getEncryption());
426 if (replacedMessage.getStatus() == Message.STATUS_RECEIVED) {
427 replacedMessage.markUnread();
428 }
429 mXmppConnectionService.updateMessage(replacedMessage, uuid);
430 mXmppConnectionService.getNotificationService().updateNotification(false);
431 if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
432 sendMessageReceipts(account, packet);
433 }
434 if (replacedMessage.getEncryption() == Message.ENCRYPTION_PGP) {
435 conversation.getAccount().getPgpDecryptionService().add(replacedMessage);
436 }
437 return;
438 } else {
439 Log.d(Config.LOGTAG,account.getJid().toBareJid()+": received message correction but verification didn't check out");
440 }
441 }
442 }
443
444 boolean checkForDuplicates = query != null
445 || (isTypeGroupChat && packet.hasChild("delay","urn:xmpp:delay"))
446 || message.getType() == Message.TYPE_PRIVATE;
447 if (checkForDuplicates && conversation.hasDuplicateMessage(message)) {
448 Log.d(Config.LOGTAG,"skipping duplicate message from "+message.getCounterpart().toString()+" "+message.getBody());
449 return;
450 }
451
452 if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
453 conversation.prepend(message);
454 } else {
455 conversation.add(message);
456 }
457
458 if (message.getEncryption() == Message.ENCRYPTION_PGP) {
459 conversation.getAccount().getPgpDecryptionService().add(message);
460 }
461
462 if (query == null || query.getWith() == null) { //either no mam or catchup
463 if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) {
464 mXmppConnectionService.markRead(conversation);
465 if (query == null) {
466 account.activateGracePeriod();
467 }
468 } else {
469 message.markUnread();
470 }
471 }
472
473 if (query == null) {
474 mXmppConnectionService.updateConversationUi();
475 }
476
477 if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
478 sendMessageReceipts(account, packet);
479 }
480
481 if (message.getStatus() == Message.STATUS_RECEIVED
482 && conversation.getOtrSession() != null
483 && !conversation.getOtrSession().getSessionID().getUserID()
484 .equals(message.getCounterpart().getResourcepart())) {
485 conversation.endOtrIfNeeded();
486 }
487
488 if (message.getEncryption() == Message.ENCRYPTION_NONE || mXmppConnectionService.saveEncryptedMessages()) {
489 mXmppConnectionService.databaseBackend.createMessage(message);
490 }
491 final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
492 if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
493 manager.createNewDownloadConnection(message);
494 } else if (!message.isRead()) {
495 if (query == null) {
496 mXmppConnectionService.getNotificationService().push(message);
497 } else if (query.getWith() == null) { // mam catchup
498 mXmppConnectionService.getNotificationService().pushFromBacklog(message);
499 }
500 }
501 } else if (!packet.hasChild("body")){ //no body
502 if (isTypeGroupChat) {
503 Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
504 if (packet.hasChild("subject")) {
505 if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
506 conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0);
507 String subject = packet.findChildContent("subject");
508 conversation.getMucOptions().setSubject(subject);
509 final Bookmark bookmark = conversation.getBookmark();
510 if (bookmark != null && bookmark.getBookmarkName() == null) {
511 if (bookmark.setBookmarkName(subject)) {
512 mXmppConnectionService.pushBookmarks(account);
513 }
514 }
515 mXmppConnectionService.updateConversationUi();
516 return;
517 }
518 }
519
520 if (conversation != null && isMucStatusMessage) {
521 for (Element child : mucUserElement.getChildren()) {
522 if (child.getName().equals("status")
523 && MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED.equals(child.getAttribute("code"))) {
524 mXmppConnectionService.fetchConferenceConfiguration(conversation);
525 }
526 }
527 }
528 }
529 }
530
531 Element received = packet.findChild("received", "urn:xmpp:chat-markers:0");
532 if (received == null) {
533 received = packet.findChild("received", "urn:xmpp:receipts");
534 }
535 if (received != null && !packet.fromAccount(account)) {
536 mXmppConnectionService.markMessage(account, from.toBareJid(), received.getAttribute("id"), Message.STATUS_SEND_RECEIVED);
537 }
538 Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0");
539 if (displayed != null) {
540 if (packet.fromAccount(account)) {
541 Conversation conversation = mXmppConnectionService.find(account,counterpart.toBareJid());
542 if (conversation != null) {
543 mXmppConnectionService.markRead(conversation);
544 }
545 } else {
546 updateLastseen(timestamp, account, packet.getFrom(), true);
547 final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), displayed.getAttribute("id"), Message.STATUS_SEND_DISPLAYED);
548 Message message = displayedMessage == null ? null : displayedMessage.prev();
549 while (message != null
550 && message.getStatus() == Message.STATUS_SEND_RECEIVED
551 && message.getTimeSent() < displayedMessage.getTimeSent()) {
552 mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED);
553 message = message.prev();
554 }
555 }
556 }
557
558 Element event = packet.findChild("event", "http://jabber.org/protocol/pubsub#event");
559 if (event != null) {
560 parseEvent(event, from, account);
561 }
562
563 String nick = packet.findChildContent("nick", "http://jabber.org/protocol/nick");
564 if (nick != null) {
565 Contact contact = account.getRoster().getContact(from);
566 contact.setPresenceName(nick);
567 }
568 }
569
570 private void sendMessageReceipts(Account account, MessagePacket packet) {
571 ArrayList<String> receiptsNamespaces = new ArrayList<>();
572 if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
573 receiptsNamespaces.add("urn:xmpp:chat-markers:0");
574 }
575 if (packet.hasChild("request", "urn:xmpp:receipts")) {
576 receiptsNamespaces.add("urn:xmpp:receipts");
577 }
578 if (receiptsNamespaces.size() > 0) {
579 MessagePacket receipt = mXmppConnectionService.getMessageGenerator().received(account,
580 packet,
581 receiptsNamespaces,
582 packet.getType());
583 mXmppConnectionService.sendMessagePacket(account, receipt);
584 }
585 }
586}