From e81c6ead61c533827ad3ccf57d2ab832c4d91055 Mon Sep 17 00:00:00 2001 From: Evan Schoenberg Date: Tue, 9 Jan 2007 00:05:20 +0000 Subject: [PATCH] * Don't try to cache the blocked / permitted contacts in CBGaimAccount; just query libgaim when the information is needed and build up the array. Fixes #6110 * Actually update the blocked status of an AIListContact when libgaim tells us they are blocked - for a service which allowed multiple simultaneous logins, this allows us to update local display appropriately * Cleanup {{{ESBlockingPlugin}}}'s behavior at sign-on. Use {{{-[AIAccount listObjectsOnPrivacyList:]}}} and get rid of the listObjectIDsOnPrivacyList method which is duplicative implementation for account subclasses -- if something actually wanted that data, it should use listObjectsOnPrivacyList: then get the UID, but in this situation it's not even what we want. git-svn-id: svn://svn.adiumx.com/adium/branches/adium-1.0@18627 1c916fce-81e2-0310-a464-8ca513f45935 --- Frameworks/Adium Framework/Source/AIAccount.h | 2 - Plugins/Gaim Service/CBGaimAccount.h | 11 ----- Plugins/Gaim Service/CBGaimAccount.m | 58 +++++++++++++-------------- Source/ESBlockingPlugin.m | 39 ++++-------------- 4 files changed, 35 insertions(+), 75 deletions(-) diff --git a/Frameworks/Adium Framework/Source/AIAccount.h b/Frameworks/Adium Framework/Source/AIAccount.h index 0bc3ba39d..8729155b1 100644 --- a/Frameworks/Adium Framework/Source/AIAccount.h +++ b/Frameworks/Adium Framework/Source/AIAccount.h @@ -98,8 +98,6 @@ typedef enum { -(BOOL)removeListObject:(AIListObject *)inObject fromPrivacyList:(AIPrivacyType)type; //Return an array of AIListContacts on the specified privacy list. Returns an empty array if no contacts are on the list. -(NSArray *)listObjectsOnPrivacyList:(AIPrivacyType)type; - //Identical to the above method, except it returns an array of strings, not list objects - -(NSArray *)listObjectIDsOnPrivacyList:(AIPrivacyType)type; //Set the privacy options -(void)setPrivacyOptions:(AIPrivacyOption)option; //Get the privacy options diff --git a/Plugins/Gaim Service/CBGaimAccount.h b/Plugins/Gaim Service/CBGaimAccount.h index 92b7dfbb9..8dff32aa4 100644 --- a/Plugins/Gaim Service/CBGaimAccount.h +++ b/Plugins/Gaim Service/CBGaimAccount.h @@ -123,9 +123,6 @@ - (void)receivedMultiChatMessage:(NSDictionary *)messageDict inChat:(AIChat *)chat; - (void)removeUser:(NSString *)contactName fromChat:(AIChat *)chat; -- (void)accountPrivacyList:(AIPrivacyType)type added:(NSString *)sourceUID; -- (void)accountPrivacyList:(AIPrivacyType)type removed:(NSString *)sourceUID; - - (void)requestReceiveOfFileTransfer:(ESFileTransfer *)fileTransfer; - (void)updateProgressForFileTransfer:(ESFileTransfer *)fileTransfer percent:(NSNumber *)percent @@ -173,14 +170,6 @@ newArrivals:(NSNumber *)newArrivals toChat:(AIChat *)chat; - -#pragma mark Privacy -- (void)privacyPermitListAdded:(NSString *)sourceUID; -- (void)privacyPermitListRemoved:(NSString *)sourceUID; -- (void)privacyDenyListAdded:(NSString *)sourceUID; -- (void)privacyDenyListRemoved:(NSString *)sourceUID; - - #pragma mark Emoticons - (void)chat:(AIChat *)inChat isWaitingOnCustomEmoticon:(NSString *)isWaiting; - (void)chat:(AIChat *)inChat setCustomEmoticon:(NSString *)emoticonEquivalent withImageData:(NSData *)inImageData; diff --git a/Plugins/Gaim Service/CBGaimAccount.m b/Plugins/Gaim Service/CBGaimAccount.m index da725c91a..1e239267f 100644 --- a/Plugins/Gaim Service/CBGaimAccount.m +++ b/Plugins/Gaim Service/CBGaimAccount.m @@ -980,31 +980,15 @@ static SLGaimCocoaAdapter *gaimThread = nil; - (NSArray *)listObjectsOnPrivacyList:(AIPrivacyType)type { - return (type == AIPrivacyTypePermit ? permittedContactsArray : deniedContactsArray); -} + GSList *list; + GSList *sourceList = ((type == AIPrivacyTypePermit) ? account->permit : account->deny); + NSMutableArray *array = [NSMutableArray array]; -- (NSArray *)listObjectIDsOnPrivacyList:(AIPrivacyType)type -{ - NSArray *listObjectArray = [self listObjectsOnPrivacyList:type]; - NSMutableArray *idArray = [[NSMutableArray alloc] initWithCapacity:[listObjectArray count]]; - NSEnumerator *enumerator = [listObjectArray objectEnumerator]; - AIListObject *object = nil; - - while ((object = [enumerator nextObject])) { - [idArray addObject:[object UID]]; + for (list = sourceList; (list != NULL); list=list->next) { + [array addObject:[self contactWithUID:[NSString stringWithUTF8String:(char *)list->data]]]; } - - return [idArray autorelease]; -} - -- (void)privacyPermitListAdded:(NSString *)sourceUID -{ - [self accountPrivacyList:AIPrivacyTypePermit added:sourceUID]; -} -- (void)privacyDenyListAdded:(NSString *)sourceUID -{ - [self accountPrivacyList:AIPrivacyTypeDeny added:sourceUID]; + return array; } - (void)accountPrivacyList:(AIPrivacyType)type added:(NSString *)sourceUID @@ -1013,19 +997,20 @@ static SLGaimCocoaAdapter *gaimThread = nil; if ([sourceUID length]) { //Get our contact AIListContact *contact = [self contactWithUID:sourceUID]; - - [(type == AIPrivacyTypePermit ? permittedContactsArray : deniedContactsArray) addObject:contact]; + + //Update Adium's knowledge of it + [contact setIsBlocked:((type == AIPrivacyTypeDeny) ? YES : NO) updateList:NO]; } } -- (void)privacyPermitListRemoved:(NSString *)sourceUID +- (void)privacyPermitListAdded:(NSString *)sourceUID { - [self accountPrivacyList:AIPrivacyTypePermit removed:sourceUID]; + [self accountPrivacyList:AIPrivacyTypePermit added:sourceUID]; } -- (void)privacyDenyListRemoved:(NSString *)sourceUID +- (void)privacyDenyListAdded:(NSString *)sourceUID { - [self accountPrivacyList:AIPrivacyTypeDeny removed:sourceUID]; + [self accountPrivacyList:AIPrivacyTypeDeny added:sourceUID]; } - (void)accountPrivacyList:(AIPrivacyType)type removed:(NSString *)sourceUID @@ -1035,18 +1020,29 @@ static SLGaimCocoaAdapter *gaimThread = nil; if (!namesAreCaseSensitive) { sourceUID = [sourceUID compactedString]; } - + //Get our contact, which must already exist for us to care about its removal AIListContact *contact = [[adium contactController] existingContactWithService:service account:self UID:sourceUID]; - if (contact) { - [(type == AIPrivacyTypePermit ? permittedContactsArray : deniedContactsArray) removeObject:contact]; + if (contact) { + //Update Adium's knowledge of it + [contact setIsBlocked:((type == AIPrivacyTypeDeny) ? NO : YES) updateList:NO]; } } } +- (void)privacyPermitListRemoved:(NSString *)sourceUID +{ + [self accountPrivacyList:AIPrivacyTypePermit removed:sourceUID]; +} + +- (void)privacyDenyListRemoved:(NSString *)sourceUID +{ + [self accountPrivacyList:AIPrivacyTypeDeny removed:sourceUID]; +} + - (void)setPrivacyOptions:(AIPrivacyOption)option { if (account && gaim_account_get_connection(account)) { diff --git a/Source/ESBlockingPlugin.m b/Source/ESBlockingPlugin.m index df5861c00..435b8c206 100644 --- a/Source/ESBlockingPlugin.m +++ b/Source/ESBlockingPlugin.m @@ -40,7 +40,6 @@ @interface ESBlockingPlugin(PRIVATE) - (void)_setContact:(AIListContact *)contact isBlocked:(BOOL)isBlocked; -- (BOOL)_searchPrivacyListsForListContact:(AIListContact *)contact withDesiredResult:(BOOL)desiredResult; - (void)accountConnected:(NSNotification *)notification; - (BOOL)areAllGivenContactsBlocked:(NSArray *)contacts; - (void)setPrivacy:(BOOL)block forContacts:(NSArray *)contacts; @@ -350,46 +349,24 @@ } } -- (BOOL)_searchPrivacyListsForListContact:(AIListContact *)contact withDesiredResult:(BOOL)desiredResult -{ - AIAccount *account = nil; - NSEnumerator *enumerator; - - enumerator = [[[adium accountController] accountsCompatibleWithService:[contact service]] objectEnumerator]; - - while ((account = [enumerator nextObject])) { - if ([account conformsToProtocol:@protocol(AIAccount_Privacy)]) { - AIAccount *privacyAccount = (AIAccount *)account; - if ([[privacyAccount listObjectIDsOnPrivacyList:AIPrivacyTypeDeny] containsObject:[contact UID]] == desiredResult) { - return YES; - } - } - } - return NO; -} - /*! * @brief Inform AIListContact instances of the user's intended privacy towards the people they represent */ - (void)accountConnected:(NSNotification *)notification { - //NSLog(@"account connected: %@", notification); - - AIAccount *accountConnected = [notification object]; - NSEnumerator *contactEnumerator = nil; - AIListContact *currentContact = nil; - - if ([accountConnected conformsToProtocol:@protocol(AIAccount_Privacy)]) { + AIAccount *account = [notification object]; + + if ([account conformsToProtocol:@protocol(AIAccount_Privacy)]) { + NSEnumerator *contactEnumerator; + AIListContact *currentContact; + NSArray *blockedContacts = [(AIAccount *)account listObjectsOnPrivacyList:AIPrivacyTypeDeny]; //check if each contact is on the account's deny list - contactEnumerator = [[accountConnected contacts] objectEnumerator]; + contactEnumerator = [[account contacts] objectEnumerator]; while ((currentContact = [contactEnumerator nextObject])) { - //NSLog(@"The current contact is: %@", currentContact); - - if ([[(AIAccount *)accountConnected listObjectIDsOnPrivacyList:AIPrivacyTypeDeny] containsObject:[currentContact UID]]) { + if ([blockedContacts containsObject:[currentContact UID]]) { //inform the contact that they're blocked [currentContact setIsBlocked:YES updateList:NO]; - //NSLog(@"** %@ is blocked **", [currentContact formattedUID]); } else { [currentContact setIsBlocked:NO updateList:NO]; } -- 2.11.4.GIT