MessageParser.java

  1package eu.siacs.conversations.parser;
  2
  3import android.util.Log;
  4
  5import net.java.otr4j.session.Session;
  6import net.java.otr4j.session.SessionStatus;
  7
  8import eu.siacs.conversations.Config;
  9import eu.siacs.conversations.entities.Account;
 10import eu.siacs.conversations.entities.Contact;
 11import eu.siacs.conversations.entities.Conversation;
 12import eu.siacs.conversations.entities.Message;
 13import eu.siacs.conversations.entities.MucOptions;
 14import eu.siacs.conversations.http.HttpConnectionManager;
 15import eu.siacs.conversations.services.MessageArchiveService;
 16import eu.siacs.conversations.services.XmppConnectionService;
 17import eu.siacs.conversations.utils.CryptoHelper;
 18import eu.siacs.conversations.xml.Element;
 19import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
 20import eu.siacs.conversations.xmpp.chatstate.ChatState;
 21import eu.siacs.conversations.xmpp.jid.Jid;
 22import eu.siacs.conversations.xmpp.pep.Avatar;
 23import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
 24
 25public class MessageParser extends AbstractParser implements
 26		OnMessagePacketReceived {
 27	public MessageParser(XmppConnectionService service) {
 28		super(service);
 29	}
 30
 31	private boolean extractChatState(Conversation conversation, final Element element) {
 32		ChatState state = ChatState.parse(element);
 33		if (state != null && conversation != null) {
 34			final Account account = conversation.getAccount();
 35			Jid from = element.getAttributeAsJid("from");
 36			if (from != null && from.toBareJid().equals(account.getJid().toBareJid())) {
 37				conversation.setOutgoingChatState(state);
 38				return false;
 39			} else {
 40				return conversation.setIncomingChatState(state);
 41			}
 42		}
 43		return false;
 44	}
 45
 46	private Message parseChat(MessagePacket packet, Account account) {
 47        final Jid jid = packet.getFrom();
 48		if (jid == null) {
 49			return null;
 50		}
 51		Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, jid.toBareJid(), false);
 52		updateLastseen(packet, account, true);
 53		String pgpBody = getPgpBody(packet);
 54		Message finishedMessage;
 55		if (pgpBody != null) {
 56			finishedMessage = new Message(conversation,
 57					pgpBody, Message.ENCRYPTION_PGP, Message.STATUS_RECEIVED);
 58		} else {
 59			finishedMessage = new Message(conversation,
 60					packet.getBody(), Message.ENCRYPTION_NONE,
 61					Message.STATUS_RECEIVED);
 62		}
 63		finishedMessage.setRemoteMsgId(packet.getId());
 64		finishedMessage.markable = isMarkable(packet);
 65		if (conversation.getMode() == Conversation.MODE_MULTI
 66				&& !jid.isBareJid()) {
 67			finishedMessage.setType(Message.TYPE_PRIVATE);
 68			finishedMessage.setTrueCounterpart(conversation.getMucOptions()
 69					.getTrueCounterpart(jid.getResourcepart()));
 70			if (conversation.hasDuplicateMessage(finishedMessage)) {
 71				return null;
 72			}
 73
 74		}
 75		finishedMessage.setCounterpart(jid);
 76		finishedMessage.setTime(getTimestamp(packet));
 77		extractChatState(conversation,packet);
 78		return finishedMessage;
 79	}
 80
 81	private Message parseOtrChat(MessagePacket packet, Account account) {
 82		final Jid to = packet.getTo();
 83		final Jid from = packet.getFrom();
 84		if (to == null || from == null) {
 85			return null;
 86		}
 87		boolean properlyAddressed = !to.isBareJid() || account.countPresences() == 1;
 88		Conversation conversation = mXmppConnectionService
 89				.findOrCreateConversation(account, from.toBareJid(), false);
 90		String presence;
 91		if (from.isBareJid()) {
 92            presence = "";
 93		} else {
 94			presence = from.getResourcepart();
 95		}
 96		updateLastseen(packet, account, true);
 97		String body = packet.getBody();
 98		if (body.matches("^\\?OTRv\\d{1,2}\\?.*")) {
 99			conversation.endOtrIfNeeded();
100		}
101		if (!conversation.hasValidOtrSession()) {
102			if (properlyAddressed) {
103				conversation.startOtrSession(presence,false);
104			} else {
105				return null;
106			}
107		} else {
108			String foreignPresence = conversation.getOtrSession()
109					.getSessionID().getUserID();
110			if (!foreignPresence.equals(presence)) {
111				conversation.endOtrIfNeeded();
112				if (properlyAddressed) {
113					conversation.startOtrSession(presence, false);
114				} else {
115					return null;
116				}
117			}
118		}
119		try {
120			Session otrSession = conversation.getOtrSession();
121			SessionStatus before = otrSession.getSessionStatus();
122			body = otrSession.transformReceiving(body);
123			SessionStatus after = otrSession.getSessionStatus();
124			if ((before != after) && (after == SessionStatus.ENCRYPTED)) {
125				conversation.setNextEncryption(Message.ENCRYPTION_OTR);
126				mXmppConnectionService.onOtrSessionEstablished(conversation);
127			} else if ((before != after) && (after == SessionStatus.FINISHED)) {
128				conversation.setNextEncryption(Message.ENCRYPTION_NONE);
129				conversation.resetOtrSession();
130				mXmppConnectionService.updateConversationUi();
131			}
132			if ((body == null) || (body.isEmpty())) {
133				return null;
134			}
135			if (body.startsWith(CryptoHelper.FILETRANSFER)) {
136				String key = body.substring(CryptoHelper.FILETRANSFER.length());
137				conversation.setSymmetricKey(CryptoHelper.hexToBytes(key));
138				return null;
139			}
140			Message finishedMessage = new Message(conversation, body, Message.ENCRYPTION_OTR,
141					Message.STATUS_RECEIVED);
142			finishedMessage.setTime(getTimestamp(packet));
143			finishedMessage.setRemoteMsgId(packet.getId());
144			finishedMessage.markable = isMarkable(packet);
145			finishedMessage.setCounterpart(from);
146			extractChatState(conversation,packet);
147			return finishedMessage;
148		} catch (Exception e) {
149			conversation.resetOtrSession();
150			return null;
151		}
152	}
153
154	private Message parseGroupchat(MessagePacket packet, Account account) {
155		int status;
156        final Jid from = packet.getFrom();
157		if (from == null) {
158			return null;
159		}
160		if (mXmppConnectionService.find(account.pendingConferenceLeaves,
161				account, from.toBareJid()) != null) {
162			return null;
163		}
164		Conversation conversation = mXmppConnectionService
165				.findOrCreateConversation(account, from.toBareJid(), true);
166		if (packet.hasChild("subject")) {
167			conversation.setHasMessagesLeftOnServer(true);
168			conversation.getMucOptions().setSubject(packet.findChild("subject").getContent());
169			mXmppConnectionService.updateConversationUi();
170			return null;
171		}
172
173		final Element x = packet.findChild("x", "http://jabber.org/protocol/muc#user");
174		if (from.isBareJid() && (x == null || !x.hasChild("status"))) {
175			return null;
176		} else if (from.isBareJid() && x.hasChild("status")) {
177			for(Element child : x.getChildren()) {
178				if (child.getName().equals("status")) {
179					String code = child.getAttribute("code");
180					if (code.contains(MucOptions.STATUS_CODE_ROOM_CONFIG_CHANGED)) {
181						mXmppConnectionService.fetchConferenceConfiguration(conversation);
182					}
183				}
184			}
185			return null;
186		}
187
188		if (from.getResourcepart().equals(conversation.getMucOptions().getActualNick())) {
189			if (mXmppConnectionService.markMessage(conversation,
190					packet.getId(), Message.STATUS_SEND_RECEIVED)) {
191				return null;
192			} else if (packet.getId() == null) {
193				Message message = conversation.findSentMessageWithBody(packet.getBody());
194				if (message != null) {
195					mXmppConnectionService.markMessage(message,Message.STATUS_SEND_RECEIVED);
196					return null;
197				} else {
198					status = Message.STATUS_SEND;
199				}
200			} else {
201				status = Message.STATUS_SEND;
202			}
203		} else {
204			status = Message.STATUS_RECEIVED;
205		}
206		String pgpBody = getPgpBody(packet);
207		Message finishedMessage;
208		if (pgpBody == null) {
209			finishedMessage = new Message(conversation,
210					packet.getBody(), Message.ENCRYPTION_NONE, status);
211		} else {
212			finishedMessage = new Message(conversation, pgpBody,
213					Message.ENCRYPTION_PGP, status);
214		}
215		finishedMessage.setRemoteMsgId(packet.getId());
216		finishedMessage.markable = isMarkable(packet);
217		finishedMessage.setCounterpart(from);
218		if (status == Message.STATUS_RECEIVED) {
219			finishedMessage.setTrueCounterpart(conversation.getMucOptions()
220					.getTrueCounterpart(from.getResourcepart()));
221		}
222		if (packet.hasChild("delay")
223				&& conversation.hasDuplicateMessage(finishedMessage)) {
224			return null;
225		}
226		finishedMessage.setTime(getTimestamp(packet));
227		return finishedMessage;
228	}
229
230	private Message parseCarbonMessage(final MessagePacket packet, final Account account) {
231		int status;
232		final Jid fullJid;
233		Element forwarded;
234		if (packet.hasChild("received", "urn:xmpp:carbons:2")) {
235			forwarded = packet.findChild("received", "urn:xmpp:carbons:2")
236					.findChild("forwarded", "urn:xmpp:forward:0");
237			status = Message.STATUS_RECEIVED;
238		} else if (packet.hasChild("sent", "urn:xmpp:carbons:2")) {
239			forwarded = packet.findChild("sent", "urn:xmpp:carbons:2")
240					.findChild("forwarded", "urn:xmpp:forward:0");
241			status = Message.STATUS_SEND;
242		} else {
243			return null;
244		}
245		if (forwarded == null) {
246			return null;
247		}
248		Element message = forwarded.findChild("message");
249		if (message == null) {
250			return null;
251		}
252		if (!message.hasChild("body")) {
253			if (status == Message.STATUS_RECEIVED
254					&& message.getAttribute("from") != null) {
255				parseNonMessage(message, account);
256			} else if (status == Message.STATUS_SEND
257					&& message.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
258				final Jid to = message.getAttributeAsJid("to");
259				if (to != null) {
260					final Conversation conversation = mXmppConnectionService.find(
261							mXmppConnectionService.getConversations(), account,
262							to.toBareJid());
263					if (conversation != null) {
264						mXmppConnectionService.markRead(conversation);
265					}
266				}
267			}
268			return null;
269		}
270		if (status == Message.STATUS_RECEIVED) {
271			fullJid = message.getAttributeAsJid("from");
272			if (fullJid == null) {
273				return null;
274			} else {
275				updateLastseen(message, account, true);
276			}
277		} else {
278			fullJid = message.getAttributeAsJid("to");
279			if (fullJid == null) {
280				return null;
281			}
282		}
283		if (message.hasChild("x","http://jabber.org/protocol/muc#user")
284				&& "chat".equals(message.getAttribute("type"))) {
285			return null;
286		}
287		Conversation conversation = mXmppConnectionService
288				.findOrCreateConversation(account, fullJid.toBareJid(), false);
289		String pgpBody = getPgpBody(message);
290		Message finishedMessage;
291		if (pgpBody != null) {
292			finishedMessage = new Message(conversation, pgpBody,
293					Message.ENCRYPTION_PGP, status);
294		} else {
295			String body = message.findChild("body").getContent();
296			finishedMessage = new Message(conversation, body,
297					Message.ENCRYPTION_NONE, status);
298		}
299		extractChatState(conversation,message);
300		finishedMessage.setTime(getTimestamp(message));
301		finishedMessage.setRemoteMsgId(message.getAttribute("id"));
302		finishedMessage.markable = isMarkable(message);
303		finishedMessage.setCounterpart(fullJid);
304		if (conversation.getMode() == Conversation.MODE_MULTI
305				&& !fullJid.isBareJid()) {
306			finishedMessage.setType(Message.TYPE_PRIVATE);
307			finishedMessage.setTrueCounterpart(conversation.getMucOptions()
308					.getTrueCounterpart(fullJid.getResourcepart()));
309			if (conversation.hasDuplicateMessage(finishedMessage)) {
310				return null;
311			}
312		}
313		return finishedMessage;
314	}
315
316	private Message parseMamMessage(MessagePacket packet, final Account account) {
317		final Element result = packet.findChild("result","urn:xmpp:mam:0");
318		if (result == null ) {
319			return null;
320		}
321		final MessageArchiveService.Query query = this.mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid"));
322		if (query!=null) {
323			query.incrementTotalCount();
324		}
325		final Element forwarded = result.findChild("forwarded","urn:xmpp:forward:0");
326		if (forwarded == null) {
327			return null;
328		}
329		final Element message = forwarded.findChild("message");
330		if (message == null) {
331			return null;
332		}
333		final Element body = message.findChild("body");
334		if (body == null || message.hasChild("private","urn:xmpp:carbons:2") || message.hasChild("no-copy","urn:xmpp:hints")) {
335			return null;
336		}
337		int encryption;
338		String content = getPgpBody(message);
339		if (content != null) {
340			encryption = Message.ENCRYPTION_PGP;
341		} else {
342			encryption = Message.ENCRYPTION_NONE;
343			content = body.getContent();
344		}
345		if (content == null) {
346			return null;
347		}
348		final long timestamp = getTimestamp(forwarded);
349		final Jid to = message.getAttributeAsJid("to");
350		final Jid from = message.getAttributeAsJid("from");
351		Jid counterpart;
352		int status;
353		Conversation conversation;
354		if (from!=null && to != null && from.toBareJid().equals(account.getJid().toBareJid())) {
355			status = Message.STATUS_SEND;
356			conversation = this.mXmppConnectionService.findOrCreateConversation(account,to.toBareJid(),false,query);
357			counterpart = to;
358		} else if (from !=null && to != null) {
359			status = Message.STATUS_RECEIVED;
360			conversation = this.mXmppConnectionService.findOrCreateConversation(account,from.toBareJid(),false,query);
361			counterpart = from;
362		} else {
363			return null;
364		}
365		Message finishedMessage = new Message(conversation,content,encryption,status);
366		finishedMessage.setTime(timestamp);
367		finishedMessage.setCounterpart(counterpart);
368		finishedMessage.setRemoteMsgId(message.getAttribute("id"));
369		finishedMessage.setServerMsgId(result.getAttribute("id"));
370		if (conversation.hasDuplicateMessage(finishedMessage)) {
371			return null;
372		}
373		if (query!=null) {
374			query.incrementMessageCount();
375		}
376		return finishedMessage;
377	}
378
379	private void parseError(final MessagePacket packet, final Account account) {
380		final Jid from = packet.getFrom();
381		mXmppConnectionService.markMessage(account, from.toBareJid(),
382				packet.getId(), Message.STATUS_SEND_FAILED);
383	}
384
385	private void parseNonMessage(Element packet, Account account) {
386		final Jid from = packet.getAttributeAsJid("from");
387		if (extractChatState(from == null ? null : mXmppConnectionService.find(account,from), packet)) {
388			mXmppConnectionService.updateConversationUi();
389		}
390		Element invite = extractInvite(packet);
391		if (invite != null) {
392			Conversation conversation = mXmppConnectionService.findOrCreateConversation(account, from, true);
393			if (!conversation.getMucOptions().online()) {
394				Element password = invite.findChild("password");
395				conversation.getMucOptions().setPassword(password == null ? null : password.getContent());
396				mXmppConnectionService.databaseBackend.updateConversation(conversation);
397				mXmppConnectionService.joinMuc(conversation);
398				mXmppConnectionService.updateConversationUi();
399			}
400		}
401		if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
402			Element event = packet.findChild("event",
403					"http://jabber.org/protocol/pubsub#event");
404			parseEvent(event, from, account);
405		} else if (from != null && packet.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
406			String id = packet
407					.findChild("displayed", "urn:xmpp:chat-markers:0")
408					.getAttribute("id");
409			updateLastseen(packet, account, true);
410			final Message displayedMessage = mXmppConnectionService.markMessage(account, from.toBareJid(), id, Message.STATUS_SEND_DISPLAYED);
411			Message message = displayedMessage.prev();
412			while(message != null
413					&& message.getStatus() == Message.STATUS_SEND_RECEIVED
414					&& message.getTimeSent() < displayedMessage.getTimeSent()) {
415				mXmppConnectionService.markMessage(message,Message.STATUS_SEND_DISPLAYED);
416				message = message.prev();
417			}
418		} else if (from != null
419				&& packet.hasChild("received", "urn:xmpp:chat-markers:0")) {
420			String id = packet.findChild("received", "urn:xmpp:chat-markers:0")
421					.getAttribute("id");
422			updateLastseen(packet, account, false);
423			mXmppConnectionService.markMessage(account, from.toBareJid(),
424					id, Message.STATUS_SEND_RECEIVED);
425		} else if (from != null
426				&& packet.hasChild("received", "urn:xmpp:receipts")) {
427			String id = packet.findChild("received", "urn:xmpp:receipts")
428					.getAttribute("id");
429			updateLastseen(packet, account, false);
430			mXmppConnectionService.markMessage(account, from.toBareJid(),
431					id, Message.STATUS_SEND_RECEIVED);
432		}
433	}
434
435	private Element extractInvite(Element message) {
436		Element x = message.findChild("x","http://jabber.org/protocol/muc#user");
437		if (x == null) {
438			x = message.findChild("x","jabber:x:conference");
439		}
440		if (x != null && x.hasChild("invite")) {
441			return x;
442		} else {
443			return null;
444		}
445	}
446
447	private void parseEvent(final Element event, final Jid from, final Account account) {
448		Element items = event.findChild("items");
449		if (items == null) {
450			return;
451		}
452		String node = items.getAttribute("node");
453		if (node == null) {
454			return;
455		}
456		if (node.equals("urn:xmpp:avatar:metadata")) {
457			Avatar avatar = Avatar.parseMetadata(items);
458			if (avatar != null) {
459				avatar.owner = from;
460				if (mXmppConnectionService.getFileBackend().isAvatarCached(
461						avatar)) {
462					if (account.getJid().toBareJid().equals(from)) {
463						if (account.setAvatar(avatar.getFilename())) {
464							mXmppConnectionService.databaseBackend
465									.updateAccount(account);
466						}
467						mXmppConnectionService.getAvatarService().clear(
468								account);
469						mXmppConnectionService.updateConversationUi();
470						mXmppConnectionService.updateAccountUi();
471					} else {
472						Contact contact = account.getRoster().getContact(
473								from);
474						contact.setAvatar(avatar.getFilename());
475						mXmppConnectionService.getAvatarService().clear(
476								contact);
477						mXmppConnectionService.updateConversationUi();
478						mXmppConnectionService.updateRosterUi();
479					}
480				} else {
481					mXmppConnectionService.fetchAvatar(account, avatar);
482				}
483			}
484		} else if (node.equals("http://jabber.org/protocol/nick")) {
485			Element item = items.findChild("item");
486			if (item != null) {
487				Element nick = item.findChild("nick",
488						"http://jabber.org/protocol/nick");
489				if (nick != null) {
490					if (from != null) {
491						Contact contact = account.getRoster().getContact(
492								from);
493						contact.setPresenceName(nick.getContent());
494						mXmppConnectionService.getAvatarService().clear(account);
495						mXmppConnectionService.updateConversationUi();
496						mXmppConnectionService.updateAccountUi();
497					}
498				}
499			}
500		}
501	}
502
503	private String getPgpBody(Element message) {
504		Element child = message.findChild("x", "jabber:x:encrypted");
505		if (child == null) {
506			return null;
507		} else {
508			return child.getContent();
509		}
510	}
511
512	private boolean isMarkable(Element message) {
513		return message.hasChild("markable", "urn:xmpp:chat-markers:0");
514	}
515
516	@Override
517	public void onMessagePacketReceived(Account account, MessagePacket packet) {
518		Message message = null;
519		this.parseNick(packet, account);
520		if ((packet.getType() == MessagePacket.TYPE_CHAT || packet.getType() == MessagePacket.TYPE_NORMAL)) {
521			if ((packet.getBody() != null)
522					&& (packet.getBody().startsWith("?OTR"))) {
523				message = this.parseOtrChat(packet, account);
524				if (message != null) {
525					message.markUnread();
526				}
527			} else if (packet.hasChild("body") && extractInvite(packet) == null) {
528				message = this.parseChat(packet, account);
529				if (message != null) {
530					message.markUnread();
531				}
532			} else if (packet.hasChild("received", "urn:xmpp:carbons:2")
533					|| (packet.hasChild("sent", "urn:xmpp:carbons:2"))) {
534				message = this.parseCarbonMessage(packet, account);
535				if (message != null) {
536					if (message.getStatus() == Message.STATUS_SEND) {
537						account.activateGracePeriod();
538						mXmppConnectionService.markRead(message.getConversation());
539					} else {
540						message.markUnread();
541					}
542				}
543			} else if (packet.hasChild("result","urn:xmpp:mam:0")) {
544				message = parseMamMessage(packet, account);
545				if (message != null) {
546					Conversation conversation = message.getConversation();
547					conversation.add(message);
548					mXmppConnectionService.databaseBackend.createMessage(message);
549				}
550				return;
551			} else if (packet.hasChild("fin","urn:xmpp:mam:0")) {
552				Element fin = packet.findChild("fin","urn:xmpp:mam:0");
553				mXmppConnectionService.getMessageArchiveService().processFin(fin);
554			} else {
555				parseNonMessage(packet, account);
556			}
557		} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {
558			message = this.parseGroupchat(packet, account);
559			if (message != null) {
560				if (message.getStatus() == Message.STATUS_RECEIVED) {
561					message.markUnread();
562				} else {
563					mXmppConnectionService.markRead(message.getConversation());
564					account.activateGracePeriod();
565				}
566			}
567		} else if (packet.getType() == MessagePacket.TYPE_ERROR) {
568			this.parseError(packet, account);
569			return;
570		} else if (packet.getType() == MessagePacket.TYPE_HEADLINE) {
571			this.parseHeadline(packet, account);
572			return;
573		}
574		if ((message == null) || (message.getBody() == null)) {
575			return;
576		}
577		if ((mXmppConnectionService.confirmMessages())
578				&& ((packet.getId() != null))) {
579			if (packet.hasChild("markable", "urn:xmpp:chat-markers:0")) {
580				MessagePacket receipt = mXmppConnectionService
581						.getMessageGenerator().received(account, packet,
582								"urn:xmpp:chat-markers:0");
583				mXmppConnectionService.sendMessagePacket(account, receipt);
584			}
585			if (packet.hasChild("request", "urn:xmpp:receipts")) {
586				MessagePacket receipt = mXmppConnectionService
587						.getMessageGenerator().received(account, packet,
588								"urn:xmpp:receipts");
589				mXmppConnectionService.sendMessagePacket(account, receipt);
590			}
591		}
592		Conversation conversation = message.getConversation();
593		conversation.add(message);
594		if (account.getXmppConnection() != null && account.getXmppConnection().getFeatures().advancedStreamFeaturesLoaded()) {
595			if (conversation.setLastMessageTransmitted(System.currentTimeMillis())) {
596				mXmppConnectionService.updateConversation(conversation);
597			}
598		}
599
600		if (message.getStatus() == Message.STATUS_RECEIVED
601				&& conversation.getOtrSession() != null
602				&& !conversation.getOtrSession().getSessionID().getUserID()
603				.equals(message.getCounterpart().getResourcepart())) {
604			conversation.endOtrIfNeeded();
605		}
606
607		if (packet.getType() != MessagePacket.TYPE_ERROR) {
608			if (message.getEncryption() == Message.ENCRYPTION_NONE
609					|| mXmppConnectionService.saveEncryptedMessages()) {
610				mXmppConnectionService.databaseBackend.createMessage(message);
611			}
612		}
613		final HttpConnectionManager manager = this.mXmppConnectionService.getHttpConnectionManager();
614		if (message.trusted() && message.bodyContainsDownloadable() && manager.getAutoAcceptFileSize() > 0) {
615			manager.createNewConnection(message);
616		} else if (!message.isRead()) {
617			mXmppConnectionService.getNotificationService().push(message);
618		}
619		mXmppConnectionService.updateConversationUi();
620	}
621
622	private void parseHeadline(MessagePacket packet, Account account) {
623		if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
624			Element event = packet.findChild("event",
625					"http://jabber.org/protocol/pubsub#event");
626			parseEvent(event, packet.getFrom(), account);
627		}
628	}
629
630	private void parseNick(MessagePacket packet, Account account) {
631		Element nick = packet.findChild("nick",
632				"http://jabber.org/protocol/nick");
633		if (nick != null) {
634			if (packet.getFrom() != null) {
635				Contact contact = account.getRoster().getContact(
636						packet.getFrom());
637				contact.setPresenceName(nick.getContent());
638			}
639		}
640	}
641}