Source/CBContactLastSeenPlugin.m
changeset 2707 6ed082e67639
parent 1946 866f1f27b315
     1.1 --- a/Source/CBContactLastSeenPlugin.m	Wed Apr 22 17:18:01 2009 -0700
     1.2 +++ b/Source/CBContactLastSeenPlugin.m	Sat Oct 31 13:13:20 2009 -0500
     1.3 @@ -18,6 +18,7 @@
     1.4  #import "CBContactLastSeenPlugin.h"
     1.5  #import <AIUtilities/AIDateFormatterAdditions.h>
     1.6  #import <Adium/AIListObject.h>
     1.7 +#import <Adium/AIMetaContact.h>
     1.8  
     1.9  #define PREF_GROUP_LAST_SEEN	@"Last Seen"
    1.10  #define KEY_LAST_SEEN_STATUS	@"Last Seen Status"
    1.11 @@ -36,58 +37,51 @@
    1.12  {
    1.13      //Install our tooltip entry
    1.14      [adium.interfaceController registerContactListTooltipEntry:self secondaryEntry:NO];
    1.15 -	
    1.16 -	//Install our observers
    1.17 -	[[NSNotificationCenter defaultCenter] addObserver:self
    1.18 -								   selector:@selector(statusUpdate:)
    1.19 -									   name:CONTACT_SEEN_ONLINE_YES
    1.20 -									 object:nil];
    1.21 -									 
    1.22 -	[[NSNotificationCenter defaultCenter] addObserver:self
    1.23 -								   selector:@selector(statusUpdate:)
    1.24 -									   name:CONTACT_STATUS_ONLINE_NO
    1.25 -									 object:nil];
    1.26  
    1.27 -	[[NSNotificationCenter defaultCenter] addObserver:self
    1.28 -								   selector:@selector(statusUpdate:)
    1.29 -									   name:CONTACT_SEEN_ONLINE_NO
    1.30 -									 object:nil];
    1.31 +	//Observe status changes
    1.32 +    [[AIContactObserverManager sharedManager] registerListObjectObserver:self];
    1.33  }
    1.34  
    1.35 -/*!
    1.36 - * @brief Contact status change notification
    1.37 - *
    1.38 - * @param notification A notificaiton with an AIListObject object and an eventID name
    1.39 - */
    1.40 -- (void)statusUpdate:(NSNotification *)notification
    1.41 +- (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
    1.42  {
    1.43 -	AIListObject	*inObject = [notification object];
    1.44 +	/* Update only for contacts whose online status has changed */
    1.45 +	if ([inObject isKindOfClass:[AIListContact class]]) {
    1.46 +		if ([inModifiedKeys containsObject:@"Online"]) {
    1.47 +			if (inObject.online) {
    1.48 +				//Either they are online, or we've come online. Either way, update both their status and the time
    1.49 +				[inObject setPreference:AILocalizedString(@"Online",nil)
    1.50 +								 forKey:KEY_LAST_SEEN_STATUS
    1.51 +								  group:PREF_GROUP_LAST_SEEN];
    1.52 +				
    1.53 +				[inObject setPreference:[NSDate date]
    1.54 +								 forKey:KEY_LAST_SEEN_DATE
    1.55 +								  group:PREF_GROUP_LAST_SEEN];
    1.56 +				
    1.57 +				
    1.58 +			} else {
    1.59 +				if (!silent) {
    1.60 +					//They've signed off, update their status and the time		
    1.61 +					[inObject setPreference:AILocalizedString(@"Signing off",nil)
    1.62 +									 forKey:KEY_LAST_SEEN_STATUS
    1.63 +									  group:PREF_GROUP_LAST_SEEN];
    1.64 +					
    1.65 +					[inObject setPreference:[NSDate date]
    1.66 +									 forKey:KEY_LAST_SEEN_DATE
    1.67 +									  group:PREF_GROUP_LAST_SEEN];	
    1.68 +				} else {
    1.69 +					/* Don't update the status, as we didn't see them signing off but
    1.70 +					 * rather we signed off (silent updates are grouped ones.)
    1.71 +					 * Just update the date.
    1.72 +					 */
    1.73 +					[inObject setPreference:[NSDate date]
    1.74 +									 forKey:KEY_LAST_SEEN_DATE
    1.75 +									  group:PREF_GROUP_LAST_SEEN];
    1.76 +				}
    1.77 +			}
    1.78 +		}
    1.79 +	}
    1.80  	
    1.81 -	//Either they are online, or we've come online. Either way, update both their status and the time
    1.82 -	if ([[notification name] isEqualToString:CONTACT_SEEN_ONLINE_YES]) {
    1.83 -		[inObject setPreference:AILocalizedString(@"Online",nil)
    1.84 -						 forKey:KEY_LAST_SEEN_STATUS
    1.85 -						  group:PREF_GROUP_LAST_SEEN];
    1.86 -
    1.87 -		[inObject setPreference:[NSDate date]
    1.88 -						 forKey:KEY_LAST_SEEN_DATE
    1.89 -						  group:PREF_GROUP_LAST_SEEN];
    1.90 -		
    1.91 -	//They've signed off, update their status and the time		
    1.92 -	} else if ([[notification name] isEqualToString:CONTACT_STATUS_ONLINE_NO]) {
    1.93 -		[inObject setPreference:AILocalizedString(@"Signing off",nil)
    1.94 -						 forKey:KEY_LAST_SEEN_STATUS
    1.95 -						  group:PREF_GROUP_LAST_SEEN];
    1.96 -
    1.97 -		[inObject setPreference:[NSDate date]
    1.98 -						 forKey:KEY_LAST_SEEN_DATE
    1.99 -						  group:PREF_GROUP_LAST_SEEN];	
   1.100 -
   1.101 -	//Don't update the status, just the date
   1.102 -	} else if ([[notification name] isEqualToString:CONTACT_SEEN_ONLINE_NO]) {
   1.103 -		[inObject setPreference:[NSDate date]
   1.104 -						 forKey:KEY_LAST_SEEN_DATE
   1.105 -						  group:PREF_GROUP_LAST_SEEN];	}
   1.106 +	return nil;	
   1.107  }
   1.108  
   1.109  #pragma mark Tooltip entry