adium 5818:ed8cdee02551: Rotate transcripts at midnight. Fixes #...

commits at adium.im commits at adium.im
Mon Dec 30 22:45:23 UTC 2013


details:	http://hg.adium.im/adium/rev/ed8cdee02551
revision:	5818:ed8cdee02551
branch:		adium-1.6
author:		Frank Dowsett <wixardy at adium.im>
date:		Mon Dec 30 17:43:21 2013 -0500

Rotate transcripts at midnight. Fixes #6786
Subject: adium 5819:6c3530a07d29: Change the transcript viewer's selection when contacts and their logs are deleted. Fixes #11420

details:	http://hg.adium.im/adium/rev/6c3530a07d29
revision:	5819:6c3530a07d29
branch:		adium-1.6
author:		Frank Dowsett <wixardy at adium.im>
date:		Mon Dec 30 17:44:54 2013 -0500

Change the transcript viewer's selection when contacts and their logs are deleted. Fixes #11420

diffs (184 lines):

diff -r b2711140d862 -r 6c3530a07d29 Frameworks/AIUtilities Framework/Source/AIDateAdditions.h
--- a/Frameworks/AIUtilities Framework/Source/AIDateAdditions.h	Sun Dec 29 17:16:24 2013 -0500
+++ b/Frameworks/AIUtilities Framework/Source/AIDateAdditions.h	Mon Dec 30 17:44:54 2013 -0500
@@ -38,4 +38,6 @@
 
 + (BOOL)isDate:(NSDate *)date1 sameDayAsDate:(NSDate *)date2;
 
++ (NSDate *)midnightTomorrow;
+
 @end
diff -r b2711140d862 -r 6c3530a07d29 Frameworks/AIUtilities Framework/Source/AIDateAdditions.m
--- a/Frameworks/AIUtilities Framework/Source/AIDateAdditions.m	Sun Dec 29 17:16:24 2013 -0500
+++ b/Frameworks/AIUtilities Framework/Source/AIDateAdditions.m	Mon Dec 30 17:44:54 2013 -0500
@@ -53,4 +53,15 @@
 	return (comp1.day == comp2.day && comp1.month == comp2.month && comp1.year == comp2.year);
 }
 
++ (NSDate *)midnightTomorrow
+{
+	NSCalendar *calendar = [NSCalendar currentCalendar];
+	
+	unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
+	NSDateComponents *comps = [calendar components:unitFlags fromDate:[NSDate date]];
+	comps.day++;
+	
+	return [calendar dateFromComponents:comps];
+}
+
 @end
diff -r b2711140d862 -r 6c3530a07d29 Source/AILogViewerWindowController.m
--- a/Source/AILogViewerWindowController.m	Sun Dec 29 17:16:24 2013 -0500
+++ b/Source/AILogViewerWindowController.m	Mon Dec 30 17:44:54 2013 -0500
@@ -2793,6 +2793,9 @@
 								   selector:@selector(restoreDeletedToGroups:)
 									 object:allSelectedToGroups];
 		[undoManager setActionName:DELETE];
+
+		//Force a selection change in case of a noncontiguous selection
+		[outlineView_contacts selectRowIndexes:[NSIndexSet indexSetWithIndex:[outlineView_contacts selectedRow]] byExtendingSelection:NO];
 		
 		[self rebuildIndices];
 		[self updateProgressDisplay];
diff -r b2711140d862 -r 6c3530a07d29 Source/AILoggerPlugin.h
--- a/Source/AILoggerPlugin.h	Sun Dec 29 17:16:24 2013 -0500
+++ b/Source/AILoggerPlugin.h	Mon Dec 30 17:44:54 2013 -0500
@@ -44,6 +44,7 @@
 	AIHTMLDecoder       *xhtmlDecoder;
 	NSDictionary        *statusTranslation;
 	BOOL                 logHTML;
+	NSTimer				*logRotateTimer;
 	
 	ISO8601DateFormatter *formatter;
 	
diff -r b2711140d862 -r 6c3530a07d29 Source/AILoggerPlugin.m
--- a/Source/AILoggerPlugin.m	Sun Dec 29 17:16:24 2013 -0500
+++ b/Source/AILoggerPlugin.m	Mon Dec 30 17:44:54 2013 -0500
@@ -39,6 +39,7 @@
 #import <Adium/AIListBookmark.h>
 #import <Adium/AIService.h>
 #import <AIUtilities/AIAttributedStringAdditions.h>
+#import <AIUtilities/AIDateAdditions.h>
 #import <AIUtilities/AIDictionaryAdditions.h>
 #import <AIUtilities/AIFileManagerAdditions.h>
 #import <AIUtilities/AIMenuAdditions.h>
@@ -258,6 +259,13 @@
 							  @"away",@"away_message",
 							  nil];
 	
+	logRotateTimer = [[NSTimer scheduledTimerWithTimeInterval:86400
+													   target:self
+													 selector:@selector(rotateLogs:)
+													 userInfo:nil
+													  repeats:YES] retain];
+	[logRotateTimer setFireDate:[NSDate midnightTomorrow]];
+	
 	//Setup our preferences
 	[adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed: LOGGING_DEFAULT_PREFS forClass:[self class]] forGroup:PREF_GROUP_LOGGING];
 	
@@ -366,6 +374,7 @@
 	dispatch_release(jobSemaphore); jobSemaphore = nil;
 	dispatch_release(loggerPluginGroup); loggerPluginGroup = nil;
 	
+	[logRotateTimer invalidate]; [logRotateTimer release];
 	[formatter release]; formatter = nil;
 	
 	[super dealloc];
@@ -1262,13 +1271,31 @@
 												 selector:@selector(finishClosingAppender:) 
 												   object:[self keyForChat:chat]];
 	} else {
-		//If there isn't already an appender, create a new one and add it to the dictionary
-		NSDate			*chatDate = [chat dateOpened];
-		NSString		*fullPath = [AILoggerPlugin fullPathForLogOfChat:chat onDate:chatDate];
-		
-		AIXMLElement *rootElement = [[[AIXMLElement alloc] initWithName:@"chat"] autorelease];
-		
-		[rootElement setAttributeNames:[NSArray arrayWithObjects:@"xmlns", @"account", @"service", @"adiumversion", @"buildid", nil]
+		appender = [self _createAppenderForChat:chat withDate:nil];
+
+		//Add the window opened event now
+		AIXMLElement *eventElement = [[[AIXMLElement alloc] initWithName:@"event"] autorelease];
+
+		[eventElement setAttributeNames:[NSArray arrayWithObjects:@"type", @"sender", @"time", nil]
+								 values:[NSArray arrayWithObjects:@"windowOpened", chat.account.UID, [formatter stringFromDate:[[NSDate date] dateWithCalendarFormat:nil timeZone:nil]], nil]];
+
+		[appender appendElement:eventElement];
+	}
+	
+	return appender;
+}
+
+- (AIXMLAppender *)_createAppenderForChat:(AIChat *)chat withDate:(NSDate *)chatDate
+{
+	//If there isn't already an appender, create a new one and add it to the dictionary
+	if (!chatDate)
+		chatDate = [chat dateOpened];
+	
+	NSString		*fullPath = [AILoggerPlugin fullPathForLogOfChat:chat onDate:chatDate];
+
+	AIXMLElement *rootElement = [[[AIXMLElement alloc] initWithName:@"chat"] autorelease];
+
+	[rootElement setAttributeNames:[NSArray arrayWithObjects:@"xmlns", @"account", @"service", @"adiumversion", @"buildid", nil]
 								values:[NSArray arrayWithObjects:
 										XML_LOGGING_NAMESPACE,
 										chat.account.UID,
@@ -1276,21 +1303,12 @@
 										[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
 										[[NSBundle mainBundle] objectForInfoDictionaryKey:@"AIBuildIdentifier"],
 										nil]];
-		
-		appender = [AIXMLAppender documentWithPath:fullPath rootElement:rootElement];
-		
-		//Add the window opened event now
-		AIXMLElement *eventElement = [[[AIXMLElement alloc] initWithName:@"event"] autorelease];
-		
-		[eventElement setAttributeNames:[NSArray arrayWithObjects:@"type", @"sender", @"time", nil]
-								 values:[NSArray arrayWithObjects:@"windowOpened", chat.account.UID, [formatter stringFromDate:[[NSDate date] dateWithCalendarFormat:nil timeZone:nil]], nil]];
-		
-		[appender appendElement:eventElement];
-		
-		[activeAppenders setObject:appender forKey:[self keyForChat:chat]];
-		
-		[self _markLogDirtyAtPath:[appender path] forChat:chat];
-	}
+
+	AIXMLAppender *appender = [AIXMLAppender documentWithPath:fullPath rootElement:rootElement];
+
+	[activeAppenders setObject:appender forKey:[self keyForChat:chat]];
+
+	[self _markLogDirtyAtPath:[appender path] forChat:chat];
 	
 	return appender;
 }
@@ -1327,6 +1345,30 @@
 	[activeAppenders removeObjectForKey:chatKey];
 }
 
+- (void)rotateLogs:(NSTimer *)timer
+{
+	for (AIChat *chat in adium.chatController.openChats) {
+		AIXMLAppender *oldAppender = [self _existingAppenderForChat:chat];
+		if (!oldAppender)
+			continue;
+		
+		//Close old appender
+		NSString *chatKey = [self keyForChat:chat];
+		[NSObject cancelPreviousPerformRequestsWithTarget:self
+												 selector:@selector(finishClosingAppender:)
+												   object:chatKey];
+		[self finishClosingAppender:chatKey];
+
+		//Create new appender
+		AIXMLAppender *appender = [self _createAppenderForChat:chat withDate:[NSDate date]];
+
+		AILogWithSignature(@"Rotated %@ to %@", chat, [appender path]);
+	}
+	
+	//Update the timer for DST and the like
+	[logRotateTimer setFireDate:[NSDate midnightTomorrow]];
+}
+
 #pragma mark Log Indexing
 - (NSString *)_logIndexPath
 {




More information about the commits mailing list