I am developing a chat App using XMPPFrameWork
. Everything is working
perfectly but I'm stuck at obtaining number of unread messages. I've to show on
tableView
the number of messages that are not opened yet. How should I proceed
, any idea? I tried to show the mostRecentMessage
but it didn't work.
Any help would be appreciated.Thanks.
Asked
Active
Viewed 1,335 times
4

WannaBeGeek
- 979
- 14
- 32

Sushil Sharma
- 2,321
- 3
- 29
- 49
1 Answers
-1
There is an attribute named "unreadMessages" in "XMPPUserCoreDataStorageObject" in XMPP. Pass the FROM "jid" to get the corresponding user object and Increment "unreadMessages" value in below method in Appdelegate,
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
and update it in the same db again.Like,
XMPPUserCoreDataStorageObject *user = [self.xmppRosterStorage userForJID:[XMPPJID jidWithString:[NSString stringWithFormat:@"%@", [[[message fromStr] componentsSeparatedByString:@"/"]objectAtIndex:0] ]]
xmppStream:self.xmppStream
managedObjectContext:[self managedObjectContext_roster]];
NSNumber *number = user.unreadMessages;
int value = [number intValue];
number = [NSNumber numberWithInt:value + 1];
user.unreadMessages = number;
Then use the above code in any viewcontroller to retrieve unread message count.

Vijay Karthik
- 457
- 4
- 6
-
i have use your code..but it return user every time nil. – Balaji Gupta Feb 24 '16 at 08:43
-
it works for me..if the USER is nil,obviously the JID you passed is wrong or not in proper format..please check it. – Vijay Karthik Feb 25 '16 at 04:11
-
@VijayKarthik i had written above code but even if user read the message its shows in unread message count.... and when need to set it to 0.. how we know messages is read or not... – Ashok Londhe Sep 02 '16 at 15:40