iOS: XMPP: Message Archiving for Group Chat Message - ios

All one-one chat is send with Message Type as Chat.
Thus the Message Archiving technique (shown below) worked fine for me to save/retrieve chat history.
// Setup message archiving
xmppMessageArchivingStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
xmppMessageArchiving = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:xmppMessageArchivingStorage];
[xmppMessageArchiving setClientSideMessageArchivingOnly:YES];
// Activate xmpp modules
[xmppMessageArchiving activate:xmppStream];
// Add delegate
[xmppMessageArchiving addDelegate:self delegateQueue:dispatch_get_main_queue()];
However for Group Chat, the message type sent is "groupchat"
This will not be archived by the XMPPMessageArchivingCoreDataStorage
Can someone please guide me as to how I can achieve the Message Archiving for Group Chat Message.

This is the Series of Stanza that you will need to send to get Archived Messages. For more detail you can checkout http://xmpp.org/extensions/xep-0136.html
REQ
<iq type='get' id='mrug_sender#staging.openfire.com'>
<list xmlns='urn:xmpp:archive'
with='mrug_target_155#staging.openfire.com'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>6900</max>
</set>
</list>
</iq>
RES
<iq type="result" id="mrug_sender#staging.openfire.com" to="mrug_sender#staging.openfire.com/Psi">
<list xmlns="urn:xmpp:archive">
<chat with="mrug_target_155#staging.openfire.com" start="2014-06-07T06:52:26.041Z"/>
<chat with="mrug_target_155#staging.openfire.com" start="2014-06-07T07:06:53.372Z"/>
<set xmlns="http://jabber.org/protocol/rsm">
<first index="0">866</first>
<last>867</last>
<count>2</count>
</set>
</list>
</iq>
REQ
<iq type='get' id='mrug_sender#staging.openfire.com'>
<retrieve xmlns='urn:xmpp:archive' with='mrug_target_155#staging.openfire.com' start='2014-06-07T06:52:26.041Z'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>8000</max>
</set>
</retrieve>
</iq>
RES
<iq type="result" id="mrug_sender#staging.openfire.com" to="mrug_sender#staging.openfire.com/Psi">
<chat xmlns="urn:xmpp:archive" with="mrug_target_155#staging.openfire.com" start="2014-06-07T06:52:26.041Z">
<from secs="0" jid="mrug_target_155#staging.openfire.com">
<body>Wow !! This is Archived Message</body>
</from>
<set xmlns="http://jabber.org/protocol/rsm">
<first index="0">0</first>
<last>0</last>
<count>1</count>
</set>
</chat>
</iq>
To Fetch List of all Conversations
<iq type='get' id='mrug_sender#staging.openfire.com'>
<list xmlns='urn:xmpp:archive'>
<set xmlns='http://jabber.org/protocol/rsm'>
<max>6900</max>
</set>
</list>
</iq>

You can easily get archive messages from xmpp core database. Use Below code.
XMPPMessageArchivingCoreDataStorage *_xmppMsgStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [_xmppMsgStorage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:#"XMPPMessageArchiving_Message_CoreDataObject"
inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
//[request setFetchLimit:20];
NSError *error;
NSString *predicateFrmt = #"bareJidStr == %#";
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFrmt, [NSString stringWithFormat:#"%#%#",GroupName,GROUP_CHAT_DOMAIN]];
request.predicate = predicate;
NSArray *messages = [moc executeFetchRequest:request error:&error];

Related

remote-server-not-found (error code="404") XMPP

I am getting 404 error while adding user to contact using roster
Here is my code
NSString * buddyNameJID = #"vinod#192.168.1.45";
XMPPJID *jid = [XMPPJID jidWithString:buddyNameJID];
[[appDelegate xmppRoster] addUser:jid withNickname:#"vinod"];
[[appDelegate xmppRoster]subscribePresenceToUser:jid];
after this getting error
<presence xmlns="jabber:client" to="kishore#eswks45/5r493h8jj8" from="vinod#192.168.1.45" type="error"><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></presence>
I have checked so many sites so many question but didn't get any solution

How to register user using xmpp/jabber in ios?

iPhone Chat app using xmpp/jabber.
This method i am not able register on server. it gives me "403" error.
Can anyone help me, how can i create a new account on server using xmpp/jabber in ios?
here my code :
NSString *username = loginField.text;
NSString *password = passwordField.text;
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
del.xmppStream.myJID = [XMPPJID jidWithString:username];
NSLog(#"Does supports registration %hhd ",del.xmppStream.supportsInBandRegistration );
NSLog(#"Attempting registration for username %#",del.xmppStream.myJID.bare);
if (del.xmppStream.supportsInBandRegistration)
{
NSError *error = nil;
if (![del.xmppStream registerWithPassword:password error:&error])
{
NSLog(#"Oops, I forgot something: %#", error);
}
else
{
NSLog(#"No Error");
}
}
and i got error
ERROR :-
<iq xmlns="jabber:client" from="username#Testlocalhost" to="username#Testlocalhost/40751035661420464079722458" type="error">
<query xmlns="jabber:iq:register">
<username>newusername</username>
<password>userpassword</password>
</query>
<error code="403" type="auth">
<forbidden xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>

Cant fetch detail of XMPPRoom from the server XMPP Framework

I have created a MembersOnly, Persistant Room. In which I have invited multiple occupants.
Now I want to fetch detail of room for the user which was invited by creator.
I tried this code :
XMPP requirement :
<iq from='hag66#shakespeare.lit/pda'
id='ik3vs715'
to='coven#chat.shakespeare.lit'
type='get'>
<query xmlns='http://jabber.org/protocol/disco#info'/>
</iq>
iOS code to call the from iOS
NSXMLElement *query = [NSXMLElement elementWithName:#"query" xmlns:#"http://jabber.org/protocol/disco#info"];//
NSString *iqID = [[appDelegate xmppStream] generateUUID];
XMPPJID *jID = self.room.roomJID;
XMPPIQ *element = [XMPPIQ iqWithType:#"get" to:jID elementID:iqID child:query];
[element addAttributeWithName:#"from" stringValue:[[[appDelegate xmppStream] myJID] full]];
[[appDelegate xmppStream] fetchInformationForGivenIQ:element];
This should provide me this kinda result :
<iq from='coven#chat.shakespeare.lit'
id='ik3vs715'
to='hag66#shakespeare.lit/pda'
type='result'>
<query xmlns='http://jabber.org/protocol/disco#info'>
<identity
category='conference'
name='A Dark Cave'
type='text'/>
<feature var='http://jabber.org/protocol/muc'/>
<feature var='muc_passwordprotected'/>
<feature var='muc_hidden'/>
<feature var='muc_temporary'/>
<feature var='muc_open'/>
<feature var='muc_unmoderated'/>
<feature var='muc_nonanonymous'/>
</query>
</iq>
But I am getting this result :
<iq xmlns="jabber:client" type="result" id="some ID" from="Group-ID" to="My Full JabberID">
<query xmlns="http://jabber.org/protocol/disco#info">
<feature var="http://jabber.org/protocol/disco#info">
</feature>
</query>
</iq>
Can any one help me what I am doing wrong.
THanks in advance.
If you want to get the room info , you can call the mothod on XMPPRoom
- (void)fetchConfigurationForm;
Then , get the room info in the room's Delegate method
- (void)xmppRoom:(XMPPRoom *)sender didFetchConfigurationForm:(NSXMLElement *)configForm;

FileTransfer by using XMPPFrameWork XEP-0065 and XEP-0096 in IOS

i have a lot of search regarding file transfer in IOS. I am using XEP-0065 and XEP-0096 for FileTransfer . Code which i am using :
- (void)sendToOtherDevice:(NSData *)fileData receiverJid:(NSString *)receiverJid
{
NSString *s = [NSString stringWithFormat:#"%#/Smack",receiverJid];
XMPPJID *jid = [XMPPJID jidWithString:s];
// XMPPSIFileTransfer * sifiletransfer = [[XMPPSIFileTransfer alloc] initiateFileTransferTo:jid withData:fileData];
XMPPSIFileTransfer *sifiletransfer = [[XMPPSIFileTransfer alloc] init];
[sifiletransfer initiateFileTransferTo:jid withData:fileData];
//XMPPJID *jid = [XMPPJID jidWithString:receiverJid];
NSString *jabbarID = [[[[self appDelegate] xmppStream] myJID] bare];
XMPPJID *senderjid = [XMPPJID jidWithString:jabbarID];
//[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:s, nil]];
// [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:s,jabbarID, nil]];
[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain,senderjid.domain, nil]];
// [TURNSocket setProxyCandidates:[NSArray arrayWithObjects:jid.domain, nil]];
//[TURNSocket setProxyCandidates:[NSArray arrayWithObjects:#"111.11.111.111", nil]];
TURNSocket *socket1 = [[TURNSocket alloc] initWithStream:[self xmppStream] toJID:jid];
// [turnSockets addObject:turnSocket];
[socket1 startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
-(void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
{
[socket writeData:photoData withTimeout:60.0f tag:0];
[socket disconnectAfterWriting];
}
- (void)turnSocketDidFail:(TURNSocket *)sender
{
NSLog(#"Couldn't set up bytestream for file transfer!");
}
and i found following XML stanzas :
2013-11-22 14:23:08:990 iPhoneXMPP[1434:6417] SEND: <iq type="get" to="lava1" id="A5D91010-C182-4BCB-A989-5DFF2C0B6AE8"><query xmlns="http://jabber.org/protocol/disco#items"/></iq>
2013-11-22 14:23:09:290 iPhoneXMPP[1434:6a07] RECV: <iq xmlns="jabber:client" type="error" id="A5D91010-C182-4BCB-A989-5DFF2C0B6AE8" to="lava#example.com/368c5070" from="lava1"><query xmlns="http://jabber.org/protocol/disco#items"/><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
2013-11-22 14:23:09:291 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:294 iPhoneXMPP[1434:6417] SEND: <iq type="get" to="example.com" id="7EB43464-63BC-4ADF-8B98-A1A15AB51DB3"><query xmlns="http://jabber.org/protocol/disco#items"/></iq>
2013-11-22 14:23:09:493 iPhoneXMPP[1434:400b] RECV: <iq xmlns="jabber:client" type="result" id="7EB43464-63BC-4ADF-8B98-A1A15AB51DB3" from="example.com" to="lava#example.com/368c5070"><query xmlns="http://jabber.org/protocol/disco#items"><item jid="search.example.com" name="User Search"/><item jid="conference.example.com" name="Public Chatrooms"/><item jid="proxy.example.com" name="Socks 5 Bytestreams Proxy"/><item jid="pubsub.example.com" name="Publish-Subscribe service"/></query></iq>
2013-11-22 14:23:09:494 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:504 iPhoneXMPP[1434:6417] SEND: <iq type="get" to="proxy.example.com" id="0DFDF89F-29DE-4477-AF5E-B67387DD973C"><query xmlns="http://jabber.org/protocol/disco#info"/></iq>
2013-11-22 14:23:09:698 iPhoneXMPP[1434:400b] RECV: <iq xmlns="jabber:client" type="result" id="0DFDF89F-29DE-4477-AF5E-B67387DD973C" from="proxy.example.com" to="lava#example.com/368c5070"><query xmlns="http://jabber.org/protocol/disco#info"><identity category="proxy" name="SOCKS5 Bytestreams Service" type="bytestreams"/><feature var="http://jabber.org/protocol/bytestreams"/><feature var="http://jabber.org/protocol/disco#info"/></query></iq>
2013-11-22 14:23:09:699 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:701 iPhoneXMPP[1434:6a07] SEND: <iq type="get" to="proxy.example.com" id="63C74776-93A4-4C97-8CFC-63C57494E4F6"><query xmlns="http://jabber.org/protocol/bytestreams"/></iq>
2013-11-22 14:23:09:903 iPhoneXMPP[1434:6417] RECV: <iq xmlns="jabber:client" type="result" id="63C74776-93A4-4C97-8CFC-63C57494E4F6" from="proxy.example.com" to="lava#example.com/368c5070"><query xmlns="http://jabber.org/protocol/bytestreams"><streamhost jid="proxy.example.com" host="10.128.63.123" port="7777"/></query></iq>
2013-11-22 14:23:09:904 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:09:906 iPhoneXMPP[1434:6417] SEND: <iq type="set" to="lava1/Smack" id="BB87F255-51AF-49F1-B700-D009BFF8A057"><query xmlns="http://jabber.org/protocol/bytestreams" sid="BB87F255-51AF-49F1-B700-D009BFF8A057" mode="tcp"><streamhost xmlns="http://jabber.org/protocol/bytestreams" jid="proxy.example.com" host="10.128.63.123" port="7777"/></query></iq>
2013-11-22 14:23:10:210 iPhoneXMPP[1434:6a07] RECV: <iq xmlns="jabber:client" type="error" id="BB87F255-51AF-49F1-B700-D009BFF8A057" to="lava#example.com/368c5070" from="lava1/Smack"><query xmlns="http://jabber.org/protocol/bytestreams" sid="BB87F255-51AF-49F1-B700-D009BFF8A057" mode="tcp"><streamhost jid="proxy.example.com" host="10.128.63.123" port="7777"/></query><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>
2013-11-22 14:23:10:212 iPhoneXMPP[1434:60b] iPhoneXMPPAppDelegate: xmppStream:didReceiveIQ:
2013-11-22 14:23:10.213 iPhoneXMPP[1434:60b] Couldn't set up bytestream for file transfer!
Please Let me know what i am doing wrong. How Can i use XEP-0096 for FileTransfer.

Quickblox chat message didn't sent after reconnect

I have problem with sending messages after reconnecting with the quickblox server. The user is automatically logout in the middle of chatting with the others and after reconnect with the server again, the chat messages is not sending. But the log shown it was sent , not showing the receive log. The reconnect code works fine but cannot chat anymore.
when it was working as fine,
2013-10-12 10:48:37.033 football365[1000:8517] -[QBChat xmppStream:didSendMessage:] -> Message: <message to="4099_000000001000000003#muc.chat.quickblox.com" id="7" type="groupchat"><body>hello</body></message>
2013-10-12 10:48:37.463 football365[1000:8517] -[QBChat xmppRoom:didReceiveMessage:fromNick:] -> message: <message xmlns="jabber:client" type="groupchat" to="578338-4099#chat.quickblox.com/tigase-11258" from="4099_000000001000000003#muc.chat.quickblox.com/578338"><body>hello</body></message> fromNick: 578338
when message only sent, the received log is not shown.
2013-10-12 10:48:37.033 football365[1000:8517] -[QBChat xmppStream:didSendMessage:] -> Message: <message to="4099_000000001000000003#muc.chat.quickblox.com" id="7" type="groupchat"><body>hello</body></message>
the login code in DataManager.m.
- (void)chatLogin{
QBASessionCreationRequest *extendedAuthRequest = [QBASessionCreationRequest request];
extendedAuthRequest.userLogin = #"userid";
extendedAuthRequest.userPassword = #"password";
[QBAuth createSessionWithExtendedRequest:extendedAuthRequest delegate:self];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
- (void)completedWithResult:(Result *)result{
if(result.success && [result isKindOfClass:QBAAuthSessionCreationResult.class]){
QBAAuthSessionCreationResult *res = (QBAAuthSessionCreationResult *)result;
currentUser = [QBUUser user];
currentUser.ID = res.session.userID;
currentUser.password = #"password";
[[DataManager shared] setCurrentUser: currentUser];
[QBChat instance].delegate = self;
[[QBChat instance] loginWithUser:currentUser];
}
}
reconnect code in chatViewController.m,
-(void)chatDidFailWithError:(int)code
{
[[QBChat instance] loginWithUser:currentUser];
}

Resources