获取与 XEP-0313 每次对话的最后一条消息? [英] Get last message of each conversation with XEP-0313?

查看:29
本文介绍了获取与 XEP-0313 每次对话的最后一条消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用实现 XEP-0313 的 XMPP 服务器来检索对话历史记录.我只想获取每个对话的最后一条消息,以便我可以构建您最近的对话列表,预览最后一条消息.

I'm using an XMPP server that implements XEP-0313 for retrieving conversation history. I would like to fetch only the last message of each conversation, so that I can build a list of your most recent conversations previewing the last message.

我已经设法获取所有对话的所有消息,并基于此我可以构建列表,但这是对数据的巨大浪费,而不是一种选择.我不确定这是完成此任务的正确扩展程序,因此如果我应该查看其他扩展程序,请指导我朝着正确的方向前进.

I've managed to fetch all messages of all conversations and based on that I could build the list, but it's a big waste of data and not an option. I'm not sure this is the right extension for accomplishing this, so if there is another extension I should be looking at, please guide me in the right direction.

推荐答案

您可以轻松完成的一件事是首先检索用户名册,然后为每个联系人检索最新消息.

One thing you can do easily is first retrieve the user's roster and then for each contact retrieve the latest message.

<iq from='juliet@example.com/balcony'
    id='bv1bs71f'
    type='get'>
  <query xmlns='jabber:iq:roster'/>
</iq>

结果:

<iq id='bv1bs71f'
    to='juliet@example.com/chamber'
    type='result'>
   <query xmlns='jabber:iq:roster' ver='ver7'>
     <item jid='nurse@example.com'/>
     <item jid='romeo@example.net'/>
   </query>
 </iq>

检索来自或发送至nurse@example.com的最后一条消息:

Retrieve the last message from or to nurse@example.com:

<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>nurse@example.com</value>
      </field>
    </x>
    <set xmlns='http://jabber.org/protocol/rsm'>
      <max>1</max>
      <before/>
    </set>
  </query>
</iq>

当然,用户可以与不在他们名册上的人进行对话,但实际上这在 XMPP 上非常罕见.

Of course users can have conversations with people not on their roster, but in practice this is quite rare on XMPP.

这篇关于获取与 XEP-0313 每次对话的最后一条消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆