William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againadium / Plugins / Purple Service / PurpleFacebookAccount.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | //
// PurpleFacebookAccount.m
// Adium
//
// Created by Evan Schoenberg on 1/15/09.
// Copyright 2009 Adium X. All rights reserved.
//
#import "PurpleFacebookAccount.h"
#import <Adium/AIHTMLDecoder.h>
#import <Adium/AIListContact.h>
#import <Adium/AIStatus.h>
#import "PurpleFacebookService.h"
#import <AIUtilities/AIMenuAdditions.h>
#import <Adium/AIMetaContact.h>
@implementation PurpleFacebookAccount
- (const char*)protocolPlugin
{
return "prpl-bigbrownchunx-facebookim";
}
- (NSString *)webProfileStringForContact:(AIListContact *)contact
{
return [NSString stringWithFormat:AILocalizedString(@"View %@'s Facebook profile", nil),
contact.displayName];
}
- (void)configurePurpleAccount
{
[super configurePurpleAccount];
/* We could add a pref for this, but not without some enhancements to mail notifications. Currently, this being
* enabled means ugly nasty "You have new mail!" popups continuously, since that's how 'notifications' are passed
* to us.
*/
purple_account_set_bool(account, "facebook_get_notifications", FALSE);
}
- (NSString *)host
{
return @"login.facebook.com";
}
- (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
arguments:(NSMutableDictionary *)arguments
{
if (statusState.statusType == AIOfflineStatusType) {
return "offline";
} else {
return "available";
}
}
- (void)setSocialNetworkingStatusMessage:(NSAttributedString *)statusMessage
{
NSMutableDictionary *arguments = [NSMutableDictionary dictionary];
NSString *encodedStatusMessage = (statusMessage ?
[self encodedAttributedString:statusMessage
forStatusState:nil] :
nil);
if (encodedStatusMessage) {
[arguments setObject:encodedStatusMessage
forKey:@"message"];
}
purple_account_set_bool(account, "facebook_set_status_through_pidgin", TRUE);
[self setStatusState:nil
statusID:"available" /* facebook only supports available */
isActive:[NSNumber numberWithBool:YES]
arguments:arguments];
purple_account_set_bool(account, "facebook_set_status_through_pidgin", FALSE);
}
- (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forListObject:(AIListObject *)inListObject
{
return [AIHTMLDecoder encodeHTML:inAttributedString
headers:YES
fontTags:YES
includingColorTags:YES
closeFontTags:YES
styleTags:YES
closeStyleTagsOnFontChange:YES
encodeNonASCII:NO
encodeSpaces:NO
imagesPath:nil
attachmentsAsText:YES
onlyIncludeOutgoingImages:NO
simpleTagsOnly:NO
bodyBackground:NO
allowJavascriptURLs:YES];
}
/*!
* @brief Set an alias for a contact
*
* Normally, we consider the name a 'serverside alias' unless it matches the UID's characters
* However, the UID in facebook should never be presented to the user if possible; it's for internal use
* only. We'll therefore consider any alias a formatted UID such that it will replace the UID when displayed
* in Adium.
*/
- (void)updateContact:(AIListContact *)theContact toAlias:(NSString *)purpleAlias
{
if (![purpleAlias isEqualToString:theContact.formattedUID] &&
![purpleAlias isEqualToString:theContact.UID]) {
[theContact setFormattedUID:purpleAlias
notify:NotifyLater];
//Apply any changes
[theContact notifyOfChangedPropertiesSilently:silentAndDelayed];
}
}
#pragma mark Menu Items
/*!
* @brief Menu items for contact
*
* Returns an array of menu items for a contact on this account. This is the best place to add protocol-specific
* actions that aren't otherwise supported by Adium.
* @param inContact AIListContact for menu items
* @return NSArray of NSMenuItem instances for the passed contact
*/
- (NSArray *)menuItemsForContact:(AIListContact *)inContact
{
NSMutableArray *menuItemArray = [NSMutableArray array];
//Fill with any items supplied by libpurple
[menuItemArray addObjectsFromArray:[super menuItemsForContact:inContact]];
//Add a new menu item with the facebook icon to view the contacts profile
NSMenuItem *menuItem;
NSImage *serviceIcon = [AIServiceIcons serviceIconForService:self.service
type:AIServiceIconSmall
direction:AIIconNormal];
menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[NSString stringWithFormat:AILocalizedString(@"View %@'s Facebook profile", nil), inContact.displayName]
target:self
action:@selector(viewFacebookProfile:)
keyEquivalent:@""] autorelease];
[menuItem setImage:serviceIcon];
[menuItem setRepresentedObject:inContact];
[menuItemArray addObject:menuItem];
//Don't return an empty array
if (![menuItemArray count]) menuItemArray = nil;
return menuItemArray;
}
/*!
* @brief Open Facebook Profile
*
* Opens the selected contacts or chats facebook profile in the default web browser
*/
- (void)viewFacebookProfile:(NSMenuItem *)menuItem
{
AIListContact *contact = (AIListContact *)menuItem.representedObject;
NSString *url = [NSString stringWithFormat:@"http://www.facebook.com/profile.php?id=%@",[contact UID]];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:url]];
}
@end
|