ios - How to get the Message read/unread report in xmpp frame work? -


hi developing chat app using xmpp framework.chatting working fine how message delivery in whatsapp, facebook etc.,i searched found document here code upto implemented

in connect method

xmppmessagedeliveryreceipts* xmppmessagedeliveryrecipts = [[xmppmessagedeliveryreceipts alloc] initwithdispatchqueue:dispatch_get_main_queue()]; xmppmessagedeliveryrecipts.autosendmessagedeliveryreceipts = yes; xmppmessagedeliveryrecipts.autosendmessagedeliveryrequests = yes; [xmppmessagedeliveryrecipts activate:self.xmppstream]; 

added lines in sending messsage method

nsxmlelement *request = [nsxmlelement elementwithname:@"request"];  [request addattributewithname:@"xmlns" stringvalue:@"urn:xmpp:receipts"];  [message addchild:request]; [message addchild:body]; 

but message delivered or not how can check deliverd message read or not have seen these extentions xep-0184,xep-0333 don't have idea implement read /unread messages. please me

if want read receipts instead of sending auto message delivery receipts, send whenever user reads message. each message has it's corresponding message_id. use message_id send delivery receipt particular message has been read. so, comment following line

//xmppmessagedeliveryrecipts.autosendmessagedeliveryreceipts = yes; 

i solved problem adding 'chatstatus' attribute in message entity. sender have kept value of chatstatus sent, unsent, or received(received other side or not). receiver side have kept values read or unread(have read message or not, unread message send read receipts).

on click of send button:

//save message entity   nsmutabledictionary *m = [[nsmutabledictionary alloc] init]; [m setobject: message_body forkey:@"message_body"]; [m setobject:messageid forkey:@"message_id"]; [m setobject:@"yes" forkey:@"isoutgoing"]; [m setobject:datestring forkey:@"date"]; [m setobject:timestring forkey:@"time"]; [m setobject:[nsdate date] forkey:@"timestamp"]; [m setobject:yourid forkey:@"from"]; [m setobject:toid forkey:@"to"];  if (!is_internetavailable]) {  [m setobject:unsent forkey:@"chatstatus"]; } else{  [m setobject:sent forkey:@"chatstatus"]; } [[coredatamethods sharedcoredatamethods] saveusermessage:m]; } 

in cellforrowatindexpath:

if ([message isoutgoing]) {//if have sent message          // mine bubble         if ([[messagedict valueforkey:@"chatstatus"] isequaltostring:unsent]) {             //set unsent image         }         else if ([[messagedict valueforkey:@"chatstatus"] isequaltostring:sent]){             //set sent image         }         else if ([[messagedict valueforkey:@"chatstatus"] isequaltostring:received]){           //set received image         }     }     else{         // other bubble , notify them have read message if unread/new message          if ([[messagedict valueforkey:@"chatstatus"] isequaltostring:unread]) {              //send read receipt                 nsxmlelement *receivedelement = [nsxmlelement elementwithname:@"received" xmlns:@"urn:xmpp:receipts"];                  nsxmlelement *message = [nsxmlelement elementwithname:@"message" xmlns:@"jabber:client"];                 [message addattributewithname:@"to" stringvalue:toid];                 [message addattributewithname:@"from" stringvalue:fromid];                 [receivedelement addattributewithname:@"id" stringvalue:[messagedict valueforkey:@"message_id"]];                 [message addchild:receivedelement];                  //xmppmessage *generatedreceiptresponse = [[messagedict valueforkey:@"xmppmessage"] generatereceiptresponse];                 [[[kappdelegate xmpphandler] xmppstream] sendelement:message];                  // update message entity                 [self updatechatstatus:read withmessageid:[messagedict valueforkey:@"message_id"]];         }     } 

and when receive delivery receipt in didreceivemessage, update chatstatus received

- (void)xmppstream:(xmppstream *)sender didreceivemessage:(xmppmessage *)message{  if ([message hasreceiptresponse]) {//message read //update database message entity  [self updatechatstatus:@"received" withmessageid:[message receiptresponseid]]; } } 

you set values of chatstatus per requirement. unsent messages have set sent in didsendmessage delegate.

hope helps!!


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -