Adium

Changeset 24100

Show
Ignore:
Timestamp:
06/29/2008 05:08:58 PM (5 months ago)
Author:
evands
Message:

Track the metacontacts created by the address book plugin. If -[AIContactController knownMetaContactForGroupingUIDs:forServices:] returns nil, access our tracking dictionary to determine a previously-automatically-created metacontact. If we have one, suggest it as the metaContactHint in -[AIContactController groupUIDs:forServices:usingMetaContactHint:].

This lets the same metacontact be recreated, restoring its preferences and stored info. Fixes #8742.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Source/ESAddressBookIntegrationPlugin.m

    r24080 r24100  
    4747#define KEY_ADDRESS_BOOK_ACTIONS_INSTALLED      @"Adium:Installed Adress Book Actions 1.3" 
    4848 
     49#define KEY_AB_TO_METACONTACT_DICT                      @"UniqueIDToMetaContactObjectIDDictionary" 
     50 
    4951@interface ESAddressBookIntegrationPlugin(PRIVATE) 
    5052+ (ABPerson *)_searchForUID:(NSString *)UID serviceID:(NSString *)serviceID; 
     
    5456- (void)updateAllContacts; 
    5557- (void)updateSelfIncludingIcon:(BOOL)includeIcon; 
    56 - (void)preferencesChanged:(NSNotification *)notification; 
    5758- (NSString *)nameForPerson:(ABPerson *)person phonetic:(NSString **)phonetic; 
    5859- (void)rebuildAddressBookDict; 
     
    502503        } 
    503504 
    504     if ([group isEqualToString:PREF_GROUP_ADDRESSBOOK]) { 
     505    if ([group isEqualToString:PREF_GROUP_ADDRESSBOOK] && 
     506                ![key isEqualToString:KEY_AB_TO_METACONTACT_DICT]) { 
    505507                BOOL                    oldCreateMetaContacts = createMetaContacts; 
    506508                 
     
    11611163                if (([UIDsArray count] > 1) && createMetaContacts) { 
    11621164                        /* Got a record with multiple names. Group the names together, adding them to the meta contact. */ 
    1163                         AIMetaContact *metaContact = [[adium contactController] groupUIDs:UIDsArray  
    1164                                                                                                                                   forServices:servicesArray]; 
     1165                        AIMetaContact *metaContact, *metaContactHint; 
     1166                        NSString *uniqueId = [person uniqueId]; 
     1167 
     1168                        metaContactHint = [[adium contactController] knownMetaContactForGroupingUIDs:UIDsArray 
     1169                                                                                                                                                 forServices:servicesArray]; 
     1170                        if (!metaContactHint) { 
     1171                                /* Find a metacontact we used previously but which wasn't saved, if possible. This keeps us from creating a  
     1172                                 * new metacontact with every launch when the metacontact is created by the address book rather than the user. 
     1173                                 * 
     1174                                 * We don't make address book metacontacts actually persistent because then we would persist them even if the address 
     1175                                 * book card were modified or deleted or if the user disabled "Conslidate contacts listed on the card." 
     1176                                 */ 
     1177                                NSDictionary *dict = [[adium preferenceController] preferenceForKey:KEY_AB_TO_METACONTACT_DICT 
     1178                                                                                                                                                          group:PREF_GROUP_ADDRESSBOOK]; 
     1179                                NSNumber *metaContactObjectID = [dict objectForKey:uniqueId]; 
     1180                                if (metaContactObjectID) 
     1181                                        metaContactHint = [[adium contactController] metaContactWithObjectID:metaContactObjectID]; 
     1182                        } 
     1183                                 
     1184                        metaContact = [[adium contactController] groupUIDs:UIDsArray  
     1185                                                                                                   forServices:servicesArray 
     1186                                                                                  usingMetaContactHint:metaContactHint]; 
    11651187                        if (metaContact) { 
    1166                                 NSString *uniqueId = [person uniqueId]; 
    11671188                                [metaContact setValue:uniqueId 
    11681189                                                  forProperty:KEY_AB_UNIQUE_ID 
     
    11711192                                [personUniqueIdToMetaContactDict setObject:metaContact 
    11721193                                                                                                        forKey:uniqueId]; 
     1194                                if (metaContact != metaContactHint) { 
     1195                                        //Keep track of the use of this metacontact for this address book card 
     1196                                        NSMutableDictionary *dict = [[[[adium preferenceController] preferenceForKey:KEY_AB_TO_METACONTACT_DICT 
     1197                                                                                                                                                                                   group:PREF_GROUP_ADDRESSBOOK] mutableCopy] autorelease]; 
     1198                                        if (!dict) dict = [NSMutableDictionary dictionary]; 
     1199                                        [dict setObject:[metaContact objectID] 
     1200                                                         forKey:uniqueId]; 
     1201                                        [[adium preferenceController] setPreference:dict 
     1202                                                                                                                 forKey:@"UniqueIDToMetaContactObjectIDDictionary" 
     1203                                                                                                                  group:PREF_GROUP_ADDRESSBOOK]; 
     1204                                } 
    11731205                        } 
    11741206                }