How to create a new group on xmpp server

We use the Strophe.js library for communication between my application and the XMPP (Openfire) server.

I want to add a user with a group. How to create a new group? How can I name a group name with a friend request added?

This is my code to add a 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 use the XMPP extension for the day, but I can not find the correct result

+4
source share
2 answers

You need to send a registry update. See RFC 6121, Section 2 for details . You will send 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') 
+5
source

I did this using the code below.

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]; 

}

0
source

Source: https://habr.com/ru/post/1390392/


All Articles