4

Am using Strophe.js library for communication between my application with XMPP(Openfire) server.

I want add user with group, How can i create new group? How can i mention group name with add buddy query?

This is my code for adding new user

var str1=$pres({'xmlns':'jabber:client','from':xxx@example.com,'to':yyy@example.com,'type':'subscribe'}).c('nick',{'xmlns':'http://jabber.org/protocol/nick'}).t(userName);
 connection.send(str1.tree());

I refer XMPP extension over day but i cant find proper result

Kenster
  • 23,465
  • 21
  • 80
  • 106
Rajamohan Sugumaran
  • 4,439
  • 4
  • 22
  • 19

2 Answers2

5

You need to send a roster update. Read RFC 6121, Section 2 for details. You'll be sending this protocol:

<iq from='juliet@example.com/balcony'
    id='rs1'
    type='set'>
   <query xmlns='jabber:iq:roster'>
     <item jid='yyy@example.com' name='nick'>
        <group>My Group</group>
     </item>         
   </query>
</iq>

With code something like:

$iq({'type':'set'}).c('query',{'xmlns':Strophe.NS.ROSTER}) 
   .c('item', {'jid':'yyy@example.com','name':'nick'})
       .c('group').t('My Group')
Community
  • 1
  • 1
Joe Hildebrand
  • 10,354
  • 2
  • 38
  • 48
  • 1
    Hai Joe in this case i cant add the user to particular group.,First i want create new group then only its possible.,Which extension will provide this – Rajamohan Sugumaran Jan 30 '12 at 06:45
  • 2
    There's no such thing as an empty group in base XMPP. You could store a list of empty groups separately, perhaps using PEP (XEP-0163: http://xmpp.org/extensions/xep-0163.html), or, failing that Private Storage (XEP-0049: http://xmpp.org/extensions/xep-0049.html). For either of those, use a new namespace that you control, but don't expect other clients to be able to see the empty groups. If you feel strongly about this, write a new XEP, and submit it to the XSF: http://xmpp.org/xmpp-protocols/xmpp-extensions/submitting-a-xep/ – Joe Hildebrand Jan 31 '12 at 05:56
0

I have made this Using below code.

XMPPRoomCoreDataStorage *rosterstorage =[[XMPPRoomCoreDataStorage alloc] init]; XMPPRoom *xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:rosterstorage jid:[XMPPJID jidWithString:@"MyFirstGroup@conference.test-desktop"] dispatchQueue:dispatch_get_main_queue()];

[xmppRoom activate:[[self appDelegate]xmppStream]];
[xmppRoom joinRoomUsingNickname:@"DeveloperQ" history:nil];

 [[[self appDelegate] xmppStream]  addDelegate:self delegateQueue:dispatch_get_main_queue()];
 [xmppRoom addDelegate:self  delegateQueue:dispatch_get_main_queue()];

Then

  • (void)xmppRoomDidJoin:(XMPPRoom *)sender

{

NSXMLElement *iq = [NSXMLElement elementWithName:@"iq"];

[iq addAttributeWithName:@"id" stringValue:[NSString stringWithFormat:@"inroom-cr%@",groupName]]; 
[iq addAttributeWithName:@"to" stringValue::@"MyFirstGroup@conference.test-desktop"];
[iq addAttributeWithName:@"type" stringValue:@"set"];
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:XMPPMUCOwnerNamespaceName];
NSXMLElement *xelem = [NSXMLElement elementWithName:@"x" xmlns:@"jabber:x:data"];
[xelem addAttributeWithName:@"type" stringValue:@"submit"];
[query addChild:xelem];
[iq addChild:query];
[[[self appDelegate] xmppStream] sendElement:iq];

}

Kiran K
  • 919
  • 10
  • 17