adium 4172:f5b424ece00d: Patch from kbotc based on one by brion:...
commits at adium.im
commits at adium.im
Mon Aug 22 20:19:20 UTC 2011
details: http://hg.adium.im/adium/rev/f5b424ece00d
revision: 4172:f5b424ece00d
branch: (none)
author: Robert Vehse
date: Mon Aug 22 22:19:05 2011 +0200
Patch from kbotc based on one by brion: allow overriding the 140 character limit for StatusNet. Fixes #13485.
diffs (191 lines):
diff -r d29e1b34966c -r f5b424ece00d Plugins/Twitter Plugin/AILaconicaAccount.h
--- a/Plugins/Twitter Plugin/AILaconicaAccount.h Mon Aug 22 13:06:41 2011 +0200
+++ b/Plugins/Twitter Plugin/AILaconicaAccount.h Mon Aug 22 22:19:05 2011 +0200
@@ -23,7 +23,12 @@
#define LACONICA_REMOTE_GROUP_NAME @"StatusNet"
@interface AILaconicaAccount : AITwitterAccount {
-
+ //For servers that allow more than 140 characters to be used as a status.
+ int textlimit;
+ NSURLConnection *textLimitConfigDownload;
+ NSMutableData *configData;
}
+- (void)queryTextLimit;
+
@end
diff -r d29e1b34966c -r f5b424ece00d Plugins/Twitter Plugin/AILaconicaAccount.m
--- a/Plugins/Twitter Plugin/AILaconicaAccount.m Mon Aug 22 13:06:41 2011 +0200
+++ b/Plugins/Twitter Plugin/AILaconicaAccount.m Mon Aug 22 22:19:05 2011 +0200
@@ -17,6 +17,7 @@
#import "AILaconicaAccount.h"
#import "AITwitterURLParser.h"
#import <Adium/AIContactObserverManager.h>
+#import <Adium/AIChatControllerProtocol.h>
@interface AITwitterAccount()
@@ -119,6 +120,97 @@
}
/*!
+ * @brief Connection successful
+ *
+ * Pull all the usual stuff, but also check for the max notice length,
+ * provided by StatusNet 0.9 and later.
+ */
+- (void)didConnect
+{
+ [super didConnect];
+
+ textLimitConfigDownload = nil;
+ [self queryTextLimit];
+
+ AIChat *timelineChat = [adium.chatController existingChatWithName:self.timelineChatName
+ onAccount:self];
+ if (timelineChat) {
+ [self updateTimelineChat: timelineChat];
+ }
+}
+
+/*!
+ * @brief Query the StatusNet API for the site/textlimit config variable.
+ * Returns the limit if present, or the default of 140.
+ */
+- (void)queryTextLimit
+{
+ // Hardcoded default for older servers that don't report their configured limit.
+ textlimit = 140;
+
+ NSString *path = [[@"/" stringByAppendingPathComponent:self.apiPath]
+ stringByAppendingPathComponent:@"statusnet/config.xml"];
+
+ NSURL *url = [[NSURL alloc] initWithScheme:(self.useSSL ? @"https" : @"http")
+ host:self.host
+ path:path];
+
+ NSURLRequest *configRequest = [NSURLRequest requestWithURL:url];
+
+ if (textLimitConfigDownload) {
+ [textLimitConfigDownload cancel];
+ [textLimitConfigDownload release]; textLimitConfigDownload = nil;
+ }
+
+ textLimitConfigDownload = [[NSURLConnection alloc] initWithRequest:configRequest delegate:self];
+}
+
+/*!
+ * @brief Downloads the configuration xml file from the server.
+ */
+-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
+{
+ if ([connection isEqual:textLimitConfigDownload])
+ [configData appendData:data];
+
+}
+
+-(void)connectionDidFinishLoading:(NSURLConnection *)connection
+{
+ if ([connection isEqual:textLimitConfigDownload]) {
+ NSError *err=nil;
+ NSXMLDocument *config = [[NSXMLDocument alloc] initWithData:configData
+ options:0
+ error:&err];
+
+ if (config != nil) {
+ NSArray *nodes = [config nodesForXPath:@"/config/site/textlimit"
+ error:&err];
+ if (nodes != nil) {
+ if ([nodes count] > 0)
+ textlimit = [[(NSXMLNode *)[nodes objectAtIndex: 0] stringValue] intValue];
+ }
+ }
+
+ if (err != nil)
+ AILogWithSignature(@"Failed fetching StatusNet server config for %@: %d %@", self.host, [err code], [err localizedDescription]);
+ }
+}
+
+/*!
+ * @brief This method is called when there is an error
+ */
+-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
+{
+ [textLimitConfigDownload release]; textLimitConfigDownload = nil;
+
+ [configData release];
+ configData = nil;
+
+ AILogWithSignature(@"%@",[NSString stringWithFormat:@"Fetch failed: %@", [error localizedDescription]]);
+}
+
+/*!
* @brief Returns the link URL for a specific type of link
*/
- (NSString *)addressForLinkType:(AITwitterLinkType)linkType
@@ -221,4 +313,13 @@
return LACONICA_REMOTE_GROUP_NAME;
}
+/*!
+ * @brief Returns the maximum number of characters available for a post, or 0 if unlimited.
+ * For StatusNet servers, this may have been provided via API.
+ */
+- (int)maxChars
+{
+ return textlimit;
+}
+
@end
diff -r d29e1b34966c -r f5b424ece00d Plugins/Twitter Plugin/AITwitterAccount.h
--- a/Plugins/Twitter Plugin/AITwitterAccount.h Mon Aug 22 13:06:41 2011 +0200
+++ b/Plugins/Twitter Plugin/AITwitterAccount.h Mon Aug 22 22:19:05 2011 +0200
@@ -169,6 +169,7 @@
@property (readonly, nonatomic) NSString *sourceToken;
@property (readonly, nonatomic) NSString *defaultServer;
+ at property (readonly, nonatomic) int maxChars;
@property (readonly, nonatomic) BOOL useSSL;
@property (readonly, nonatomic) BOOL useOAuth;
@property (readonly, nonatomic) BOOL supportsCursors;
@@ -200,4 +201,6 @@
statusID:(NSString *)statusID
context:(NSString *)context;
+- (void)updateTimelineChat:(AIChat *)timelineChat;
+
@end
diff -r d29e1b34966c -r f5b424ece00d Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m Mon Aug 22 13:06:41 2011 +0200
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m Mon Aug 22 22:19:05 2011 +0200
@@ -325,6 +325,16 @@
}
/*!
+ * @brief Returns the maximum number of characters available for a post, or 0 if unlimited.
+ *
+ * For Twitter, this is hardcoded to 140.
+ */
+- (int)maxChars
+{
+ return 140;
+}
+
+/*!
* @brief Returns whether or not to connect to Twitter API over HTTPS.
*/
- (BOOL)useSSL
@@ -896,7 +906,11 @@
// Update the participant list.
[timelineChat addParticipatingListObjects:self.contacts notify:NotifyNow];
- [timelineChat setValue:[NSNumber numberWithInt:140] forProperty:@"Character Counter Max" notify:NotifyNow];
+ NSNumber *max = nil;
+ if (self.maxChars > 0) {
+ max = [NSNumber numberWithInt:self.maxChars];
+ }
+ [timelineChat setValue:max forProperty:@"Character Counter Max" notify:NotifyNow];
}
/*!
More information about the commits
mailing list