adium 2276:d087b2dc06e0: Apply classes to the Twitter action lin...
commits at adium.im
commits at adium.im
Sat May 23 17:33:30 UTC 2009
details: http://hg.adium.im/adium/rev/d087b2dc06e0
revision: 2276:d087b2dc06e0
author: Zachary West <zacw at adium.im>
date: Sat May 23 13:33:21 2009 -0400
Apply classes to the Twitter action links. Fixes #12049.
I've stuffed this into AITwitterAccount (the link creation) since AIAttributedStringAdditions can't know about AIHTMLDecoder, and I want to keep from arbitrary defines in AIUtilities for this. It seems iffy to keep it here, but better than hacking around this.
In reply to ("IRT") -> twitter_inReplyTo
Retweet ("RT") -> twitter_reTweet
Reply ("@") -> twitter_reply
Delete (backspace) -> twitter_delete
Favorite (star) -> twitter_favorite
Status link ("#") -> twitter_status
The action links in total (…) are not yet in a classed element. This will change in a future commit.
diffstat:
Frameworks/Adium Framework/Source/AIHTMLDecoder.h | 2 +
Frameworks/Adium Framework/Source/AIHTMLDecoder.m | 8 ++
Plugins/Twitter Plugin/AITwitterAccount.h | 8 ++
Plugins/Twitter Plugin/AITwitterAccount.m | 57 ++++++++++++++----
4 files changed, 61 insertions(+), 14 deletions(-)
diffs (171 lines):
diff -r ad85d31457ce -r d087b2dc06e0 Frameworks/Adium Framework/Source/AIHTMLDecoder.h
--- a/Frameworks/Adium Framework/Source/AIHTMLDecoder.h Sat May 23 12:46:07 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIHTMLDecoder.h Sat May 23 13:33:21 2009 -0400
@@ -52,6 +52,8 @@
BOOL inLogSpan;
}
+#define AIElementClassAttributeName @"AIElementClass"
+
#pragma mark Creation
//+decoder, +new, and -init all return an instance with all flags set to 0.
diff -r ad85d31457ce -r d087b2dc06e0 Frameworks/Adium Framework/Source/AIHTMLDecoder.m
--- a/Frameworks/Adium Framework/Source/AIHTMLDecoder.m Sat May 23 12:46:07 2009 -0400
+++ b/Frameworks/Adium Framework/Source/AIHTMLDecoder.m Sat May 23 13:33:21 2009 -0400
@@ -437,6 +437,14 @@
[string appendString:@"\" title=\""];
[string appendString:linkString];
}
+
+ NSString *classString = [attributes objectForKey:AIElementClassAttributeName];
+
+ if (!thingsToInclude.simpleTagsOnly && classString) {
+ [string appendString:@"\" class=\""];
+ [string appendString:classString];
+ }
+
[string appendString:@"\">"];
oldLink = linkString;
diff -r ad85d31457ce -r d087b2dc06e0 Plugins/Twitter Plugin/AITwitterAccount.h
--- a/Plugins/Twitter Plugin/AITwitterAccount.h Sat May 23 12:46:07 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.h Sat May 23 13:33:21 2009 -0400
@@ -67,6 +67,14 @@
AITwitterLinkDestroyDM
} AITwitterLinkType;
+// HTML class names
+#define AITwitterInReplyToClassName @"twitter_inReplyTo"
+#define AITwitterRetweetClassName @"twitter_reTweet"
+#define AITwitterReplyClassName @"twitter_reply"
+#define AITwitterDeleteClassName @"twitter_delete"
+#define AITwitterFavoriteClassName @"twitter_favorite"
+#define AITwitterStatusLinkClassName @"twitter_status"
+
#define TWITTER_UPDATE_INTERVAL_MINUTES 10 // Used as the default Preferences
#define TWITTER_UPDATE_TIMELINE_COUNT_FIRST_RUN 50
diff -r ad85d31457ce -r d087b2dc06e0 Plugins/Twitter Plugin/AITwitterAccount.m
--- a/Plugins/Twitter Plugin/AITwitterAccount.m Sat May 23 12:46:07 2009 -0400
+++ b/Plugins/Twitter Plugin/AITwitterAccount.m Sat May 23 13:33:21 2009 -0400
@@ -53,6 +53,9 @@
- (NSAttributedString *)parseDirectMessage:(NSString *)inMessage
withID:(NSString *)dmID
fromUser:(NSString *)sourceUID;
+- (NSAttributedString *)attributedStringWithLinkLabel:(NSString *)label
+ linkDestination:(NSString *)destination
+ linkClass:(NSString *)attributeName;
- (void)setRequestType:(AITwitterRequestType)type forRequestID:(NSString *)requestID withDictionary:(NSDictionary *)info;
- (AITwitterRequestType)requestTypeForRequestID:(NSString *)requestID;
@@ -1254,6 +1257,25 @@
}
/*!
+ * @brief Convert a link URL and name into an attributed link
+ *
+ * @param label The text to display for the link.
+ * @param destination The destination address for the link.
+ * @param attributeName The name of the twitter link attribute for HTML processing.
+ */
+- (NSAttributedString *)attributedStringWithLinkLabel:(NSString *)label
+ linkDestination:(NSString *)destination
+ linkClass:(NSString *)className
+{
+ NSURL *url = [NSURL URLWithString:destination];
+ NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
+ url, NSLinkAttributeName,
+ className, AIElementClassAttributeName, nil];
+
+ return [[[NSAttributedString alloc] initWithString:label attributes:attributes] autorelease];
+}
+
+/*!
* @brief Parse an attributed string into a linkified version.
*/
- (NSAttributedString *)linkifiedAttributedStringFromString:(NSAttributedString *)inString
@@ -1332,8 +1354,9 @@
} else {
// This happens for mentions which are in_reply_to_status_id but the @target isn't the first part of the message.
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:AILocalizedString(@"IRT", "An abbreviation for 'in reply to' - placed at the beginning of the tweet tools for those which are directly in reply to another")
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:AILocalizedString(@"IRT", "An abbreviation for 'in reply to' - placed at the beginning of the tweet tools for those which are directly in reply to another")
+ linkDestination:linkAddress
+ linkClass:AITwitterInReplyToClassName]];
commaNeeded = YES;
}
@@ -1355,8 +1378,9 @@
statusID:tweetID
context:[inMessage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:@"RT"
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:@"RT"
+ linkDestination:linkAddress
+ linkClass:AITwitterRetweetClassName]];
commaNeeded = YES;
}
@@ -1369,8 +1393,9 @@
statusID:tweetID
context:nil];
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:@"@"
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:@"@"
+ linkDestination:linkAddress
+ linkClass:AITwitterReplyClassName]];
} else {
if(commaNeeded) {
[mutableMessage appendString:@", " withAttributes:nil];
@@ -1382,8 +1407,9 @@
statusID:tweetID
context:[inMessage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:@"\u232B"
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:@"\u232B"
+ linkDestination:linkAddress
+ linkClass:AITwitterDeleteClassName]];
}
[mutableMessage appendString:@", " withAttributes:nil];
@@ -1393,8 +1419,9 @@
statusID:tweetID
context:nil];
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:@"\u2606"
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:@"\u2606"
+ linkDestination:linkAddress
+ linkClass:AITwitterFavoriteClassName]];
[mutableMessage appendString:@", " withAttributes:nil];
@@ -1403,8 +1430,9 @@
statusID:tweetID
context:nil];
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:@"#"
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:@"#"
+ linkDestination:linkAddress
+ linkClass:AITwitterStatusLinkClassName]];
}
@@ -1438,8 +1466,9 @@
statusID:dmID
context:[inMessage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
- [mutableMessage appendAttributedString:[NSAttributedString attributedStringWithLinkLabel:@"\u232B"
- linkDestination:linkAddress]];
+ [mutableMessage appendAttributedString:[self attributedStringWithLinkLabel:@"\u232B"
+ linkDestination:linkAddress
+ linkClass:AITwitterDeleteClassName]];
[mutableMessage appendString:@")" withAttributes:nil];
More information about the commits
mailing list