在不在线的情况下从 XMPP 获取离线消息

Get Offline Messages From XMPP Without Becoming Online

我们正在为我们的移动聊天应用程序使用 ejabberd 服务器。 我们正在为我们的 IOS 应用程序 (https://github.com/robbiehanson/XMPPFramework)

使用 IOS XMPP-Framework

但是我们在实施方面遇到了问题,我们找不到解决方案。 我们已经实现了 XMPP 消息传递的各个方面,除了一件事之外一切都很好:

当我们的应用程序在后台运行时,我们的 ejabberd 服务器会向我们发送推送通知以通知我们有关离线消息的信息。 (仅发送离线消息通知)

然后我们决定实现 IOS 后台推送通知功能,以便在应用程序处于后台时获取离线消息。

但问题是我们必须在线(发送状态)才能接收离线消息。 但是当我们这样做时,它会产生 2 个不良后果:

  1. 发送消息的一方看到我们在线(即使我们在后台)
  2. 正因为我们在应用程序处于后台时上线,所以我们的服务器无法发送其他人消息的推送通知,因为我们在线并且服务器只能发送离线消息的通知。

为了解决这个问题,我唯一能想到的是,如果有一种方法可以在不上线的情况下从xmpp 服务器检索离线消息。 有谁知道是否有任何方法可以使用 ios

的 XMPP-Framework 做到这一点

[编辑] 让我再澄清一下这个问题:

问题不止一个:

问题 1 - 推送通知问题:

1.1 - Server check if the message is sending to an online or offline user. If the user is offline server sends push notification to inform user but if the user is online server doesnt send anything. 
1.2 - When the application is in background and receive notification for offline messages, application become alive(still in background) and become online in order to get offline messages
1.3 - Because the client became online, server doesnt send the push notifications anymore but the application is still in background so the user cannot be informed about the message he/she received.

因此,为了解决这些问题,我需要找到一种通过不向服务器发送在线状态来接收离线消息的方法

问题 2 - 消息接收问题

2.1 - Server check if the message is sending to an online or offline user. If the user is offline server sends push notification to inform user but if the user is online server doesnt send anything. 
2.2 - When the application is in background and receive notification for offline messages, application become alive(still in background) and become online in order to get offline messages
2.3 - When the application became online server sends all offline messages to client but doesnt send the total count of offline messages(At least I cannot get it with IOS XMPPFramework)
2.4 - So I dont know how much longer the client should stay alive in the background because I dont know the total count of offline messages, so after getting 2-3 messages I have to suspend the application in the background. But in that case there might be buggy situations such as XMPP Framework receive the offline message but I suspend the client application before writing it to database etc...

为了找到解决这些问题的方法:

  1. 我需要找到一种方法,以便在需要时从服务器仅获取 1 条离线消息
  2. 如果可能的话,我还需要在不在线的情况下获取那些离线消息

我建议您将自定义扩展元素添加到您的 "background" 在线状态,例如

<presence ...>
<source xmlns:="com.foo#background"/>
</presence>

然后,客户端,当您收到存在时,如果扩展元素“source”和 xmlns“com.foo#background”存在,则不通知。

调查ejabberd_mod_offline_post

  1. 首先配置Room必须是Member-Only room,创建后立即将所有用户添加为成员,这样才能得到总数。
  2. 将以上模块添加到 ejabberd 模块中。
  3. 实施回调服务来处理回调 post。

想法是当用户下线时:

  • 在一对一的情况下,offline_message_hook会增加
  • 在 MUC 情况下,muc_filter_message 将被引发,并且任何不存在的人都处于离线状态。

[已编辑]:

我在 16.06 上使用它。并且源代码中有一个错误行:

...

Body = xml:get_path_s(Stanza, [{elem, list_to_binary("body")}, cdata]),

...

 Type = xml:get_tag_attr_s(list_to_binary("type"), Packet),

 Body = xml:get_path_s(Packet, [{elem, list_to_binary("body")}, cdata]),

...

我通过将 f 添加到 xml: 来修复它们,例如 主体 = fxml:get_path_s(节, [{elem, list_to_binary("body")}, cdata]),

对于 MUC,离线用户在 'Offline' 字段中作为这种格式,'user1..user2..user3..',您需要将其从字符串中拆分出来。