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 (!isTypeGroupChat) {
399 message.setType(Message.TYPE_PRIVATE);
400 }
401 } else {
402 updateLastseen(timestamp, account, from);
403 }
404
405 if (replacementId != null && mXmppConnectionService.allowMessageCorrection()) {
406 Message replacedMessage = conversation.findMessageWithRemoteIdAndCounterpart(replacementId,
407 counterpart,
408 message.getStatus() == Message.STATUS_RECEIVED,
409 message.isCarbon());
410 if (replacedMessage != null) {
411 final boolean fingerprintsMatch = replacedMessage.getFingerprint() == null
412 || replacedMessage.getFingerprint().equals(message.getFingerprint());
413 final boolean trueCountersMatch = replacedMessage.getTrueCounterpart() != null
414 && replacedMessage.getTrueCounterpart().equals(message.getTrueCounterpart());
415 if (fingerprintsMatch && (trueCountersMatch || conversation.getMode() == Conversation.MODE_SINGLE)) {
416 Log.d(Config.LOGTAG, "replaced message '" + replacedMessage.getBody() + "' with '" + message.getBody() + "'");
417 final String uuid = replacedMessage.getUuid();
418 replacedMessage.setUuid(UUID.randomUUID().toString());
419 replacedMessage.setBody(message.getBody());
420 replacedMessage.setEdited(replacedMessage.getRemoteMsgId());
421 replacedMessage.setRemoteMsgId(remoteMsgId);
422 replacedMessage.setEncryption(message.getEncryption());
423 if (replacedMessage.getStatus() == Message.STATUS_RECEIVED) {
424 replacedMessage.markUnread();
425 }
426 mXmppConnectionService.updateMessage(replacedMessage, uuid);
427 mXmppConnectionService.getNotificationService().updateNotification(false);
428 if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
429 sendMessageReceipts(account, packet);
430 }
431 if (replacedMessage.getEncryption() == Message.ENCRYPTION_PGP) {
432 conversation.getAccount().getPgpDecryptionService().add(replacedMessage);
433 }
434 return;
435 } else {
436 Log.d(Config.LOGTAG,account.getJid().toBareJid()+": received message correction but verification didn't check out");
437 }
438 }
439 }
440
441 boolean checkForDuplicates = query != null
442 || (isTypeGroupChat && packet.hasChild("delay","urn:xmpp:delay"))
443 || message.getType() == Message.TYPE_PRIVATE;
444 if (checkForDuplicates && conversation.hasDuplicateMessage(message)) {
445 Log.d(Config.LOGTAG,"skipping duplicate message from "+message.getCounterpart().toString()+" "+message.getBody());
446 return;
447 }
448
449 if (query != null && query.getPagingOrder() == MessageArchiveService.PagingOrder.REVERSE) {
450 conversation.prepend(message);
451 } else {
452 conversation.add(message);
453 }
454
455 if (message.getEncryption() == Message.ENCRYPTION_PGP) {
456 conversation.getAccount().getPgpDecryptionService().add(message);
457 }
458
459 if (query == null || query.getWith() == null) { //either no mam or catchup
460 if (status == Message.STATUS_SEND || status == Message.STATUS_SEND_RECEIVED) {
461 mXmppConnectionService.markRead(conversation);
462 if (query == null) {
463 account.activateGracePeriod();
464 }
465 } else {
466 message.markUnread();
467 }
468 }
469
470 if (query == null) {
471 mXmppConnectionService.updateConversationUi();
472 }
473
474 if (mXmppConnectionService.confirmMessages() && remoteMsgId != null && !isForwarded && !isTypeGroupChat) {
475 sendMessageReceipts(account, packet);
476 }
477
478 if (message.getStatus() == Message.STATUS_RECEIVED
479 && conversation.getOtrSession() != null
480 && !conversation.getOtrSession().getSessionID().getUserID()
481 .equals(message.getCounterpart().getResourcepart())) {
482 conversation.endOtrIfNeeded();
483 }
484
485 if (message.getEncryption() == Message.ENCRYPTION_NONE || mXmppConnectionService.saveEncryptedMessages()) {
486 mXmppConnectionService.databaseBackend.createMessage(message);
487 }
488 final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
489 if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
490 manager.createNewDownloadConnection(message);
491 } else if (!message.isRead()) {
492 if (query == null) {
493 mXmppConnectionService.getNotificationService().push(message);
494 } else if (query.getWith() == null) { // mam catchup
495 mXmppConnectionService.getNotificationService().pushFromBacklog(message);
496 }
497 }
498 } else if (!packet.hasChild("body")){ //no body
499 if (isTypeGroupChat) {
500 Conversation conversation = mXmppConnectionService.find(account, from.toBareJid());
501 if (packet.hasChild("subject")) {
502 if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {
503 conversation.setHasMessagesLeftOnServer(conversation.countMessages() > 0);
504 String subject = packet.findChildContent("subject");
505 conversation.getMucOptions().setSubject(subject);
506 final Bookmark bookmark = conversation.getBookmark();
507 if (bookmark != null && bookmark.getBookmarkName() == null) {
508 if (bookmark.setBookmarkName(subject)) {
509 mXmppConnectionService.pushBookmarks(account);
510 }
511 }
512 mXmppConnectionService.updateConversationUi();
513 return;
514 }
515 }
516
517 if (conversation != null && isMucStatusMessage) {
518 for (Element child : mucUserElement.getChildren()) {
519 if (child.getName().equals("status")
520 && MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED.equals(child.getAttribute("code"))) {
521 mXmppConnectionService.fetchConferenceConfiguration(conversation);
522 }
523 }
524 }
525 }
526 }
527
528 Element received = packet.findChild("received", "urn:xmpp:chat-markers:0");
529 if (received == null) {
530 received = packet.findChild("received", "urn:xmpp:receipts");
531 }
532 if (received != null && !packet.fromAccount(account)) {
533 mXmppConnectionService.markMessage(account, from.toBareJid(), received.getAttribute("id"), Message.STATUS_SEND_RECEIVED);
534 }
535 Element displayed = packet.findChild("displayed", "urn:xmpp:chat-markers:0");
536 if (displayed != null) {
537 if (packet.fromAccount(account)) {
538 Conversation conversation = mXmppConnectionService.find(account,counterpart.toBareJid());
539 if (conversation != null) {
540 mXmppConnectionService.markRead(conversation);
541 }
542 } else {
543 updateLastseen(timestamp, account, from);
544 final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), displayed.getAttribute("id"), Message.STATUS_SEND_DISPLAYED);
545 Message message = displayedMessage == null ? null : displayedMessage.prev();
546 while (message != null
547 && message.getStatus() == Message.STATUS_SEND_RECEIVED
548 && message.getTimeSent() < displayedMessage.getTimeSent()) {
549 mXmppConnectionService.markMessage(message, Message.STATUS_SEND_DISPLAYED);
550 message = message.prev();
551 }
552 }
553 }
554
555 Element event = packet.findChild("event", "http://jabber.org/protocol/pubsub#event");
556 if (event != null) {
557 parseEvent(event, from, account);
558 }
559
560 String nick = packet.findChildContent("nick", "http://jabber.org/protocol/nick");
561 if (nick != null) {
562 Contact contact = account.getRoster().getContact(from);
563 contact.setPresenceName(nick);
564 }
565 }
566
567 private void sendMessageReceipts(Account account, MessagePacket packet) {
568 ArrayList<String> receiptsNamespaces = new ArrayList<>();
569 if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
570 receiptsNamespaces.add("urn:xmpp:chat-markers:0");
571 }
572 if (packet.hasChild("request", "urn:xmpp:receipts")) {
573 receiptsNamespaces.add("urn:xmpp:receipts");
574 }
575 if (receiptsNamespaces.size() > 0) {
576 MessagePacket receipt = mXmppConnectionService.getMessageGenerator().received(account,
577 packet,
578 receiptsNamespaces,
579 packet.getType());
580 mXmppConnectionService.sendMessagePacket(account, receipt);
581 }
582 }
583}