xmpp msg format(server by openfire, client by java app and spark)

E:\bench-cluster\mybatis_in_action_eclipse\xmpp\src>java -cp .;../lib/* com.xmpp.client.ClientA
executing connectAndLogin method.
successfully connection.
successfully login.
executing createChat method.
executing addChatListener method.

receiving <message to='[email protected]' from='[email protected]/Spark' id='ORj7K-188' type='chat'><body>nihao</body><thread>E4nnJR</thread><x xmlns="jabber:x:event"><offline/><composing/></x></message> // client by spark.
<pre name="code" class="cpp"><message to='[email protected]' from='[email protected]/Smack' id='Kh64Z-9' type='chat'><body>hello, my name is pacoson.</body><thread>185663b4-f6d3-4c03-8038-a0bc7e351b00</thread><delay xmlns='urn:xmpp:delay' stamp='2016-07-03T11:44:16.795+00:00' from='csdn.pacosonswjtu.com'></delay></message> // client by javapp
<span style="font-family:Microsoft YaHei;font-size:14px;">
</span>
对以上代码的分析(Analysis):

A1)从上述的msg 封装格式,我们看到,smack java app 实现的 client 发送msg 的时候(且对方处于离线的时候),会自动封装 <delay> 元素.

A2)delay 元素为:<delay xmlns='urn:xmpp:delay' stamp='2016-07-03T12:49:53.808+00:00' from='csdn.pacosonswjtu.com'></delay>

A3)特别注意,只有当 消息接收者处于离线的时候,其接收到的消息才会封装 delay 元素,其属性有 stamp 记录了 msg 发送的时间。(also, you can refer to https://community.igniterealtime.org/thread/22791)

A4)获取 offline msg 的 发送 timestamp

public Date getChatTimestamp(Message msg) {
		System.out.println(msg);
		ExtensionElement delay = DelayInformation.from(msg);

		if(delay == null) {
			return null;
		}
		Date date = ((DelayInformation) delay).getStamp();
		return date;
	}

你可能感兴趣的:(xmpp msg format(server by openfire, client by java app and spark))