robbiehanson / XMPPFramework

An XMPP Framework in Objective-C for Mac and iOS
Other
5.91k stars 2.09k forks source link

Getting unread messages count returns 0 #605

Open orkhanalizade opened 9 years ago

orkhanalizade commented 9 years ago

I'm trying to get unread messages value, but it returns me 0. I present my code:

public class func userFromRosterAtIndexPath(indexPath indexPath: NSIndexPath) -> XMPPUserCoreDataStorageObject {
    return sharedInstance.fetchedResultsController()!.objectAtIndexPath(indexPath) as! XMPPUserCoreDataStorageObject
}

let user = OneRoster.userFromRosterAtIndexPath(indexPath: indexPath)
print(user.unreadMessages.intValue)

and it returns me 0. Why? Can anyone help me to fix it?

alberttai1 commented 8 years ago

i'm having the same problem, does anyone have a sol. for this?

nawar commented 5 years ago

You'll need to update the unreadMessage yourself after you receive the message. However, this won't save it to the XMPPRoster CoreData because you are probably reading user info on the MainThreadManagedContext which is not suitable for saving.