From 83f57f5092fd96fef29fd2784ed5d7701b52378b Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Wed, 7 Nov 2012 20:49:14 +0000 Subject: Merged with original Twitter: v1.1.0.0 - fixed some memory leaks (thx borkra) - fixed up some API v1.1 preferences - avatars now work for users that tweet - fixed the retweet truncation issue finally (properly this time), i test for the "retweeted_status" attribute now instead of flailing around blindly. git-svn-id: http://svn.miranda-ng.org/main/trunk@2239 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Twitter/src/twitter.cpp | 67 ++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 39 deletions(-) (limited to 'protocols/Twitter/src/twitter.cpp') diff --git a/protocols/Twitter/src/twitter.cpp b/protocols/Twitter/src/twitter.cpp index f5c3d1a8b3..ffba858f7a 100644 --- a/protocols/Twitter/src/twitter.cpp +++ b/protocols/Twitter/src/twitter.cpp @@ -349,53 +349,42 @@ std::vector twitter::get_statuses(int count,twitter_id id) { const js::object &one = boost::any_cast(**i); const js::object &user = retrieve(one,"user"); - //size_t RTcount = retrieve(one,"retweet_count", true); // why doesn't this work?? it can't cast the output into an int even though twitter api says it's an int twitter_user u; u.username = retrieve(user,"screen_name"); - - std::string rawText = retrieve(one,"text"); - bool foundTruncatedRT = false; - if (rawText.length() == 140) { // might be a truncated tweet - if (rawText.substr(0, 4) == "RT @") { // starting to look like a RT... - if (rawText.substr(136, 4) == " ...") { // ok this is the best I can do. it starts with "RT @", ends with " ...", and is the full 140 chars - - - //if (RTcount > 0) { // the tweet will be truncated unless we take action. i hate you twitter API - //MessageBox(NULL, L"retweeted: TRUE", L"long tweets", MB_OK); - // here we grab the "retweeted_status" um.. section? it's in here that all the info we need is - // at this point the user will get no tweets and an error popup if the tweet happens to be exactly 140 chars, start with - // "RT @", end in " ...", and notactually be a real retweet. it's possible but unlikely, wish i knew how to get - // the retweet_count variable to work :( - const js::object &Retweet = retrieve(one,"retweeted_status"); - const js::object &RTUser = retrieve(Retweet,"user"); - - std::string retweeteesName = retrieve(RTUser,"screen_name"); // the user that is being retweeted - std::string retweetText = retrieve(Retweet,"text"); // their tweet in all it's untruncated glory - - // fix "&" in the tweets :( - size_t pos = 0; - while((pos = retweetText.find("&", pos)) != std::string::npos) { - retweetText.replace(pos, 5, "&"); - pos += 1; - } - - u.status.text = "RT @" + retweeteesName + " " + retweetText; // mash it together in some format people will understand - foundTruncatedRT = true; - } + u.profile_image_url = retrieve(user,"profile_image_url"); + + // the tweet will be truncated unless we take action. i hate you twitter API + if(one.find("retweeted_status") != one.end()) + { + //MessageBox(NULL, L"retweeted: TRUE", L"long tweets", MB_OK); + // here we grab the "retweeted_status" um.. section? it's in here that all the info we need is + // at this point the user will get no tweets and an error popup if the tweet happens to be exactly 140 chars, start with + // "RT @", end in " ...", and notactually be a real retweet. it's possible but unlikely, wish i knew how to get + // the retweet_count variable to work :( + const js::object &Retweet = retrieve(one,"retweeted_status"); + const js::object &RTUser = retrieve(Retweet,"user"); + + std::string retweeteesName = retrieve(RTUser,"screen_name"); // the user that is being retweeted + std::string retweetText = retrieve(Retweet,"text"); // their tweet in all it's untruncated glory + + // fix "&" in the tweets :( + for(size_t pos = 0;(pos = retweetText.find("&", pos)) != std::string::npos;pos++) + { + retweetText.replace(pos, 5, "&"); } - } - - if (foundTruncatedRT == false) { // if it's not truncated, then the twitter API returns the native RT correctly anyway, - - //std::string twt = retrieve(one,"text"); // no need to do this anymore, we already grabbed it above in rawText + u.status.text = "RT @" + retweeteesName + " " + retweetText; // mash it together in some format people will understand + } + else + { + // if it's not truncated, then the twitter API returns the native RT correctly anyway, + std::string rawText = retrieve(one,"text"); // ok here i'm trying some way to fix all the "&" things that are showing up // i dunno why it's happening, so i'll just find and replace each occurance :/ - size_t pos = 0; - while((pos = rawText.find("&", pos)) != std::string::npos) { + for(size_t pos = 0;(pos = rawText.find("&", pos)) != std::string::npos;pos++) + { rawText.replace(pos, 5, "&"); - pos += 1; } u.status.text = rawText; -- cgit v1.2.3