SweetaAhuja

Untitled

Apr 20th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. -(void)sendGroupMessage:(Message *)objMessage
  2. to:(Groups *)objGroups
  3. {
  4. // Code by sweeta...
  5. XMPPJID* recipient = [XMPPJID jidWithString:objGroups.jId];
  6.  
  7. XMPPMessage* message = [[XMPPMessage alloc] initWithType:@"groupchat" to:recipient];
  8. [message addAttributeWithName:@"type" stringValue:@"groupchat"];
  9.  
  10. NSMutableDictionary *msgDic = [[NSMutableDictionary alloc] init];
  11.  
  12. NSMutableDictionary *senderProperty = [[NSMutableDictionary alloc] init];
  13. [senderProperty setObject:objGroups.groupName forKey:kGroupName];
  14. [senderProperty setObject:objGroups.jId forKey:kJId];
  15.  
  16. [msgDic setObject:senderProperty forKey:@"sender"];
  17. [msgDic setObject:[objMessage getDic] forKey:@"message"];
  18.  
  19. NSError *err = nil;
  20.  
  21. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:msgDic options:NSJSONWritingPrettyPrinted error:&err];
  22.  
  23. NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  24.  
  25. [message addBody:str];
  26.  
  27.  
  28. XMPPRoomMemoryStorage *roomMemoryStorage = [[XMPPRoomMemoryStorage alloc] init];
  29. XMPPRoom *xmppRoom = [[XMPPRoom alloc]
  30. initWithRoomStorage:roomMemoryStorage
  31. jid:recipient
  32. dispatchQueue:dispatch_get_main_queue()];
  33.  
  34. [xmppRoom sendMessageWithBody:str];
  35.  
  36. //
  37. // NSXMLElement *x = [NSXMLElement elementWithName:@"groupchat" xmlns:XMPPMUCNamespace];
  38. //
  39. // XMPPMessage* message = [[XMPPMessage alloc] initWithType:@"groupchat" to:recipient];
  40. // [message addChild:x];
  41. // [message addBody:str];
  42. //
  43. // [[APP_DELEGATE xmppStream] sendElement:message];
  44. }
Add Comment
Please, Sign In to add comment