[Adium-commits] adium 1961:06e7207bb467: Store list bookmarks in a dictionary in...

adium-commits at adiumx.com adium-commits at adiumx.com
Fri Apr 24 20:09:14 UTC 2009


details:	http://hg.adiumx.com/adium/rev/06e7207bb467
revision:	1961:06e7207bb467
author:		Zachary West <zacw at adiumx.com>
date:		Fri Apr 24 16:09:03 2009 -0400

Store list bookmarks in a dictionary instead of an array, keyed on their internal object ID.

Change their internal object ID to include their account's UID (since you can have multiple on different accounts), and remove a previously-initiated bookmark if it matches a new bookmark's internal object ID.

Set the bookmark's display name (aka, alias) when creating from a chat, using the chat's display name, since it has the case-intended value.

Fixes an annoying crash I could only see on my regular account, which had spawned too many timeline accounts, causing proxy failure like crazy (since it's keyed on internal object ID).

diffstat:

 Frameworks/Adium Framework/Source/AIListBookmark.m |  31 +++++++++++++--
 Frameworks/Adium Framework/Source/AIListObject.m   |   1 -
 Plugins/Twitter Plugin/AITwitterAccount.m          |   2 +
 Source/AIContactController.h                       |   3 +-
 Source/AIContactController.m                       |  24 ++++++++---
 5 files changed, 46 insertions(+), 15 deletions(-)

diffs (162 lines):

diff -r 7dd50cb1e864 -r 06e7207bb467 Frameworks/Adium Framework/Source/AIListBookmark.m
--- a/Frameworks/Adium Framework/Source/AIListBookmark.m	Fri Apr 24 15:19:21 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListBookmark.m	Fri Apr 24 16:09:03 2009 -0400
@@ -69,11 +69,15 @@
 
 -(id)initWithChat:(AIChat *)inChat
 {
-	return [self initWithUID:[NSString stringWithFormat:@"Bookmark:%@", inChat.uniqueChatID]
-					 account:inChat.account
-					 service:inChat.account.service
-				  dictionary:inChat.chatCreationDictionary
-						name:inChat.name];
+	if ((self = [self initWithUID:[NSString stringWithFormat:@"Bookmark:%@", inChat.uniqueChatID]
+						  account:inChat.account
+						  service:inChat.account.service
+					   dictionary:inChat.chatCreationDictionary
+							 name:inChat.name])) {
+		[self setDisplayName:inChat.displayName];
+	}
+	
+	return self;
 }
 
 - (id)initWithCoder:(NSCoder *)decoder
@@ -148,6 +152,23 @@
 }
 
 /*!
+ * @brief Internal ID for this object
+ *
+ * An object ID generated by Adium that is shared by all objects which are, to most intents and purposes, identical to
+ * this object.  Ths ID is composed of the service ID and UID, so any object with identical services and object IDs
+ * will have the same value here.
+ */
+- (NSString *)internalObjectID
+{
+	if (!internalObjectID) {
+		// We're not like any other bookmarks by the same name.
+		internalObjectID = [[NSString stringWithFormat:@"%@.%@.%@", self.service.serviceID, self.UID, self.account.UID] retain];
+	}
+	
+	return internalObjectID;
+}
+
+/*!
  * @brief Set our display name
  *
  * Update the display name of our chat if our display name changes.
diff -r 7dd50cb1e864 -r 06e7207bb467 Frameworks/Adium Framework/Source/AIListObject.m
--- a/Frameworks/Adium Framework/Source/AIListObject.m	Fri Apr 24 15:19:21 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIListObject.m	Fri Apr 24 16:09:03 2009 -0400
@@ -144,7 +144,6 @@
 	return [NSString stringWithFormat:@"%@.%@",inServiceID, inUID];
 }
 
-
 //Visibility -----------------------------------------------------------------------------------------------------------
 #pragma mark Visibility
 
diff -r 7dd50cb1e864 -r 06e7207bb467 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m	Fri Apr 24 15:19:21 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m	Fri Apr 24 16:09:03 2009 -0400
@@ -204,6 +204,8 @@
 														   onAccount:self 
 													chatCreationInfo:nil];
 		
+		[newTimelineChat setDisplayName:self.timelineChatName];
+		
 		timelineBookmark = [adium.contactController bookmarkForChat:newTimelineChat];
 
 		[adium.contactController moveContact:timelineBookmark intoGroups:[NSSet setWithObject:[adium.contactController groupWithUID:TWITTER_REMOTE_GROUP_NAME]]];
diff -r 7dd50cb1e864 -r 06e7207bb467 Source/AIContactController.h
--- a/Source/AIContactController.h	Fri Apr 24 15:19:21 2009 -0400
+++ b/Source/AIContactController.h	Fri Apr 24 16:09:03 2009 -0400
@@ -37,8 +37,7 @@
 	NSMutableDictionary		*contactDict;
 	NSMutableDictionary		*metaContactDict;
 	NSMutableDictionary		*contactToMetaContactLookupDict;
-	
-	NSMutableArray			*bookmarksArray;
+	NSMutableDictionary		*bookmarkDict;
 	
 	//Contact List and Groups
 	AIContactList			*contactList;
diff -r 7dd50cb1e864 -r 06e7207bb467 Source/AIContactController.m
--- a/Source/AIContactController.m	Fri Apr 24 15:19:21 2009 -0400
+++ b/Source/AIContactController.m	Fri Apr 24 16:09:03 2009 -0400
@@ -117,9 +117,9 @@
 		contactDict = [[NSMutableDictionary alloc] init];
 		groupDict = [[NSMutableDictionary alloc] init];
 		metaContactDict = [[NSMutableDictionary alloc] init];
+		bookmarkDict = [[NSMutableDictionary alloc] init];
 		contactToMetaContactLookupDict = [[NSMutableDictionary alloc] init];
 		contactLists = [[NSMutableArray alloc] init];
-		bookmarksArray = [[NSMutableArray alloc] init];
 
 		contactPropertiesObserverManager = [AIContactObserverManager sharedManager];
 	}
@@ -168,7 +168,7 @@
 	[metaContactDict release];
 	[contactToMetaContactLookupDict release];
 	[contactLists release];
-	[bookmarksArray release];
+	[bookmarkDict release];
 	
 	[contactPropertiesObserverManager release];
 
@@ -244,7 +244,12 @@
 		AIListBookmark	*bookmark = [NSKeyedUnarchiver unarchiveObjectWithData:data];
 
 		if(bookmark) {
-			[bookmarksArray addObject:bookmark];
+			if ([bookmarkDict objectForKey:bookmark.internalObjectID]) {
+				// In case we end up with two bookmarks with the same internalObjectID; this should be almost impossible.
+				[self removeBookmark:[bookmarkDict objectForKey:bookmark.internalObjectID]];
+			}
+			
+			[bookmarkDict setObject:bookmark forKey:bookmark.internalObjectID];
 			
 			//It's a newly created object, so set its initial attributes
 			[contactPropertiesObserverManager _updateAllAttributesOfObject:bookmark];
@@ -1012,7 +1017,7 @@
  */
 - (NSArray *)allBookmarks
 {
-	return [[bookmarksArray copy] autorelease];
+	return [[[bookmarkDict allValues] copy] autorelease];
 }
 
 /*!
@@ -1203,7 +1208,7 @@
 	AIListBookmark *existingBookmark = nil;
 	
 	for(AIListBookmark *listBookmark in self.allBookmarks) {
-		if([listBookmark.name isEqualToString:inName] &&
+		if([listBookmark.name isEqualToString:[inAccount.service normalizeChatName:inName]] &&
 			listBookmark.account == inAccount &&
 			((!listBookmark.chatCreationDictionary && !inCreationInfo) ||
 			 ([listBookmark.chatCreationDictionary isEqualToDictionary:inCreationInfo]))) {
@@ -1226,7 +1231,12 @@
 	if (!bookmark) {
 		bookmark = [[[AIListBookmark alloc] initWithChat:inChat] autorelease];
 		
-		[bookmarksArray addObject:bookmark];
+		if ([bookmarkDict objectForKey:bookmark.internalObjectID]) {
+			// In case we end up with two bookmarks with the same internalObjectID; this should be almost impossible.
+			[self removeBookmark:[bookmarkDict objectForKey:bookmark.internalObjectID]];
+		}
+		
+		[bookmarkDict setObject:bookmark forKey:bookmark.internalObjectID];
 		
 		[self saveContactList];
 	}
@@ -1243,7 +1253,7 @@
 - (void)removeBookmark:(AIListBookmark *)listBookmark
 {
 	[self moveContact:listBookmark intoGroups:[NSSet set]];
-	[bookmarksArray removeObject:listBookmark];
+	[bookmarkDict removeObjectForKey:listBookmark.internalObjectID];
 	
 	[self saveContactList];
 }




More information about the commits mailing list