adium 2277:150e268bff74: Format our action links into an overall...
commits at adium.im
commits at adium.im
Sat May 23 17:54:19 UTC 2009
details: http://hg.adium.im/adium/rev/150e268bff74
revision: 2277:150e268bff74
author: Zachary West <zacw at adium.im>
date: Sat May 23 13:54:12 2009 -0400
Format our action links into an overall classed span, and class the left and right parenthesis so they can be easily hidden/removed. Refs #12049.
This creates something in the format of:
{{{
<span class="twitter_actions">
<span class="twitter_actionStart">(</span>
<a href="…" class="…">…</a>
<a href="…" class="…">…</a>
<a href="…" class="…">…</a>
<span class="twitter_actionEnd">)</span>
</span>
}}}
for all twitter messages which have action links.
diffstat:
Adium.xcodeproj/project.pbxproj | 6 ++
Plugins/Twitter Plugin/AITwitterAccount.h | 2 +
Plugins/Twitter Plugin/AITwitterAccount.m | 6 ++
Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.h | 15 +++++
Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.m | 70 +++++++++++++++++++++++
Source/AICoreComponentLoader.m | 1 +
6 files changed, 100 insertions(+), 0 deletions(-)
diffs (176 lines):
diff -r d087b2dc06e0 -r 150e268bff74 Adium.xcodeproj/project.pbxproj
--- a/Adium.xcodeproj/project.pbxproj Sat May 23 13:33:21 2009 -0400
+++ b/Adium.xcodeproj/project.pbxproj Sat May 23 13:54:12 2009 -0400
@@ -103,6 +103,7 @@
112B490A0F82FB1700690E84 /* AIGroupChatStatusTooltipPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 112B49090F82FB1700690E84 /* AIGroupChatStatusTooltipPlugin.m */; };
112B4A250F83194700690E84 /* AIMentionAdvancedPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 112B4A240F83194700690E84 /* AIMentionAdvancedPreferences.m */; };
112B4A3E0F831A4400690E84 /* AIMentionAdvancedPreferences.nib in Resources */ = {isa = PBXBuildFile; fileRef = 112B4A3D0F831A4400690E84 /* AIMentionAdvancedPreferences.nib */; };
+ 112E7FA60FC86BB400657119 /* AITwitterActionsHTMLFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 112E7FA50FC86BB400657119 /* AITwitterActionsHTMLFilter.m */; };
113891830F6B6AFF00A7D7DC /* AILaconicaService.m in Sources */ = {isa = PBXBuildFile; fileRef = 113891820F6B6AFF00A7D7DC /* AILaconicaService.m */; };
1138918A0F6B6B2800A7D7DC /* AILaconicaAccount.m in Sources */ = {isa = PBXBuildFile; fileRef = 113891890F6B6B2800A7D7DC /* AILaconicaAccount.m */; };
1138918D0F6B6B3F00A7D7DC /* AILaconicaPlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 1138918C0F6B6B3F00A7D7DC /* AILaconicaPlugin.m */; };
@@ -1795,6 +1796,8 @@
112B4A230F83194700690E84 /* AIMentionAdvancedPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AIMentionAdvancedPreferences.h; path = Source/AIMentionAdvancedPreferences.h; sourceTree = "<group>"; };
112B4A240F83194700690E84 /* AIMentionAdvancedPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AIMentionAdvancedPreferences.m; path = Source/AIMentionAdvancedPreferences.m; sourceTree = "<group>"; };
112B4A3D0F831A4400690E84 /* AIMentionAdvancedPreferences.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = AIMentionAdvancedPreferences.nib; path = Resources/AIMentionAdvancedPreferences.nib; sourceTree = "<group>"; };
+ 112E7FA40FC86BB400657119 /* AITwitterActionsHTMLFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AITwitterActionsHTMLFilter.h; path = "Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.h"; sourceTree = "<group>"; };
+ 112E7FA50FC86BB400657119 /* AITwitterActionsHTMLFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AITwitterActionsHTMLFilter.m; path = "Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.m"; sourceTree = "<group>"; };
113891810F6B6AFF00A7D7DC /* AILaconicaService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AILaconicaService.h; path = "Plugins/Twitter Plugin/AILaconicaService.h"; sourceTree = "<group>"; };
113891820F6B6AFF00A7D7DC /* AILaconicaService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AILaconicaService.m; path = "Plugins/Twitter Plugin/AILaconicaService.m"; sourceTree = "<group>"; };
113891880F6B6B2800A7D7DC /* AILaconicaAccount.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AILaconicaAccount.h; path = "Plugins/Twitter Plugin/AILaconicaAccount.h"; sourceTree = "<group>"; };
@@ -4915,6 +4918,8 @@
11F738F80F58D18700B3285B /* AITwitterService.m */,
11F738F00F58D12200B3285B /* AITwitterAccount.h */,
11F738F10F58D12200B3285B /* AITwitterAccount.m */,
+ 112E7FA40FC86BB400657119 /* AITwitterActionsHTMLFilter.h */,
+ 112E7FA50FC86BB400657119 /* AITwitterActionsHTMLFilter.m */,
);
name = Twitter;
sourceTree = "<group>";
@@ -10402,6 +10407,7 @@
1139011C0F85C9450081A418 /* AIURLHandlerPlugin.m in Sources */,
11E786810F8860210014612E /* AIJumpControlPlugin.m in Sources */,
1121B29A0F896A720047EC66 /* AIContactVisibilityControlPlugin.m in Sources */,
+ 112E7FA60FC86BB400657119 /* AITwitterActionsHTMLFilter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
diff -r d087b2dc06e0 -r 150e268bff74 Plugins/Twitter Plugin/AITwitterAccount.h
--- a/Plugins/Twitter Plugin/AITwitterAccount.h Sat May 23 13:33:21 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.h Sat May 23 13:54:12 2009 -0400
@@ -75,6 +75,8 @@
#define AITwitterFavoriteClassName @"twitter_favorite"
#define AITwitterStatusLinkClassName @"twitter_status"
+#define AITwitterActionLinksAttributeName @"AITwitterActionLinks"
+
#define TWITTER_UPDATE_INTERVAL_MINUTES 10 // Used as the default Preferences
#define TWITTER_UPDATE_TIMELINE_COUNT_FIRST_RUN 50
diff -r d087b2dc06e0 -r 150e268bff74 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m Sat May 23 13:33:21 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m Sat May 23 13:54:12 2009 -0400
@@ -1334,6 +1334,8 @@
if (replyTweet || tweetLink) {
NSMutableAttributedString *mutableMessage = [[message mutableCopy] autorelease];
+ NSUInteger startIndex = message.length;
+
[mutableMessage appendString:@" (" withAttributes:nil];
BOOL commaNeeded = NO;
@@ -1437,6 +1439,10 @@
}
[mutableMessage appendString:@")" withAttributes:nil];
+
+ [mutableMessage addAttribute:AITwitterActionLinksAttributeName
+ value:[NSNumber numberWithBool:YES]
+ range:NSMakeRange(startIndex, mutableMessage.length - startIndex)];
return mutableMessage;
} else {
diff -r d087b2dc06e0 -r 150e268bff74 Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.h Sat May 23 13:54:12 2009 -0400
@@ -0,0 +1,15 @@
+//
+// AITwitterActionsHTMLFilter.h
+// Adium
+//
+// Created by Zachary West on 2009-05-23.
+// Copyright 2009 Adium. All rights reserved.
+//
+
+#import <Adium/AIContentControllerProtocol.h>
+
+ at interface AITwitterActionsHTMLFilter : AIPlugin <AIHTMLContentFilter> {
+
+}
+
+ at end
diff -r d087b2dc06e0 -r 150e268bff74 Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.m
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Twitter Plugin/AITwitterActionsHTMLFilter.m Sat May 23 13:54:12 2009 -0400
@@ -0,0 +1,70 @@
+//
+// AITwitterActionsHTMLFilter.m
+// Adium
+//
+// Created by Zachary West on 2009-05-23.
+// Copyright 2009 Adium. All rights reserved.
+//
+
+#import "AITwitterActionsHTMLFilter.h"
+#import "AITwitterAccount.h"
+#import <Adium/AIContentControllerProtocol.h>
+#import <Adium/AIContentMessage.h>
+#import <AIUtilities/AIMutableStringAdditions.h>
+
+ at implementation AITwitterActionsHTMLFilter
+
+- (void)installPlugin
+{
+ // Twitter only sends incoming text, so we don't have to worry about outgoing.
+ [adium.contentController registerHTMLContentFilter:self direction:AIFilterIncoming];
+}
+
+- (void)uninstallPlugin
+{
+ [adium.contentController unregisterHTMLContentFilter:self];
+}
+
+/*!
+ * @brief Convert action link areas to proper HTML.
+ *
+ * (…) at the end of a message is converted into properly-formatted spans.
+ */
+- (NSString *)filterHTMLString:(NSString *)inHTMLString content:(AIContentObject*)content
+{
+ if ([content isKindOfClass:[AIContentMessage class]] && content.message.length) {
+ NSDictionary *attributes = [content.message attributesAtIndex:content.message.length-1 effectiveRange:nil];
+
+ if ([[attributes objectForKey:AITwitterActionLinksAttributeName] boolValue]) {
+ // We're in a valid message; let's replace!
+
+ NSMutableString *mutableHTML = [inHTMLString mutableCopy];
+
+ // Replace the start with <span class="twitter_actions"><span class="twitter_actionStart>(</span>
+ // This overall span will be ended next.
+ [mutableHTML replaceOccurrencesOfString:@"("
+ withString:@"<span class=\"twitter_actions\"><span class=\"twitter_actionStart\">(</span>"
+ options:NSBackwardsSearch];
+
+ // Replace the end with <span class="twitter_actionEnd">)</span></span>
+ // The second </span> finishes off the overall actions links span.
+ [mutableHTML replaceOccurrencesOfString:@")"
+ withString:@"<span class=\"twitter_actionEnd\">)</span></span>"
+ options:NSBackwardsSearch];
+
+ return [mutableHTML autorelease];
+ }
+ }
+
+ return inHTMLString;
+}
+
+/*!
+ * @brief We don't really care when we're processed.
+ */
+- (CGFloat)filterPriority
+{
+ return LOWEST_FILTER_PRIORITY;
+}
+
+ at end
diff -r d087b2dc06e0 -r 150e268bff74 Source/AICoreComponentLoader.m
--- a/Source/AICoreComponentLoader.m Sat May 23 13:33:21 2009 -0400
+++ b/Source/AICoreComponentLoader.m Sat May 23 13:54:12 2009 -0400
@@ -149,6 +149,7 @@
@"AITwitterPlugin",
@"AILaconicaPlugin",
@"AITwitterURLHandler",
+ @"AITwitterActionsHTMLFilter",
@"AIURLShortenerPlugin",
@"AIGroupChatStatusTooltipPlugin",
@"AIRealNameTooltip",
More information about the commits
mailing list