【问题标题】:Get Offline Messages From XMPP Without Becoming Online从 XMPP 获取离线消息而不变为在线
【发布时间】:2017-03-19 08:56:28
【问题描述】:

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

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

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

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

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

  1. 发送消息的一方将我们的存在视为在线(即使我们在后台)
  2. 仅仅因为我们在应用程序处于后台时在线,我们的服务器无法发送其他人消息的推送通知,因为我们在线,服务器只能发送离线消息的通知。

为了解决这个问题,我能想到的唯一一件事是,是否有一种方法可以从 xmpp 服务器检索离线消息而无需在线。 有谁知道是否有任何方法可以使用 XMPP-Framework for ios 来做到这一点

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

问题不止一个:

问题 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. 如果可能,我还需要在不在线的情况下获取这些离线消息

【问题讨论】:

  • 对这个问题有任何想法吗?

标签: ios objective-c xmpp ejabberd xmppframework


【解决方案1】:

查看ejabberd_mod_offline_post

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

这个想法是当用户下线时:

  • 在一对一的情况下,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(Stanza, [{elem, list_to_binary("body")}, cdata]),

对于 MUC,离线用户位于“离线”字段中,格式为“user1..user2..user3..”,您需要执行此操作才能将它们从字符串中拆分出来。

【讨论】:

  • 我已经在使用 mod_offline_post 模块 (mod_interact) 但是我不明白你的实际意思。创建群组聊天室后,我邀请用户加入新创建的群组,但除此之外我不知道如何将他们添加为成员(你能给我发个链接吗?)。另外,我不知道将上述模型添加到 ejabberd 模型中并实现回调服务是什么意思。你能更具体一点吗?谢谢
  • mod_interact 只支持一对一的离线消息。既然你用过它,你就知道它是如何工作的。这个我也发布了支持 MUC。您无需邀请用户加入,而是将用户直接添加到成员列表中。 xmpp.org/extensions/xep-0045.html#modifymember
  • 它是否适用于最新的 ejabberd 16.08 版本。因为我尝试改用 mod_offline_post 但即使我成功配置它,它也不起作用(不转发消息)
  • 其实我是在 16.06 上使用的,(16.08 在 windows 上安装时有 bug)。使用 mod_offline_post 时出现错误,请参阅我的编辑以获取修复。您可以检查您的日志中是否存在错误。
  • 谢谢,成功了。但是现在的问题是 mod_offline_post 将消息转发到我们的网络服务器到:部分消息看起来像群聊用户名,如 To:mygroup@mydomain.com 但我需要特定的离线接收者,所以我会找到设备令牌来发送推送通知对于特定的收件人。有没有可能。示例:To:offlineuser1@mydomain.com 不是 To:mygroup@mydomain.com 我认为我们可以做到(正如我从代码中看到的那样),但我没有知道erlang,所以我不知道怎么做
【解决方案2】:

例如,我建议您将自定义扩展元素添加到您的“背景”在线状态中

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

那么,客户端,当你收到出席信息时,不要通知扩展元素“source”和xmlns“com.foo#background”是否存在。

【讨论】:

  • 其实添加扩展元素是没有关系的,因为客户端不会发送通知。服务器端检查消息是否为离线消息,它会自动向设备发送通知,当 IOS 收到通知时,它会自动在设备上显示。所以我需要找到一种解决方案来获取离线消息而不在线,或者找到一种方法只获取一条离线消息(不是全部)
  • 我没明白重点,抱歉。问题是关于“即使我在后台,其他人也会在网上看到我”或其他什么?根据最后的评论,您似乎收到了太多“离线”消息,并且您不想收到多个消息。因此,只需在第一个离线模式下删除群组聊天/聊天的侦听器即可,或者实现一个“等待模式”(true | false)来存储消息但只显示第一个。它在第一次在后台启用,在第一次接收后禁用显示并启用队列,然后当点击将所有接收到的消息发送到您的 GUI 对象
  • 我已经编辑了我的问题,因为评论部分没有那么多字符串
  • 好吧,我得好好想想。我建议阅读:docs.ejabberd.im/admin/configuration/#modoffline 和官方规格xmpp.org/extensions/xep-0013.html
猜你喜欢
  • 1970-01-01
  • 2017-03-21
  • 1970-01-01
  • 2015-06-07
  • 2016-02-28
  • 2017-04-02
  • 2015-04-22
  • 2014-11-13
  • 2016-12-09
相关资源
最近更新 更多