Permalink
Browse files

Use a dictionary for pending presence

* Also fix a horrible false negative
  • Loading branch information...
1 parent 329b4eb commit 6a50d0f7646d89d2fa67148cbe9b128691bd7344 @benlangfeld committed Jan 15, 2011
Showing with 15 additions and 19 deletions.
  1. +5 −5 TNStropheContact.j
  2. +10 −14 TNStropheRoster.j
View
@@ -231,11 +231,11 @@
*/
- (void)sendComposing
{
- if (!_isComposing)
- {
- [self sendStatus:@"composing"];
- _isComposing = YES;
- }
+ if (_isComposing)
+ return;
+
+ [self sendStatus:@"composing"];
+ _isComposing = YES;
}
/*! this allows to send "paused" information to a user.
View
@@ -28,8 +28,8 @@
*/
@implementation TNStropheRoster : TNStropheRosterBase
{
- CPArray _groups @accessors(getter=groups);
- CPArray _pendingPresence @accessors(getter=pendingPresence);
+ CPArray _groups @accessors(getter=groups);
+ CPDictionary _pendingPresence @accessors(getter=pendingPresence);
}
@@ -54,7 +54,7 @@
if (self = [super initWithConnection:aConnection])
{
_groups = [CPArray array];
- _pendingPresence = [CPArray array];
+ _pendingPresence = [CPDictionary dictionary];
var rosterPushParams = [CPDictionary dictionaryWithObjectsAndKeys:@"iq", @"name", Strophe.NS.ROSTER, @"namespace", @"type", @"set"],
presenceParams = [CPDictionary dictionaryWithObjectsAndKeys:@"presence", @"name", [[_connection JID] bare], @"to"];
[_connection registerSelector:@selector(_didReceiveRosterPush:) ofObject:self withDict:rosterPushParams];
@@ -166,24 +166,20 @@
if ([self containsJID:[aStanza from]])
[[self contactWithJID:[aStanza from]] _didReceivePresence:aStanza];
else
- [_pendingPresence addObject:aStanza];
+ {
+ var from = [aStanza fromBare];
+ if (![_pendingPresence containsKey:from])
+ [_pendingPresence setValue:[CPArray array] forKey:from];
+ [[_pendingPresence valueForKey:from] addObject:aStanza];
+ }
}
return YES;
}
-/*! TODO: use a dictionnary for pending presence
-*/
- (CPArray)pendingPresenceForJID:(TNStropheJID)aJID
{
- var temp = [CPArray array];
- for (var i = 0; i < [_pendingPresence count]; i++)
- {
- var presence = [_pendingPresence objectAtIndex:i];
- if ([[presence from] bareEquals:aJID])
- [temp addObject:presence];
- }
- return temp;
+ return [_pendingPresence valueForKey:[aJID bare]];
}

0 comments on commit 6a50d0f

Please sign in to comment.