Patch from '''egladil''', with some tweaking by me, to improve out "last seen" monitoring to understand metacontacts and update the values accordingly. Thanks!
authorEvan Schoenberg
Sat Oct 31 13:13:20 2009 -0500 (2009-10-31)
changeset 27076ed082e67639
parent 2706 13898cc883cd
child 2708 9834b574299e
Patch from '''egladil''', with some tweaking by me, to improve out "last seen" monitoring to understand metacontacts and update the values accordingly. Thanks!

Fixes #11652
Source/CBContactLastSeenPlugin.h
Source/CBContactLastSeenPlugin.m
     1.1 --- a/Source/CBContactLastSeenPlugin.h	Sat Oct 31 12:31:33 2009 -0500
     1.2 +++ b/Source/CBContactLastSeenPlugin.h	Sat Oct 31 13:13:20 2009 -0500
     1.3 @@ -15,8 +15,9 @@
     1.4   */
     1.5  
     1.6  #import <Adium/AIInterfaceControllerProtocol.h>
     1.7 +#import <Adium/AIContactObserverManager.h>
     1.8  
     1.9 -@interface CBContactLastSeenPlugin : AIPlugin <AIContactListTooltipEntry> {
    1.10 +@interface CBContactLastSeenPlugin : AIPlugin <AIContactListTooltipEntry, AIListObjectObserver> {
    1.11  
    1.12  }
    1.13  
     2.1 --- a/Source/CBContactLastSeenPlugin.m	Sat Oct 31 12:31:33 2009 -0500
     2.2 +++ b/Source/CBContactLastSeenPlugin.m	Sat Oct 31 13:13:20 2009 -0500
     2.3 @@ -18,6 +18,7 @@
     2.4  #import "CBContactLastSeenPlugin.h"
     2.5  #import <AIUtilities/AIDateFormatterAdditions.h>
     2.6  #import <Adium/AIListObject.h>
     2.7 +#import <Adium/AIMetaContact.h>
     2.8  
     2.9  #define PREF_GROUP_LAST_SEEN	@"Last Seen"
    2.10  #define KEY_LAST_SEEN_STATUS	@"Last Seen Status"
    2.11 @@ -36,58 +37,51 @@
    2.12  {
    2.13      //Install our tooltip entry
    2.14      [adium.interfaceController registerContactListTooltipEntry:self secondaryEntry:NO];
    2.15 -	
    2.16 -	//Install our observers
    2.17 -	[[NSNotificationCenter defaultCenter] addObserver:self
    2.18 -								   selector:@selector(statusUpdate:)
    2.19 -									   name:CONTACT_SEEN_ONLINE_YES
    2.20 -									 object:nil];
    2.21 -									 
    2.22 -	[[NSNotificationCenter defaultCenter] addObserver:self
    2.23 -								   selector:@selector(statusUpdate:)
    2.24 -									   name:CONTACT_STATUS_ONLINE_NO
    2.25 -									 object:nil];
    2.26  
    2.27 -	[[NSNotificationCenter defaultCenter] addObserver:self
    2.28 -								   selector:@selector(statusUpdate:)
    2.29 -									   name:CONTACT_SEEN_ONLINE_NO
    2.30 -									 object:nil];
    2.31 +	//Observe status changes
    2.32 +    [[AIContactObserverManager sharedManager] registerListObjectObserver:self];
    2.33  }
    2.34  
    2.35 -/*!
    2.36 - * @brief Contact status change notification
    2.37 - *
    2.38 - * @param notification A notificaiton with an AIListObject object and an eventID name
    2.39 - */
    2.40 -- (void)statusUpdate:(NSNotification *)notification
    2.41 +- (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
    2.42  {
    2.43 -	AIListObject	*inObject = [notification object];
    2.44 +	/* Update only for contacts whose online status has changed */
    2.45 +	if ([inObject isKindOfClass:[AIListContact class]]) {
    2.46 +		if ([inModifiedKeys containsObject:@"Online"]) {
    2.47 +			if (inObject.online) {
    2.48 +				//Either they are online, or we've come online. Either way, update both their status and the time
    2.49 +				[inObject setPreference:AILocalizedString(@"Online",nil)
    2.50 +								 forKey:KEY_LAST_SEEN_STATUS
    2.51 +								  group:PREF_GROUP_LAST_SEEN];
    2.52 +				
    2.53 +				[inObject setPreference:[NSDate date]
    2.54 +								 forKey:KEY_LAST_SEEN_DATE
    2.55 +								  group:PREF_GROUP_LAST_SEEN];
    2.56 +				
    2.57 +				
    2.58 +			} else {
    2.59 +				if (!silent) {
    2.60 +					//They've signed off, update their status and the time		
    2.61 +					[inObject setPreference:AILocalizedString(@"Signing off",nil)
    2.62 +									 forKey:KEY_LAST_SEEN_STATUS
    2.63 +									  group:PREF_GROUP_LAST_SEEN];
    2.64 +					
    2.65 +					[inObject setPreference:[NSDate date]
    2.66 +									 forKey:KEY_LAST_SEEN_DATE
    2.67 +									  group:PREF_GROUP_LAST_SEEN];	
    2.68 +				} else {
    2.69 +					/* Don't update the status, as we didn't see them signing off but
    2.70 +					 * rather we signed off (silent updates are grouped ones.)
    2.71 +					 * Just update the date.
    2.72 +					 */
    2.73 +					[inObject setPreference:[NSDate date]
    2.74 +									 forKey:KEY_LAST_SEEN_DATE
    2.75 +									  group:PREF_GROUP_LAST_SEEN];
    2.76 +				}
    2.77 +			}
    2.78 +		}
    2.79 +	}
    2.80  	
    2.81 -	//Either they are online, or we've come online. Either way, update both their status and the time
    2.82 -	if ([[notification name] isEqualToString:CONTACT_SEEN_ONLINE_YES]) {
    2.83 -		[inObject setPreference:AILocalizedString(@"Online",nil)
    2.84 -						 forKey:KEY_LAST_SEEN_STATUS
    2.85 -						  group:PREF_GROUP_LAST_SEEN];
    2.86 -
    2.87 -		[inObject setPreference:[NSDate date]
    2.88 -						 forKey:KEY_LAST_SEEN_DATE
    2.89 -						  group:PREF_GROUP_LAST_SEEN];
    2.90 -		
    2.91 -	//They've signed off, update their status and the time		
    2.92 -	} else if ([[notification name] isEqualToString:CONTACT_STATUS_ONLINE_NO]) {
    2.93 -		[inObject setPreference:AILocalizedString(@"Signing off",nil)
    2.94 -						 forKey:KEY_LAST_SEEN_STATUS
    2.95 -						  group:PREF_GROUP_LAST_SEEN];
    2.96 -
    2.97 -		[inObject setPreference:[NSDate date]
    2.98 -						 forKey:KEY_LAST_SEEN_DATE
    2.99 -						  group:PREF_GROUP_LAST_SEEN];	
   2.100 -
   2.101 -	//Don't update the status, just the date
   2.102 -	} else if ([[notification name] isEqualToString:CONTACT_SEEN_ONLINE_NO]) {
   2.103 -		[inObject setPreference:[NSDate date]
   2.104 -						 forKey:KEY_LAST_SEEN_DATE
   2.105 -						  group:PREF_GROUP_LAST_SEEN];	}
   2.106 +	return nil;	
   2.107  }
   2.108  
   2.109  #pragma mark Tooltip entry