我正在使用一个 XMPP 服务器来实现XEP-0313 http://xmpp.org/extensions/xep-0313.html用于检索对话历史记录。我只想获取每个对话的最后一条消息,以便我可以构建您最近的对话列表,预览最后一条消息。
我已经设法获取所有对话的所有消息,并基于此我可以构建列表,但这是对数据的巨大浪费,而不是一个选择。我不确定这是否是完成此任务的正确扩展,因此如果我应该考虑其他扩展,请引导我走向正确的方向。
您可以轻松做的一件事是首先检索用户的花名册,然后为每个联系人检索最新消息。
<iq from='[email protected] /cdn-cgi/l/email-protection/balcony'
id='bv1bs71f'
type='get'>
<query xmlns='jabber:iq:roster'/>
</iq>
Result:
<iq id='bv1bs71f'
to='[email protected] /cdn-cgi/l/email-protection/chamber'
type='result'>
<query xmlns='jabber:iq:roster' ver='ver7'>
<item jid='[email protected] /cdn-cgi/l/email-protection'/>
<item jid='[email protected] /cdn-cgi/l/email-protection'/>
</query>
</iq>
检索发件人或收件人的最后一条消息[电子邮件受保护] /cdn-cgi/l/email-protection:
<iq type='set' id='juliet1'>
<query xmlns='urn:xmpp:mam:1'>
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>urn:xmpp:mam:1</value>
</field>
<field var='with'>
<value>[email protected] /cdn-cgi/l/email-protection</value>
</field>
</x>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>1</max>
<before/>
</set>
</query>
</iq>
当然,用户可以与不在其名册上的人进行对话,但实际上这在 XMPP 上很少见。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)