Code simplification; remove the old preferences, and don't use a static variable to count the lines. Refs #13362.
I can't imagine using a static variable like this wouldn't cause problems, especially with "save chats" enabled; we'd be messing with the same static variable like crazy. I'm betting this explains some weird context problems, so let's see if this helps #13362.
1.1 --- a/Plugins/General Preferences/ESGeneralPreferences.m Wed Nov 25 20:44:24 2009 -0500
1.2 +++ b/Plugins/General Preferences/ESGeneralPreferences.m Wed Nov 25 22:28:47 2009 -0500
1.3 @@ -110,11 +110,7 @@
1.4 [popUp_tabPositionMenu setMenu:[self tabPositionMenu]];
1.5 [popUp_tabPositionMenu selectItemWithTag:[[adium.preferenceController preferenceForKey:KEY_TABBAR_POSITION
1.6 group:PREF_GROUP_DUAL_WINDOW_INTERFACE] intValue]];
1.7 -
1.8 - //Quit
1.9 - //[checkBox_confirmOnQuit setState:[[adium.preferenceController preferenceForKey:KEY_CONFIRM_QUIT
1.10 - // group:PREF_GROUP_CONFIRMATIONS] boolValue]];
1.11 -
1.12 +
1.13 //Global hotkey
1.14 TISInputSourceRef currentLayout = TISCopyCurrentKeyboardLayoutInputSource();
1.15
2.1 --- a/Source/DCMessageContextDisplayPlugin.h Wed Nov 25 20:44:24 2009 -0500
2.2 +++ b/Source/DCMessageContextDisplayPlugin.h Wed Nov 25 22:28:47 2009 -0500
2.3 @@ -21,29 +21,10 @@
2.4
2.5 // Pref keys
2.6 #define KEY_DISPLAY_CONTEXT @"Display Message Context"
2.7 -#define KEY_DIM_RECENT_CONTEXT @"Dim Recent Context"
2.8 #define KEY_DISPLAY_LINES @"Lines to Display"
2.9 -#define KEY_DISPLAY_MODE @"Display Mode"
2.10 -#define KEY_HAVE_TALKED_DAYS @"Have Talked Days"
2.11 -#define KEY_HAVE_NOT_TALKED_DAYS @"Have Not Talked Days"
2.12 -#define KEY_HAVE_TALKED_UNITS @"Have Talked Units"
2.13 -#define KEY_HAVE_NOT_TALKED_UNITS @"Have Not Talked Units"
2.14
2.15 #define CONTEXT_DISPLAY_DEFAULTS @"MessageContextDisplayDefaults"
2.16
2.17 -// Possible Display Modes
2.18 -typedef enum AIMessageHistoryDisplayModes {
2.19 - MODE_ALWAYS = 0,
2.20 - MODE_HAVE_TALKED,
2.21 - MODE_HAVE_NOT_TALKED
2.22 -} AIMessageHistoryDisplayModes;
2.23 -
2.24 -// Possible Units
2.25 -typedef enum AIMessageHistoryDisplayUnits {
2.26 - UNIT_DAYS = 0,
2.27 - UNIT_HOURS
2.28 -} AIMessageHistoryDisplayUnits;
2.29 -
2.30 @class DCMessageContextDisplayPreferences, SMSQLiteLoggerPlugin;
2.31
2.32 @interface DCMessageContextDisplayPlugin : AIPlugin {
2.33 @@ -52,13 +33,6 @@
2.34 BOOL dimRecentContext;
2.35 NSInteger linesToDisplay;
2.36
2.37 - NSInteger displayMode;
2.38 - NSInteger haveTalkedDays;
2.39 - NSInteger haveNotTalkedDays;
2.40 -
2.41 - NSInteger haveTalkedUnits;
2.42 - NSInteger haveNotTalkedUnits;
2.43 -
2.44 DCMessageContextDisplayPreferences *preferences;
2.45
2.46 NSMutableArray *foundMessages;
3.1 --- a/Source/DCMessageContextDisplayPlugin.m Wed Nov 25 20:44:24 2009 -0500
3.2 +++ b/Source/DCMessageContextDisplayPlugin.m Wed Nov 25 22:28:47 2009 -0500
3.3 @@ -22,9 +22,6 @@
3.4 #import <Adium/AIContentContext.h>
3.5 #import <Adium/AIService.h>
3.6
3.7 -//#import "SMSQLiteLoggerPlugin.h"
3.8 -//#import "AICoreComponentLoader.h"
3.9 -
3.10 //Old school
3.11 #import <Adium/AIListContact.h>
3.12 #import <AIUtilities/AIAttributedStringAdditions.h>
3.13 @@ -53,9 +50,6 @@
3.14 @interface DCMessageContextDisplayPlugin ()
3.15 - (void)preferencesChangedForGroup:(NSString *)group key:(NSString *)key
3.16 object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime;
3.17 -- (void)old_preferencesChangedForGroup:(NSString *)group key:(NSString *)key
3.18 - object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime;
3.19 -- (BOOL)contextShouldBeDisplayed:(NSCalendarDate *)inDate;
3.20 - (NSArray *)contextForChat:(AIChat *)chat;
3.21 @end
3.22
3.23 @@ -72,14 +66,6 @@
3.24 [adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:CONTEXT_DISPLAY_DEFAULTS
3.25 forClass:[self class]]
3.26 forGroup:PREF_GROUP_CONTEXT_DISPLAY];
3.27 -
3.28 - //Obtain the default preferences and use them - Adium 1.1 experiment to see if people use these prefs
3.29 - [self old_preferencesChangedForGroup:PREF_GROUP_CONTEXT_DISPLAY
3.30 - key:nil
3.31 - object:nil
3.32 - preferenceDict:[NSDictionary dictionaryNamed:CONTEXT_DISPLAY_DEFAULTS
3.33 - forClass:[self class]]
3.34 - firstTime:YES];
3.35
3.36 //Observe preference changes for whether or not to display message history
3.37 [adium.preferenceController registerPreferenceObserver:self forGroup:PREF_GROUP_CONTEXT_DISPLAY];
3.38 @@ -117,23 +103,6 @@
3.39 }
3.40 }
3.41 }
3.42 -/**
3.43 - * @brief Preferences for when to display history changed
3.44 - *
3.45 - * Only change our preferences in response to global preference notifications; specific objects use this group as well.
3.46 - */
3.47 -- (void)old_preferencesChangedForGroup:(NSString *)group key:(NSString *)key
3.48 - object:(AIListObject *)object preferenceDict:(NSDictionary *)prefDict firstTime:(BOOL)firstTime
3.49 -{
3.50 - if (!object) {
3.51 - haveTalkedDays = [[prefDict objectForKey:KEY_HAVE_TALKED_DAYS] integerValue];
3.52 - haveNotTalkedDays = [[prefDict objectForKey:KEY_HAVE_NOT_TALKED_DAYS] integerValue];
3.53 - displayMode = [[prefDict objectForKey:KEY_DISPLAY_MODE] integerValue];
3.54 -
3.55 - haveTalkedUnits = [[prefDict objectForKey:KEY_HAVE_TALKED_UNITS] integerValue];
3.56 - haveNotTalkedUnits = [[prefDict objectForKey:KEY_HAVE_NOT_TALKED_UNITS] integerValue];
3.57 - }
3.58 -}
3.59
3.60 /**
3.61 * @brief Retrieve and display in-window message history
3.62 @@ -147,75 +116,23 @@
3.63 NSArray *context = [self contextForChat:chat];
3.64
3.65 if (context && [context count] > 0 && shouldDisplay) {
3.66 - //Check if the history fits the date restrictions
3.67 + AIContentContext *contextMessage;
3.68 +
3.69 + for(contextMessage in context) {
3.70 + /* Don't display immediately, so the message view can aggregate multiple message history items.
3.71 + * As required, we post Content_ChatDidFinishAddingUntrackedContent when finished adding. */
3.72 + [contextMessage setDisplayContentImmediately:NO];
3.73
3.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.
3.75 - NSCalendarDate *mostRecentMessage = [[(AIContentContext *)[context lastObject] date] dateWithCalendarFormat:nil timeZone:nil];
3.76 - if ([self contextShouldBeDisplayed:mostRecentMessage]) {
3.77 - AIContentContext *contextMessage;
3.78 + [adium.contentController displayContentObject:contextMessage
3.79 + usingContentFilters:YES
3.80 + immediately:YES];
3.81 + }
3.82
3.83 - for(contextMessage in context) {
3.84 - /* Don't display immediately, so the message view can aggregate multiple message history items.
3.85 - * As required, we post Content_ChatDidFinishAddingUntrackedContent when finished adding. */
3.86 - [contextMessage setDisplayContentImmediately:NO];
3.87 -
3.88 - [adium.contentController displayContentObject:contextMessage
3.89 - usingContentFilters:YES
3.90 - immediately:YES];
3.91 - }
3.92 -
3.93 - //We finished adding untracked content
3.94 - [[NSNotificationCenter defaultCenter] postNotificationName:Content_ChatDidFinishAddingUntrackedContent
3.95 - object:chat];
3.96 - }
3.97 + //We finished adding untracked content
3.98 + [[NSNotificationCenter defaultCenter] postNotificationName:Content_ChatDidFinishAddingUntrackedContent
3.99 + object:chat];
3.100 }
3.101 }
3.102 -
3.103 -/**
3.104 - * @brief Does a specified date match our criteria for display?
3.105 - *
3.106 - * The date passed should be the date of the _most recent_ stored message history item
3.107 - *
3.108 - * @result YES if the mesage history should be displayed
3.109 - */
3.110 -- (BOOL)contextShouldBeDisplayed:(NSCalendarDate *)inDate
3.111 -{
3.112 - BOOL dateIsGood = YES;
3.113 - NSInteger thresholdDays = 0;
3.114 - NSInteger thresholdHours = 0;
3.115 -
3.116 - if (displayMode != MODE_ALWAYS) {
3.117 -
3.118 - if (displayMode == MODE_HAVE_TALKED) {
3.119 - if (haveTalkedUnits == UNIT_DAYS)
3.120 - thresholdDays = haveTalkedDays;
3.121 -
3.122 - else if (haveTalkedUnits == UNIT_HOURS)
3.123 - thresholdHours = haveTalkedDays;
3.124 -
3.125 - } else if (displayMode == MODE_HAVE_NOT_TALKED) {
3.126 - if ( haveTalkedUnits == UNIT_DAYS )
3.127 - thresholdDays = haveNotTalkedDays;
3.128 - else if (haveTalkedUnits == UNIT_HOURS)
3.129 - thresholdHours = haveNotTalkedDays;
3.130 - }
3.131 -
3.132 - // Take the most recent message's date, add our limits to it
3.133 - // See if the new date is earlier or later than today's date
3.134 - NSCalendarDate *newDate = [inDate dateByAddingYears:0 months:0 days:thresholdDays hours:thresholdHours minutes:0 seconds:0];
3.135 -
3.136 - NSComparisonResult comparison = [newDate compare:[NSDate date]];
3.137 -
3.138 - if (((displayMode == MODE_HAVE_TALKED) && (comparison == NSOrderedAscending)) ||
3.139 - ((displayMode == MODE_HAVE_NOT_TALKED) && (comparison == NSOrderedDescending)) ) {
3.140 - dateIsGood = NO;
3.141 - }
3.142 - }
3.143 -
3.144 - return dateIsGood;
3.145 -}
3.146 -
3.147 -static NSInteger linesLeftToFind = 0;
3.148 /*!
3.149 * @brief Retrieve the message history for a particular chat
3.150 *
3.151 @@ -226,6 +143,8 @@
3.152 //If there's no log there, there's no message history. Bail out.
3.153 NSArray *logPaths = [AILoggerPlugin sortedArrayOfLogFilesForChat:chat];
3.154 if(!logPaths) return nil;
3.155 +
3.156 + NSInteger linesLeftToFind = 0;
3.157
3.158 AIHTMLDecoder *decoder = [AIHTMLDecoder decoder];
3.159
3.160 @@ -237,7 +156,7 @@
3.161 [AILoggerPlugin relativePathForLogWithObject:logObjectUID onAccount:chat.account]];
3.162
3.163 if ([chat boolValueForProperty:@"Restored Chat"] && linesToDisplay < RESTORED_CHAT_CONTEXT_LINE_NUMBER) {
3.164 - linesLeftToFind = RESTORED_CHAT_CONTEXT_LINE_NUMBER;
3.165 + linesLeftToFind = MAX(linesLeftToFind, RESTORED_CHAT_CONTEXT_LINE_NUMBER);
3.166 } else {
3.167 linesLeftToFind = linesToDisplay;
3.168 }
3.169 @@ -296,6 +215,7 @@
3.170 accountID, @"Account ID",
3.171 chat, @"Chat",
3.172 decoder, @"AIHTMLDecoder",
3.173 + [NSValue valueWithPointer:&linesLeftToFind], @"LinesLeftToFindValue",
3.174 nil];
3.175 [parser setContextInfo:(void *)contextInfo];
3.176 }
3.177 @@ -342,6 +262,11 @@
3.178 [outerFoundContentContexts replaceObjectsInRange:NSMakeRange(0, 0) withObjectsFromArray:foundMessages];
3.179 linesLeftToFind -= [outerFoundContentContexts count];
3.180 }
3.181 +
3.182 + if (linesLeftToFind > 0) {
3.183 + AILogWithSignature(@"Unable to find %d logs for %@", linesLeftToFind, chat);
3.184 + }
3.185 +
3.186 return outerFoundContentContexts;
3.187 }
3.188
3.189 @@ -384,7 +309,7 @@
3.190 AIListObject *account = [contextInfo objectForKey:@"Account"];
3.191 NSString *accountID = [contextInfo objectForKey:@"Account ID"];
3.192 AIChat *chat = [contextInfo objectForKey:@"Chat"];
3.193 -
3.194 +
3.195 //Set up some doohickers.
3.196 NSDictionary *attributes = [element attributes];
3.197 NSString *timeString = [attributes objectForKey:@"time"];
3.198 @@ -427,9 +352,11 @@
3.199 NSLog(@"Null message context display time for %@",element);
3.200 }
3.201 }
3.202 +
3.203 + NSInteger *linesLeftToFind = [[contextInfo objectForKey:@"LinesLeftToFindValue"] pointerValue];
3.204
3.205 [elementStack removeObjectAtIndex:0U];
3.206 - if ([foundMessages count] == linesLeftToFind) {
3.207 + if ([foundMessages count] == *linesLeftToFind) {
3.208 if ([elementStack count]) [elementStack removeAllObjects];
3.209 [parser abortParsing];
3.210 } else {