I am trying to auto-join rooms using XEP-0048 - Bookmarks (http://xmpp.org/extensions/xep-0048.html).
I am using RobbieHanson XMPPFramework, ejabberd v13.x So far, I have been able to add bookmark to the room using the following code :
-(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];
}
The following xml is successfully sent :
<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>
And I receive :
<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>
When I try to fetch bookmarks using the following code :
-(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];
}
It sends the following xml :
<iq type="get" id="retrievebookmark10">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<items node="storage:bookmarks"/>
</pubsub>
</iq>
and I receive :
<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>
So it seems that I can successfully store bookmarks and retrieve them. But, when I try to talk in the room testroom@conference.mydomain.com
without manually joining it I get a error saying that I have to join the room before I can talk in the room. If I join the room (manually), every things works fine.
On the server-side, I used the mod_pubsub
module with the following options :
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
I am wondering why do I have to manually join bookmarked with "auto-join = true" rooms. Any clue ?
Autojoining bookmarked rooms is entirely a client-side feature - the client is supposed to retrieve the bookmarks at startup, and explicitly join the rooms marked as "auto-join".