|
zacw@1033
|
1 |
/* |
|
zacw@1033
|
2 |
* Adium is the legal property of its developers, whose names are listed in the copyright file included |
|
zacw@1033
|
3 |
* with this source distribution. |
|
zacw@1033
|
4 |
* |
|
zacw@1033
|
5 |
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|
zacw@1033
|
6 |
* General Public License as published by the Free Software Foundation; either version 2 of the License, |
|
zacw@1033
|
7 |
* or (at your option) any later version. |
|
zacw@1033
|
8 |
* |
|
zacw@1033
|
9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|
zacw@1033
|
10 |
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
zacw@1033
|
11 |
* Public License for more details. |
|
zacw@1033
|
12 |
* |
|
zacw@1033
|
13 |
* You should have received a copy of the GNU General Public License along with this program; if not, |
|
zacw@1033
|
14 |
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
zacw@1033
|
15 |
*/ |
|
zacw@1033
|
16 |
|
|
zacw@1033
|
17 |
#import "AILaconicaAccount.h" |
|
zacw@1035
|
18 |
#import "AITwitterURLParser.h" |
|
zacw@1033
|
19 |
|
|
zacw@1033
|
20 |
@implementation AILaconicaAccount |
|
zacw@1033
|
21 |
|
|
zacw@2725
|
22 |
- (void)initAccount |
|
zacw@2725
|
23 |
{ |
|
zacw@2725
|
24 |
[super initAccount]; |
|
zacw@2725
|
25 |
[adium.preferenceController registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys: |
|
zacw@2725
|
26 |
[NSNumber numberWithBool:YES], LACONICA_PREFERENCE_SSL, nil] |
|
zacw@2725
|
27 |
forGroup:LACONICA_PREF_GROUP |
|
zacw@2725
|
28 |
object:self]; |
|
zacw@2725
|
29 |
} |
|
zacw@2725
|
30 |
|
|
zacw@1033
|
31 |
- (void)connect |
|
zacw@1041
|
32 |
{ |
|
zacw@1121
|
33 |
if (!self.host) { |
|
zacw@1033
|
34 |
[self setLastDisconnectionError:AILocalizedString(@"No Host set", nil)]; |
|
zacw@1033
|
35 |
[self didDisconnect]; |
|
zacw@1033
|
36 |
} else { |
|
zacw@1033
|
37 |
[super connect]; |
|
zacw@1033
|
38 |
} |
|
zacw@1033
|
39 |
} |
|
zacw@1033
|
40 |
|
|
zacw@1033
|
41 |
/*! |
|
zacw@1121
|
42 |
* @brief Our default server if none is provided. |
|
zacw@1121
|
43 |
* |
|
zacw@1121
|
44 |
* Do not set a default server. |
|
zacw@1033
|
45 |
*/ |
|
zacw@1121
|
46 |
- (NSString *)defaultServer |
|
zacw@1033
|
47 |
{ |
|
zacw@1121
|
48 |
return nil; |
|
zacw@1033
|
49 |
} |
|
zacw@1033
|
50 |
|
|
zacw@1033
|
51 |
/*! |
|
zacw@1033
|
52 |
* @brief API path |
|
zacw@1033
|
53 |
* |
|
zacw@1033
|
54 |
* The API path extension for the given host. |
|
zacw@1033
|
55 |
*/ |
|
zacw@1033
|
56 |
- (NSString *)apiPath |
|
zacw@1033
|
57 |
{ |
|
zacw@1041
|
58 |
// We need to guarantee this is an NSString, so -stringByAppendingPathComponent works. |
|
zacw@1043
|
59 |
NSString *path = [self preferenceForKey:LACONICA_PREFERENCE_PATH group:LACONICA_PREF_GROUP] ?: @""; |
|
zacw@1041
|
60 |
|
|
zacw@1041
|
61 |
return [path stringByAppendingPathComponent:@"api"]; |
|
zacw@1041
|
62 |
} |
|
zacw@1041
|
63 |
|
|
zacw@1041
|
64 |
/*! |
|
zacw@1041
|
65 |
* @brief Our source token |
|
zacw@1041
|
66 |
* |
|
zacw@1041
|
67 |
* On Laconica, our given source token is "adium". |
|
zacw@1041
|
68 |
*/ |
|
zacw@1041
|
69 |
- (NSString *)sourceToken |
|
zacw@1041
|
70 |
{ |
|
zacw@1041
|
71 |
return @"adium"; |
|
zacw@1033
|
72 |
} |
|
zacw@1033
|
73 |
|
|
zacw@1114
|
74 |
/*! |
|
zacw@1114
|
75 |
* @brief Our explicit formatted UID |
|
zacw@1114
|
76 |
* |
|
zacw@1114
|
77 |
* This includes "additional necessary identifying information". |
|
zacw@1114
|
78 |
*/ |
|
zacw@1114
|
79 |
- (NSString *)explicitFormattedUID |
|
zacw@1113
|
80 |
{ |
|
zacw@1114
|
81 |
if (self.host) { |
|
zacw@1114
|
82 |
return [NSString stringWithFormat:@"%@ (%@)", self.UID, self.host]; |
|
zacw@1114
|
83 |
} else { |
|
zacw@1114
|
84 |
return self.UID; |
|
zacw@1114
|
85 |
} |
|
zacw@1113
|
86 |
} |
|
zacw@1113
|
87 |
|
|
zacw@1033
|
88 |
/*! |
|
zacw@1121
|
89 |
* @brief Use our host for the servername when storing password |
|
zacw@1121
|
90 |
*/ |
|
zacw@1121
|
91 |
- (BOOL)useHostForPasswordServerName |
|
zacw@1121
|
92 |
{ |
|
zacw@1121
|
93 |
return YES; |
|
zacw@1121
|
94 |
} |
|
zacw@1121
|
95 |
|
|
zacw@1121
|
96 |
/*! |
|
zacw@2725
|
97 |
* @brief Not all StatusNet instances support HTTPS connections. |
|
zacw@2725
|
98 |
*/ |
|
zacw@2725
|
99 |
- (BOOL)useSSL |
|
zacw@2725
|
100 |
{ |
|
zacw@2725
|
101 |
return [[self preferenceForKey:LACONICA_PREFERENCE_SSL group:LACONICA_PREF_GROUP] boolValue]; |
|
zacw@2725
|
102 |
} |
|
zacw@2725
|
103 |
|
|
zacw@2725
|
104 |
/*! |
|
zacw@1132
|
105 |
* @brief Laconica does not yet support OAuth. |
|
zacw@1132
|
106 |
*/ |
|
zacw@1132
|
107 |
- (BOOL)useOAuth |
|
zacw@1132
|
108 |
{ |
|
zacw@1132
|
109 |
return NO; |
|
zacw@1132
|
110 |
} |
|
zacw@1132
|
111 |
|
|
zacw@1132
|
112 |
/*! |
|
zacw@1033
|
113 |
* @brief Returns the link URL for a specific type of link |
|
zacw@1033
|
114 |
*/ |
|
zacw@1033
|
115 |
- (NSString *)addressForLinkType:(AITwitterLinkType)linkType |
|
zacw@1033
|
116 |
userID:(NSString *)userID |
|
zacw@1033
|
117 |
statusID:(NSString *)statusID |
|
zacw@1034
|
118 |
context:(NSString *)context |
|
zacw@1033
|
119 |
{ |
|
zacw@1035
|
120 |
NSString *address = [super addressForLinkType:linkType userID:userID statusID:statusID context:context]; |
|
zacw@1033
|
121 |
|
|
zacw@1041
|
122 |
NSString *fullAddress = [self.host stringByAppendingPathComponent:[self preferenceForKey:LACONICA_PREFERENCE_PATH group:LACONICA_PREF_GROUP]]; |
|
zacw@1041
|
123 |
|
|
zacw@2725
|
124 |
NSString *protocol = self.useSSL ? @"https" : @"http"; |
|
zacw@2725
|
125 |
|
|
zacw@1033
|
126 |
if (linkType == AITwitterLinkStatus) { |
|
zacw@2725
|
127 |
address = [NSString stringWithFormat:@"%@://%@/notice/%@", protocol, fullAddress, statusID]; |
|
zacw@1033
|
128 |
} else if (linkType == AITwitterLinkFriends) { |
|
zacw@2725
|
129 |
address = [NSString stringWithFormat:@"%@://%@/%@/subscriptions", protocol, fullAddress, userID]; |
|
zacw@1033
|
130 |
} else if (linkType == AITwitterLinkFollowers) { |
|
zacw@2725
|
131 |
address = [NSString stringWithFormat:@"%@://%@/%@/subscribers", protocol, fullAddress, userID]; |
|
zacw@1033
|
132 |
} else if (linkType == AITwitterLinkUserPage) { |
|
zacw@2725
|
133 |
address = [NSString stringWithFormat:@"%@://%@/%@", protocol, fullAddress, userID]; |
|
zacw@1034
|
134 |
} else if (linkType == AITwitterLinkSearchHash) { |
|
zacw@1041
|
135 |
address = [NSString stringWithFormat:@"http://%@/tag/%@", fullAddress, context]; |
|
zacw@1035
|
136 |
} else if (linkType == AITwitterLinkGroup) { |
|
zacw@1041
|
137 |
address = [NSString stringWithFormat:@"http://%@/group/%@", fullAddress, context]; |
|
zacw@1033
|
138 |
} |
|
zacw@1033
|
139 |
|
|
zacw@1033
|
140 |
return address; |
|
zacw@1033
|
141 |
} |
|
zacw@1033
|
142 |
|
|
zacw@1035
|
143 |
/*! |
|
zacw@1035
|
144 |
* @brief Parse an attributed string into a linkified version. |
|
zacw@1035
|
145 |
*/ |
|
zacw@1035
|
146 |
- (NSAttributedString *)linkifiedAttributedStringFromString:(NSAttributedString *)inString |
|
zacw@1035
|
147 |
{ |
|
zacw@1035
|
148 |
NSAttributedString *attributedString = [super linkifiedAttributedStringFromString:inString]; |
|
zacw@1623
|
149 |
|
|
zacw@1623
|
150 |
static NSCharacterSet *groupCharacters = nil; |
|
zacw@1623
|
151 |
|
|
zacw@1623
|
152 |
if (!groupCharacters) { |
|
zacw@1623
|
153 |
NSMutableCharacterSet *disallowedCharacters = [[NSCharacterSet punctuationCharacterSet] mutableCopy]; |
|
zacw@1623
|
154 |
[disallowedCharacters formUnionWithCharacterSet:[NSCharacterSet whitespaceCharacterSet]]; |
|
zacw@1623
|
155 |
|
|
zacw@1623
|
156 |
groupCharacters = [[disallowedCharacters invertedSet] retain]; |
|
zacw@1623
|
157 |
|
|
zacw@1623
|
158 |
[disallowedCharacters release]; |
|
zacw@1623
|
159 |
} |
|
zacw@1035
|
160 |
|
|
zacw@1035
|
161 |
attributedString = [AITwitterURLParser linkifiedStringFromAttributedString:attributedString |
|
zacw@1035
|
162 |
forPrefixCharacter:@"!" |
|
zacw@1035
|
163 |
forLinkType:AITwitterLinkGroup |
|
zacw@1035
|
164 |
forAccount:self |
|
zacw@1623
|
165 |
validCharacterSet:groupCharacters]; |
|
zacw@1035
|
166 |
|
|
zacw@1035
|
167 |
return attributedString; |
|
zacw@1035
|
168 |
} |
|
zacw@1035
|
169 |
|
|
zacw@1033
|
170 |
@end |