我正在尝试使用XEP-0048 – 书签(
http://xmpp.org/extensions/xep-0048.html)自动加入房间.
我正在使用RobbieHanson XMPPFramework,ejabberd v13.x
到目前为止,我已经能够使用以下代码将书签添加到房间:
-(void) createBookmarkforRoom:(NSString *)roomJid {
NSXMLElement *nick = [NSXMLElement elementWithName:@"nick" stringValue:@"Marge"];
NSXMLElement *conference = [DDXMLNode elementWithName:@"conference"];
[conference addAttributeWithName:@"name" stringValue:@"BookmarkName"];
[conference addAttributeWithName:@"autojoin" stringValue:@"true"];
[conference addAttributeWithName:@"jid" stringValue:roomJid];
[conference addChild:nick];
NSXMLElement *storage =[DDXMLNode elementWithName:@"storage"];
[storage addAttributeWithName:@"xmlns" stringValue:@"storage:bookmarks"];
[storage addChild:conference];
NSDictionary *options = [NSDictionary dictionaryWithObjects:@[@"pubsub#persist_items",@"pubsub#access_model"]
forKeys:@[@"true",@"whitelist"]];
[self.publishSubscribeModule publishToNode:@"storage:bookmarks"
entry:(NSXMLElement *)storage
withItemID:(NSString *)@"current"
options:(NSDictionary *)options];
}
以下xml已成功发送:
<iq type="set" id="2749368B-E365-45D6-A4B0-2F79DC6F4747">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="storage:bookmarks">
<item id="current">
<storage xmlns="storage:bookmarks">
<conference name="BookmarkName" autojoin="true" jid="testroom@conference.mydomain.com">
<nick>Marge</nick>
</conference>
</storage>
</item>
</publish>
<publish-options>
<x xmlns="jabber:x:data" type="submit">
<field var="FORM_TYPE" type="hidden">
<value>http://jabber.org/protocol/pubsub#publish-options</value>
</field>
<field var="true">
<value>pubsub#persist_items</value>
</field>
<field var="whitelist">
<value>pubsub#access_model</value>
</field>
</x>
</publish-options>
</pubsub>
</iq>
我收到:
<iq xmlns="jabber:client" from="marge@mydomain.com" to="marge@mydomain.com/41045582821403862604272126" id="2749368B-E365-45D6-A4B0-2F79DC6F4747" type="result">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<publish node="storage:bookmarks">
<item id="current" />
</publish>
</pubsub>
</iq>
当我尝试使用以下代码获取书签时:
-(void)requestBookmarks {
DDXMLElement *pubsub = [DDXMLElement elementWithName:@"pubsub" xmlns:@"http://jabber.org/protocol/pubsub"];
DDXMLElement *items = [DDXMLElement elementWithName:@"items"];
[items addAttributeWithName:@"node" stringValue:@"storage:bookmarks"];
[pubsub addChild:items];
XMPPIQ *iqBookmark = [XMPPIQ iqWithType:@"get" elementID:@"retrievebookmark10" child:pubsub];
[self.stream sendElement:iqBookmark];
}
它发送以下xml:
<iq type="get" id="retrievebookmark10">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<items node="storage:bookmarks"/>
</pubsub>
</iq>
我收到:
<iq xmlns="jabber:client" from="marge@mydomain.com" to="marge@mydomain.com/41045582821403862604272126" id="retrievebookmark10" type="result">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<items node="storage:bookmarks">
<item id="current">
<storage xmlns="storage:bookmarks">
<conference name="BookmarkName" autojoin="true" jid="testroom@conference.mydomain.com">
<nick>Marge</nick>
</conference>
</storage>
</item>
</items>
</pubsub>
</iq>
所以我似乎可以成功存储书签并检索它们.但是,当我尝试在没有手动加入它的房间testroom@conference.mydomain.com谈话时,我得到一个错误,说我必须加入房间才能在房间里说话.如果我加入房间(手动),每件事情都可以.
在服务器端,我使用mod_pubsub模块和以下选项:
mod_pubsub:
access_createnode: pubsub_createnode
## reduces resource comsumption, but XEP incompliant
ignore_pep_from_offline: true
## XEP compliant, but increases resource comsumption
## ignore_pep_from_offline: false
last_item_cache: false
plugins:
- "flat"
- "hometree"
- "pep" # pep requires mod_caps
我想知道为什么我必须手动加入“auto-join = true”房间加入书签.任何线索?
最佳答案 自动加入书签的房间完全是客户端功能 – 客户端应该在启动时检索书签,并明确加入标记为“自动加入”的房间.