Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roster doesn't update correctly upon removing user from contacts list #9

Closed
niha9088 opened this issue Jan 5, 2012 · 3 comments
Closed

Comments

@niha9088
Copy link

niha9088 commented Jan 5, 2012

Every time client get presence update this method got called and without the code which I commented below, upon removing user, the removed ( unsubscribed user ) still available, with the code uncommented, it works, but I was wondering will there is an update which create new section for pending user ( instead of throw all in offline section ? ). Thanks in advance.

  • (void)updateWithPresence:(XMPPPresence *)presence streamBareJidStr:(NSString *)streamBareJidStr
    {
    XMPPResourceCoreDataStorageObject *resource;
    resource = (XMPPResourceCoreDataStorageObject *)[self resourceForJID:[presence from]];
    if ([[presence type] isEqualToString:@"unavailable"]

// || [[presence type] isEqualToString:@"unsubscribed"]
// || [[presence type] isEqualToString:@"unsubscribe"]

    || [presence isErrorPresence])

{
if (resource)
{
[self removeResourcesObject:resource];
//[[self managedObjectContext] deleteObject:resource];
[[self managedObjectContext] processPendingChanges];
}
}
else
{
if(resource)
{
[resource updateWithPresence:presence];
}
else
{
XMPPResourceCoreDataStorageObject *newResource;
newResource = [XMPPResourceCoreDataStorageObject insertInManagedObjectContext:[self managedObjectContext]
withPresence:presence
streamBareJidStr:streamBareJidStr];
[self addResourcesObject:newResource];
}
}
[self recalculatePrimaryResource];
}

@niha9088
Copy link
Author

niha9088 commented Jan 6, 2012

Well, today I rechecked and find out the deletion still lurking around and upon re-added again the status won't update ONLY if target user go offline, so here the working code now, hope this help any1 facing the same problem.

NSArray *sortedResources = [[self allResources] sortedArrayUsingSelector:@selector(compare:)];

if ([[presence type] isEqualToString:@"unavailable"] 
    || [[presence type] isEqualToString:@"unsubscribed"]
    || [[presence type] isEqualToString:@"unsubscribe"]
    || [presence isErrorPresence])
{
    if (sortedResources)
    {
        for (XMPPResourceCoreDataStorageObject *anyResource in sortedResources)
        {
            [self removeResourcesObject:anyResource];
            [[self managedObjectContext] processPendingChanges];
        }
    }
}
else
{
    XMPPResourceCoreDataStorageObject *resource;
    if (sortedResources)
        resource = [sortedResources lastObject];

    if(resource)
    {
        [resource updateWithPresence:presence];
    }
    else
    {
        XMPPResourceCoreDataStorageObject *newResource;
        newResource = [XMPPResourceCoreDataStorageObject insertInManagedObjectContext:[self managedObjectContext]
                                                                   withPresence:presence
                                                               streamBareJidStr:streamBareJidStr];

        [self addResourcesObject:newResource];
    }
}

[self recalculatePrimaryResource];

@ObjColumnist
Copy link
Collaborator

I think this may have been the same issue as #186 , could you recheck to see if the XMPPRoster now works as expected?

@ObjColumnist
Copy link
Collaborator

Im going to close this as I believe it has been fixed, if not we can reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants