Plugins/Purple Service/PurpleFacebookAccount.m
author Zachary West <zacw@adium.im>
Fri Nov 27 13:11:03 2009 -0500 (2009-11-27)
changeset 2832 c2a6b90a5b53
parent 2731 e559b41be2b6
child 2859 41cc56470598
permissions -rw-r--r--
Enable facebook_manage_friends, so that we can actually manage friends lists. Fixes #13404.
     1 //
     2 //  PurpleFacebookAccount.m
     3 //  Adium
     4 //
     5 //  Created by Evan Schoenberg on 1/15/09.
     6 //  Copyright 2009 Adium X. All rights reserved.
     7 //
     8 
     9 #import "PurpleFacebookAccount.h"
    10 #import <Adium/AIHTMLDecoder.h>
    11 #import <Adium/AIListContact.h>
    12 #import <Adium/AIStatus.h>
    13 
    14 @implementation PurpleFacebookAccount
    15 
    16 - (const char*)protocolPlugin
    17 {
    18     return "prpl-bigbrownchunx-facebookim";
    19 }
    20 
    21 - (NSString *)webProfileStringForContact:(AIListContact *)contact
    22 {
    23 	return [NSString stringWithFormat:NSLocalizedString(@"View %@'s Facebook profile", nil), 
    24 			contact.displayName];
    25 }
    26 
    27 - (void)configurePurpleAccount
    28 {
    29 	[super configurePurpleAccount];
    30 	
    31 	/* We could add a pref for this, but not without some enhancements to mail notifications. Currently, this being
    32 	 * enabled means ugly nasty "You have new mail!" popups continuously, since that's how 'notifications' are passed
    33 	 * to us.
    34 	 */
    35 	purple_account_set_bool(account, "facebook_get_notifications", FALSE);
    36 	
    37 	// We do our own history; don't let the server's history get displayed as new messages
    38 	purple_account_set_bool(account, "facebook_show_history", FALSE);
    39 	
    40 	// Use friends list as groups.
    41 	purple_account_set_bool(account, "facebook_use_groups", TRUE);
    42 	
    43 	// Allow for moving through libpurple
    44 	purple_account_set_bool(account, "facebook_manage_friends", TRUE);
    45 }
    46 
    47 - (NSString *)host
    48 {
    49 	return @"login.facebook.com";
    50 }
    51 
    52 - (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
    53 							  arguments:(NSMutableDictionary *)arguments
    54 {
    55 	if (statusState.statusType == AIOfflineStatusType) {
    56 		return "offline";
    57 	} else {
    58 		return "available";
    59 	}
    60 }
    61 
    62 - (void)setSocialNetworkingStatusMessage:(NSAttributedString *)statusMessage
    63 {
    64 	NSMutableDictionary *arguments = [NSMutableDictionary dictionary];
    65 	NSString *encodedStatusMessage = (statusMessage ? 
    66 									  [self encodedAttributedString:statusMessage
    67 													 forStatusState:nil] :
    68 									  nil);
    69 	if (encodedStatusMessage) {
    70 		[arguments setObject:encodedStatusMessage
    71 					  forKey:@"message"];
    72 	}
    73 
    74 	purple_account_set_bool(account, "facebook_set_status_through_pidgin", TRUE);
    75 	[self setStatusState:nil
    76 				statusID:"available" /* facebook only supports available */
    77 				isActive:[NSNumber numberWithBool:YES]
    78 			   arguments:arguments];
    79 	purple_account_set_bool(account, "facebook_set_status_through_pidgin", FALSE);
    80 }
    81 
    82 - (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forListObject:(AIListObject *)inListObject
    83 {
    84 	return [AIHTMLDecoder encodeHTML:inAttributedString
    85 							 headers:YES
    86 							fontTags:YES
    87 				  includingColorTags:YES
    88 					   closeFontTags:YES
    89 						   styleTags:YES
    90 		  closeStyleTagsOnFontChange:YES
    91 					  encodeNonASCII:NO
    92 						encodeSpaces:NO
    93 						  imagesPath:nil
    94 				   attachmentsAsText:YES
    95 		   onlyIncludeOutgoingImages:NO
    96 					  simpleTagsOnly:NO
    97 					  bodyBackground:NO
    98 				 allowJavascriptURLs:YES];
    99 }
   100 
   101 /*!
   102  * @brief Set an alias for a contact
   103  *
   104  * Normally, we consider the name a 'serverside alias' unless it matches the UID's characters
   105  * However, the UID in facebook should never be presented to the user if possible; it's for internal use
   106  * only.  We'll therefore consider any alias a formatted UID such that it will replace the UID when displayed
   107  * in Adium.
   108  */
   109 - (void)updateContact:(AIListContact *)theContact toAlias:(NSString *)purpleAlias
   110 {
   111 	if (![purpleAlias isEqualToString:theContact.formattedUID] && 
   112 		![purpleAlias isEqualToString:theContact.UID]) {
   113 		[theContact setFormattedUID:purpleAlias
   114 							 notify:NotifyLater];
   115 		
   116 		//Apply any changes
   117 		[theContact notifyOfChangedPropertiesSilently:silentAndDelayed];
   118 	}
   119 }
   120 
   121 @end