Source/DCMessageContextDisplayPlugin.m
changeset 2820 37f86ef91f64
parent 2798 13548a608dd3
child 2821 fa988de96a94
     1.1 --- a/Source/DCMessageContextDisplayPlugin.m	Mon Nov 23 00:38:57 2009 -0500
     1.2 +++ b/Source/DCMessageContextDisplayPlugin.m	Wed Nov 25 22:28:47 2009 -0500
     1.3 @@ -22,9 +22,6 @@
     1.4  #import <Adium/AIContentContext.h>
     1.5  #import <Adium/AIService.h>
     1.6  
     1.7 -//#import "SMSQLiteLoggerPlugin.h"
     1.8 -//#import "AICoreComponentLoader.h"
     1.9 -
    1.10  //Old school
    1.11  #import <Adium/AIListContact.h>
    1.12  #import <AIUtilities/AIAttributedStringAdditions.h>
    1.13 @@ -53,9 +50,6 @@
    1.14  @interface DCMessageContextDisplayPlugin ()
    1.15  - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
    1.16  							object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime;
    1.17 -- (void)old_preferencesChangedForGroup:(NSString *)group key:(NSString *)key
    1.18 -								object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime;
    1.19 -- (BOOL)contextShouldBeDisplayed:(NSCalendarDate *)inDate;
    1.20  - (NSArray *)contextForChat:(AIChat *)chat;
    1.21  @end
    1.22  
    1.23 @@ -72,14 +66,6 @@
    1.24      [adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:CONTEXT_DISPLAY_DEFAULTS
    1.25  																		forClass:[self class]] 
    1.26  										  forGroup:PREF_GROUP_CONTEXT_DISPLAY];
    1.27 -		
    1.28 -	//Obtain the default preferences and use them - Adium 1.1 experiment to see if people use these prefs
    1.29 -	[self old_preferencesChangedForGroup:PREF_GROUP_CONTEXT_DISPLAY
    1.30 -								 key:nil
    1.31 -							  object:nil
    1.32 -					  preferenceDict:[NSDictionary dictionaryNamed:CONTEXT_DISPLAY_DEFAULTS
    1.33 -														  forClass:[self class]]
    1.34 -						   firstTime:YES];
    1.35  	
    1.36  	//Observe preference changes for whether or not to display message history
    1.37  	[adium.preferenceController registerPreferenceObserver:self forGroup:PREF_GROUP_CONTEXT_DISPLAY];
    1.38 @@ -117,23 +103,6 @@
    1.39  		}
    1.40  	}
    1.41  }
    1.42 -/**
    1.43 - * @brief Preferences for when to display history changed
    1.44 - *
    1.45 - * Only change our preferences in response to global preference notifications; specific objects use this group as well.
    1.46 - */
    1.47 -- (void)old_preferencesChangedForGroup:(NSString *)group key:(NSString *)key
    1.48 -							object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
    1.49 -{
    1.50 -	if (!object) {
    1.51 -		haveTalkedDays = [[prefDict objectForKey:KEY_HAVE_TALKED_DAYS] integerValue];
    1.52 -		haveNotTalkedDays = [[prefDict objectForKey:KEY_HAVE_NOT_TALKED_DAYS] integerValue];
    1.53 -		displayMode = [[prefDict objectForKey:KEY_DISPLAY_MODE] integerValue];
    1.54 -		
    1.55 -		haveTalkedUnits = [[prefDict objectForKey:KEY_HAVE_TALKED_UNITS] integerValue];
    1.56 -		haveNotTalkedUnits = [[prefDict objectForKey:KEY_HAVE_NOT_TALKED_UNITS] integerValue];		
    1.57 -	}
    1.58 -}
    1.59  
    1.60  /**
    1.61   * @brief Retrieve and display in-window message history
    1.62 @@ -147,75 +116,23 @@
    1.63  	NSArray	*context = [self contextForChat:chat];
    1.64  
    1.65  	if (context && [context count] > 0 && shouldDisplay) {
    1.66 -		//Check if the history fits the date restrictions
    1.67 +		AIContentContext	*contextMessage;
    1.68 +
    1.69 +		for(contextMessage in context) {
    1.70 +			/* Don't display immediately, so the message view can aggregate multiple message history items.
    1.71 +			 * As required, we post Content_ChatDidFinishAddingUntrackedContent when finished adding. */
    1.72 +			[contextMessage setDisplayContentImmediately:NO];
    1.73  		
    1.74 -		//The most recent message is what determines whether we have "chatted in the last X days", "not chatted in the last X days", etc.
    1.75 -		NSCalendarDate *mostRecentMessage = [[(AIContentContext *)[context lastObject] date] dateWithCalendarFormat:nil timeZone:nil];
    1.76 -		if ([self contextShouldBeDisplayed:mostRecentMessage]) {
    1.77 -			AIContentContext	*contextMessage;
    1.78 +			[adium.contentController displayContentObject:contextMessage
    1.79 +										usingContentFilters:YES
    1.80 +												immediately:YES];
    1.81 +		}
    1.82  
    1.83 -			for(contextMessage in context) {
    1.84 -				/* Don't display immediately, so the message view can aggregate multiple message history items.
    1.85 -				 * As required, we post Content_ChatDidFinishAddingUntrackedContent when finished adding. */
    1.86 -				[contextMessage setDisplayContentImmediately:NO];
    1.87 -			
    1.88 -				[adium.contentController displayContentObject:contextMessage
    1.89 -											usingContentFilters:YES
    1.90 -													immediately:YES];
    1.91 -			}
    1.92 -
    1.93 -			//We finished adding untracked content
    1.94 -			[[NSNotificationCenter defaultCenter] postNotificationName:Content_ChatDidFinishAddingUntrackedContent
    1.95 -												  	  object:chat];
    1.96 -		}
    1.97 +		//We finished adding untracked content
    1.98 +		[[NSNotificationCenter defaultCenter] postNotificationName:Content_ChatDidFinishAddingUntrackedContent
    1.99 +												  object:chat];
   1.100  	}
   1.101  }
   1.102 -
   1.103 -/**
   1.104 - * @brief Does a specified date match our criteria for display?
   1.105 - *
   1.106 - * The date passed should be the date of the _most recent_ stored message history item
   1.107 - *
   1.108 - * @result YES if the mesage history should be displayed
   1.109 - */
   1.110 -- (BOOL)contextShouldBeDisplayed:(NSCalendarDate *)inDate
   1.111 -{
   1.112 -	BOOL dateIsGood = YES;
   1.113 -	NSInteger thresholdDays = 0;
   1.114 -	NSInteger thresholdHours = 0;
   1.115 -	
   1.116 -	if (displayMode != MODE_ALWAYS) {
   1.117 -		
   1.118 -		if (displayMode == MODE_HAVE_TALKED) {
   1.119 -			if (haveTalkedUnits == UNIT_DAYS)
   1.120 -				thresholdDays = haveTalkedDays;
   1.121 -			
   1.122 -			else if (haveTalkedUnits == UNIT_HOURS)
   1.123 -				thresholdHours = haveTalkedDays;
   1.124 -			
   1.125 -		} else if (displayMode == MODE_HAVE_NOT_TALKED) {
   1.126 -			if ( haveTalkedUnits == UNIT_DAYS )
   1.127 -				thresholdDays = haveNotTalkedDays;
   1.128 -			else if (haveTalkedUnits == UNIT_HOURS)
   1.129 -				thresholdHours = haveNotTalkedDays;
   1.130 -		}
   1.131 -		
   1.132 -		// Take the most recent message's date, add our limits to it
   1.133 -		// See if the new date is earlier or later than today's date
   1.134 -		NSCalendarDate *newDate = [inDate dateByAddingYears:0 months:0 days:thresholdDays hours:thresholdHours minutes:0 seconds:0];
   1.135 -
   1.136 -		NSComparisonResult comparison = [newDate compare:[NSDate date]];
   1.137 -		
   1.138 -		if (((displayMode == MODE_HAVE_TALKED) && (comparison == NSOrderedAscending)) ||
   1.139 -			((displayMode == MODE_HAVE_NOT_TALKED) && (comparison == NSOrderedDescending)) ) {
   1.140 -			dateIsGood = NO;
   1.141 -		}
   1.142 -	}
   1.143 -	
   1.144 -	return dateIsGood;
   1.145 -}
   1.146 -
   1.147 -static NSInteger linesLeftToFind = 0;
   1.148  /*!
   1.149   * @brief Retrieve the message history for a particular chat
   1.150   *
   1.151 @@ -226,6 +143,8 @@
   1.152  	//If there's no log there, there's no message history. Bail out.
   1.153  	NSArray *logPaths = [AILoggerPlugin sortedArrayOfLogFilesForChat:chat];
   1.154  	if(!logPaths) return nil;
   1.155 +	
   1.156 +	NSInteger linesLeftToFind = 0;
   1.157  
   1.158  	AIHTMLDecoder *decoder = [AIHTMLDecoder decoder];
   1.159  
   1.160 @@ -237,7 +156,7 @@
   1.161  		[AILoggerPlugin relativePathForLogWithObject:logObjectUID onAccount:chat.account]];	
   1.162  
   1.163  	if ([chat boolValueForProperty:@"Restored Chat"] && linesToDisplay < RESTORED_CHAT_CONTEXT_LINE_NUMBER) {
   1.164 -		linesLeftToFind = RESTORED_CHAT_CONTEXT_LINE_NUMBER;
   1.165 +		linesLeftToFind = MAX(linesLeftToFind, RESTORED_CHAT_CONTEXT_LINE_NUMBER);
   1.166  	} else {
   1.167  		linesLeftToFind = linesToDisplay;		
   1.168  	}
   1.169 @@ -296,6 +215,7 @@
   1.170  						   accountID, @"Account ID",
   1.171  						   chat, @"Chat",
   1.172  						   decoder, @"AIHTMLDecoder",
   1.173 +						   [NSValue valueWithPointer:&linesLeftToFind], @"LinesLeftToFindValue",
   1.174  						   nil];
   1.175  			[parser setContextInfo:(void *)contextInfo];
   1.176  		}
   1.177 @@ -342,6 +262,11 @@
   1.178  		[outerFoundContentContexts replaceObjectsInRange:NSMakeRange(0, 0) withObjectsFromArray:foundMessages];
   1.179  		linesLeftToFind -= [outerFoundContentContexts count];
   1.180  	}
   1.181 +	
   1.182 +	if (linesLeftToFind > 0) {
   1.183 +		AILogWithSignature(@"Unable to find %d logs for %@", linesLeftToFind, chat);
   1.184 +	}
   1.185 +	
   1.186  	return outerFoundContentContexts;
   1.187  }
   1.188  
   1.189 @@ -384,7 +309,7 @@
   1.190  			AIListObject *account     = [contextInfo objectForKey:@"Account"];
   1.191  			NSString     *accountID   = [contextInfo objectForKey:@"Account ID"];
   1.192  			AIChat       *chat        = [contextInfo objectForKey:@"Chat"];
   1.193 -
   1.194 +			
   1.195  			//Set up some doohickers.
   1.196  			NSDictionary	*attributes = [element attributes];
   1.197  			NSString		*timeString = [attributes objectForKey:@"time"];
   1.198 @@ -427,9 +352,11 @@
   1.199  				NSLog(@"Null message context display time for %@",element);
   1.200  			}
   1.201  		}
   1.202 +		
   1.203 +		NSInteger	 *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
   1.204  
   1.205  		[elementStack removeObjectAtIndex:0U];
   1.206 -		if ([foundMessages count] == linesLeftToFind) {
   1.207 +		if ([foundMessages count] == *linesLeftToFind) {
   1.208  			if ([elementStack count]) [elementStack removeAllObjects];
   1.209  			[parser abortParsing];
   1.210  		} else {