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

XMPPRoomMemoryStorage - Fails to update presence of XMPPRoomOccupantMemoryStorageObject, when the occupant leaves the chat room #510

Open
nageshrudrappa opened this issue Mar 20, 2015 · 1 comment

Comments

@nageshrudrappa
Copy link

In the method mentioned below, the presence of XMPPRoomOccupantMemoryStorageObject is not updated when the occupant leaves the chat room (i,e when the presence type is "unavailable")

Class: XMPPRoomMemoryStorage.m
Method: - (void)handlePresence:(XMPPPresence *)presence room:(XMPPRoom *)room { }

Added the missing line to update the occupant presence within the updated method
//Missing Line**
[occupant updateWithPresence:presence];
//
Missing Line**

Updated method:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

pragma mark XMPPRoomStorage Protocol

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  • (void)handlePresence:(XMPPPresence *)presence room:(XMPPRoom *)room
    {
    XMPPLogTrace();
    AssertParentQueue();

    XMPPJID *from = [presence from];

    if ([[presence type] isEqualToString:@"unavailable"])
    {
    XMPPRoomOccupantMemoryStorageObject occupant = occupantsDict[from];
    if (occupant)
    {
    // Occupant did leave - remove
    //
    _Missing Line_
    [occupant updateWithPresence:presence];
    //***Missing Line**

        NSUInteger index = [occupantsArray indexOfObjectIdenticalTo:occupant];
    
        [occupantsArray removeObjectAtIndex:index];
        [occupantsDict removeObjectForKey:from];
    
        // Notify delegate(s)
    
        XMPPRoomOccupantMemoryStorageObject *occupantCopy = [occupant copy];
        NSArray *occupantsCopy = [[NSArray alloc] initWithArray:occupantsArray copyItems:YES];
    
        [[self multicastDelegate] xmppRoomMemoryStorage:self
                                       occupantDidLeave:occupantCopy
                                                atIndex:index
                                              fromArray:occupantsCopy];
    }
    

    }
    else
    {
    XMPPRoomOccupantMemoryStorageObject *occupant = occupantsDict[from];
    if (occupant == nil)
    {
    // Occupant did join - add

        occupant = [[self.occupantClass alloc] initWithPresence:presence];
    
        NSUInteger index = [self insertOccupant:occupant];
        occupantsDict[from] = occupant;
    
        // Notify delegate(s)
    
        XMPPRoomOccupantMemoryStorageObject *occupantCopy = [occupant copy];
        NSArray *occupantsCopy = [[NSArray alloc] initWithArray:occupantsArray copyItems:YES];
    
        [[self multicastDelegate] xmppRoomMemoryStorage:self
                                        occupantDidJoin:occupantCopy
                                                atIndex:index
                                                inArray:occupantsCopy];
    }
    else
    {
        // Occupant did update - move
    
        [occupant updateWithPresence:presence];
    
        NSUInteger oldIndex = [occupantsArray indexOfObjectIdenticalTo:occupant];
        [occupantsArray removeObjectAtIndex:oldIndex];
        NSUInteger newIndex = [self insertOccupant:occupant];
    
        // Notify delegate(s)
    
        XMPPRoomOccupantMemoryStorageObject *occupantCopy = [occupant copy];
        NSArray *occupantsCopy = [[NSArray alloc] initWithArray:occupantsArray copyItems:YES];
    
        [[self multicastDelegate] xmppRoomMemoryStorage:self
                                      occupantDidUpdate:occupantCopy
                                              fromIndex:oldIndex
                                                toIndex:newIndex
                                                inArray:occupantsCopy];
    }
    

    }
    }

Please let me know if the update is valid or not.

@nageshrudrappa
Copy link
Author

Need help.

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

1 participant