public Stream CreateTweet(string sitename, string commentForumId, Tweet tweet) { ISite site = GetSite(sitename); if (site == null) { throw ApiException.GetError(ErrorType.UnknownSite); } try { CommentForum commentForumData = _commentObj.GetCommentForumByUid(commentForumId, site); if (commentForumData == null) { throw ApiException.GetError(ErrorType.ForumUnknown); } _commentObj.CallingUser = GetCallingTwitterUser(site, tweet); if (tweet.IsRetweet) return HandleRetweet(site, commentForumData, tweet); else return HandleTweet(site, commentForumData, tweet); } catch (ApiException ex) { throw new DnaWebProtocolException(ex); } }
public Stream CreateTweet(string sitename, string commentForumId, Tweet tweet) { var auditId = AddTwitterBuzzAudit(commentForumId, tweet.user.id, tweet.user.ScreenName, tweet.Text); try { var site = RetrieveSite(sitename); CommentForum commentForumData = _commentObj.GetCommentForumByUid(commentForumId, site); if (commentForumData == null) { throw ApiException.GetError(ErrorType.ForumUnknown); } _commentObj.CallingUser = GetCallingTwitterUser(site, tweet); if (tweet.IsRetweet) return HandleRetweet(site, commentForumData, tweet); else return HandleTweet(site, commentForumData, tweet); } catch (ApiException ex) { TweetToCommentExceptionHandler(ex, auditId); throw new DnaWebProtocolException(ex); } }
/// <summary> /// Method that choses the way the retweet needs to be handled /// </summary> /// <param name="site"></param> /// <param name="commentForumData"></param> /// <param name="tweet"></param> /// <param name="commentObj"></param> /// <returns></returns> private Stream HandleRetweet(ISite site, CommentForum commentForumData, Tweet tweet) { if (false == string.IsNullOrEmpty(tweet.Text)) { var callingOriginalTweetuser = GetCallingTwitterUser(site, tweet.RetweetedStatus); if (callingOriginalTweetuser.IsTrustedUser()) { return HandleRetweetOriginalTweetByTrustedUsers(site, commentForumData, tweet); } else { return HandleRetweetOriginalTweetByPublicUsers(site, commentForumData, tweet); } } else { throw ApiException.GetError(ErrorType.EmptyText); } }
/// <summary> /// Creates a twitter user and returns the twitter user details /// </summary> /// <param name="site"></param> /// <param name="tweet"></param> /// <returns></returns> private CallingTwitterUser GetCallingTwitterUser(ISite site, Tweet tweet) { var callingTwitterUser = new CallingTwitterUser(readerCreator, dnaDiagnostic, cacheManager); callingTwitterUser.CreateUserFromTwitterUser(site.SiteID, tweet.user); callingTwitterUser.SynchroniseSiteSuffix(tweet.user.ProfileImageUrl); return callingTwitterUser; }
/// <summary> /// Creates the tweet and the relevant tweet info /// </summary> /// <param name="site"></param> /// <param name="commentForumData"></param> /// <param name="tweet"></param> /// <returns></returns> private CommentInfo CreateCommentFromTweet(ISite site, CommentForum commentForumData, Tweet tweet) { _commentObj.CallingUser = GetCallingTwitterUser(site, tweet); CommentInfo commentInfo = _commentObj.CreateComment(commentForumData, tweet.CreateCommentInfo()); if (commentInfo.IsPreModPosting) _commentObj.CreateTweetInfoForPreModPostings(commentInfo.PreModPostingsModId, tweet.id, 0, false); else _commentObj.CreateTweetInfoForComment(commentInfo.ID, tweet.id, 0, false); return commentInfo; }
/// <summary> /// Create the thread entry and capture the tweet info /// </summary> /// <param name="site"></param> /// <param name="commentForumData"></param> /// <param name="tweet"></param> /// <returns></returns> private Stream HandleTweet(ISite site, CommentForum commentForumData, Tweet tweet) { // Retweets starting with @ are not supported for now if (tweet.Text != null && tweet.Text.Trim().StartsWith("@")) { return GetOutputStream(new CommentInfo()); //empty commentinfo object } return GetOutputStream(CreateCommentFromTweet(site, commentForumData, tweet)); }
/// <summary> /// Increment the original tweet's rating value /// </summary> /// <param name="site"></param> /// <param name="commentForumData"></param> /// <param name="tweet"></param> /// <param name="commentId"></param> /// <returns></returns> private int IncrementCommentRating(ISite site, CommentForum commentForumData, Tweet tweet, int commentId) { Guid userHash = DnaHasher.GenerateHash(tweet.RetweetedStatus.id.ToString()); short ratingValue = tweet.RetweetedStatus.RetweetCount(); return _commentObj.CreateCommentRating(commentForumData, site, commentId, 0, ratingValue, userHash); }
/// <summary> /// Adds an entry to the threadmod table and increments the comment rating value /// </summary> /// <param name="site"></param> /// <param name="commentForumData"></param> /// <param name="tweet"></param> /// <returns></returns> private Stream HandleRetweetOriginalTweetByTrustedUsers(ISite site, CommentForum commentForumData, Tweet tweet) { //Add an entry in the ThreadEntry table CommentInfo retweetCommentInfo = CreateCommentFromTweet(site, commentForumData, tweet); var commentId = _commentObj.GetCommentIdFromTweetId(tweet.RetweetedStatus.id); if (commentId < 1) //create the original tweet as it doesn't exist in the system and increment the rating value { CommentInfo originalTweetInfo = CreateCommentFromTweet(site, commentForumData, tweet.RetweetedStatus); IncrementCommentRating(site, commentForumData, tweet, originalTweetInfo.ID); } else //just increment the comment rating value { IncrementCommentRating(site, commentForumData, tweet, commentId); } if (retweetCommentInfo.IsPreModPosting) { _commentObj.CreateRetweetInfoForPreModPostings(retweetCommentInfo.PreModPostingsModId, tweet.id, tweet.RetweetedStatus.id, false); } else { _commentObj.CreateRetweetInfoForComment(retweetCommentInfo.ID, tweet.id, tweet.RetweetedStatus.id, false); } return GetOutputStream(retweetCommentInfo); }
/// <summary> /// Just increments the rating value and ignores the retweet /// </summary> /// <param name="site"></param> /// <param name="commentForumData"></param> /// <param name="tweet"></param> /// <returns></returns> private Stream HandleRetweetOriginalTweetByPublicUsers(ISite site, CommentForum commentForumData, Tweet tweet) { //Capture the retweet info in the thread entry table CommentInfo retweetCommentInfo = CreateCommentFromTweet(site, commentForumData, tweet); var commentId = _commentObj.GetCommentIdFromTweetId(tweet.RetweetedStatus.id); if (commentId > 0) //increment the comment rating value and capture the retweet info { IncrementCommentRating(site, commentForumData, tweet, commentId); if (retweetCommentInfo.IsPreModPosting) { _commentObj.CreateRetweetInfoForPreModPostings(retweetCommentInfo.PreModPostingsModId, tweet.id, tweet.RetweetedStatus.id, false); } else { _commentObj.CreateRetweetInfoForComment(retweetCommentInfo.ID, tweet.id, tweet.RetweetedStatus.id, false); } return GetOutputStream(retweetCommentInfo); } else // capture the retweet info only as the original tweet doesn't exist { if (retweetCommentInfo.IsPreModPosting) { _commentObj.CreateRetweetInfoForPreModPostings(retweetCommentInfo.PreModPostingsModId, tweet.id, tweet.RetweetedStatus.id, true); } else { _commentObj.CreateRetweetInfoForComment(retweetCommentInfo.ID, tweet.id, tweet.RetweetedStatus.id, true); } return GetOutputStream(retweetCommentInfo); } }
private void CreateTweet_SameUserMultipleTweets_Helper(Tweet tweet) { var request = new DnaTestURLRequest(_sitename); var tweetData = CreateTweetJsonData(tweet); // now get the response request.RequestPageWithFullURL(_tweetPostUrlReactive, tweetData, "application/json"); // Check to make sure that the page returned with the correct information var returnedCommentInfo = (CommentInfo)StringUtils.DeserializeJSONObject(request.GetLastResponseAsString(), typeof(CommentInfo)); TestCommentInfo(returnedCommentInfo, tweet); }
private string CreateRetweetJsonData(Tweet tweet, Tweet retweetedTweet) { string s = @" { ""retweeted_status"": { ""text"": """+retweetedTweet.Text+@""", ""retweeted"": false, ""truncated"": false, ""entities"": { ""urls"": [], ""hashtags"": [], ""user_mentions"": [] }, ""id"": "+retweetedTweet.id+@", ""source"": ""web"", ""favorited"": false, ""created_at"": ""Thu Jan 26 13:39:45 +0000 2012"", ""retweet_count"": "+retweetedTweet.RetweetCountString+@", ""id_str"": """+retweetedTweet.id+@""", ""user"": { ""location"": ""White House Press Room "", ""default_profile"": false, ""statuses_count"": 34054, ""profile_background_tile"": false, ""lang"": ""en"", ""profile_link_color"": ""0084B4"", ""id"": "+retweetedTweet.user.id+@", ""favourites_count"": 1156, ""protected"": false, ""profile_text_color"": ""333333"", ""description"": ""Independent White House journalist. Paul\u0027s bio: 5 yrs Moscow, 5 yrs network TV, 5 yrs Wall St.; foreign correspondent, private investor. 53 countries \u0026 counting"", ""contributors_enabled"": false, ""verified"": true, ""name"": """+retweetedTweet.user.Name+@""", ""profile_sidebar_border_color"": ""BDDCAD"", ""profile_background_color"": ""9AE4E8"", ""created_at"": ""Thu Feb 05 20:12:05 +0000 2009"", ""default_profile_image"": false, ""followers_count"": 98478, ""geo_enabled"": false, ""profile_image_url_https"": ""https://si0.twimg.com/profile_images/1467994261/WWR.Logo.Twitter_normal.png"", ""profile_background_image_url"": ""http://a0.twimg.com/profile_background_images/117122710/presidents.jpg"", ""profile_background_image_url_https"": ""https://si0.twimg.com/profile_background_images/117122710/presidents.jpg"", ""utc_offset"": -18000, ""time_zone"": ""Eastern Time (US \u0026 Canada)"", ""profile_use_background_image"": true, ""friends_count"": 625, ""profile_sidebar_fill_color"": ""DDFFCC"", ""screen_name"": """+retweetedTweet.user.ScreenName+@""", ""id_str"": """+retweetedTweet.user.id+@""", ""show_all_inline_media"": false, ""profile_image_url"": ""http://a3.twimg.com/profile_images/1467994261/WWR.Logo.Twitter_normal.png"", ""listed_count"": 4284, ""is_translator"": false } }, ""text"": """+tweet.Text+@""", ""retweeted"": false, ""truncated"": true, ""entities"": { ""urls"": [], ""hashtags"": [], ""user_mentions"": [ { ""id"": 20182089, ""name"": ""West Wing Report"", ""indices"": [ 3, 18 ], ""screen_name"": ""WestWingReport"", ""id_str"": ""20182089"" } ] }, ""id"": "+tweet.id+@", ""source"": ""web"", ""favorited"": false, ""created_at"": ""Thu Jan 26 14:00:35 +0000 2012"", ""retweet_count"": "+tweet.RetweetCountString+@", ""id_str"": """+tweet.id+@""", ""user"": { ""location"": ""Chillicothe, Ohio 45601"", ""default_profile"": false, ""statuses_count"": 34784, ""profile_background_tile"": true, ""lang"": ""en"", ""profile_link_color"": ""cb9934"", ""id"": "+tweet.user.id+@", ""favourites_count"": 68, ""protected"": false, ""profile_text_color"": ""575e61"", ""description"": ""Citizens, educate yourself/others to EMPOWER communities. Harming working middle class does NOT empower people! STAND UP FOR MIDDLE CLASS \u0026 WORKING POOR!"", ""contributors_enabled"": false, ""verified"": false, ""name"": """+tweet.user.Name+@""", ""profile_sidebar_border_color"": ""454b52"", ""profile_background_color"": ""181c1f"", ""created_at"": ""Fri Feb 20 14:02:37 +0000 2009"", ""default_profile_image"": false, ""followers_count"": 1263, ""geo_enabled"": true, ""profile_image_url_https"": ""https://si0.twimg.com/profile_images/1462979161/March_12__2011_Chillicothe_Rally_normal.jpg"", ""profile_background_image_url"": ""http://a2.twimg.com/profile_background_images/340364818/72_PIXELS-2nd_Portia_Rebuilding_the_American_Dream.jpg"", ""profile_background_image_url_https"": ""https://si0.twimg.com/profile_background_images/340364818/72_PIXELS-2nd_Portia_Rebuilding_the_American_Dream.jpg"", ""url"": ""https://www.facebook.com/?sk\u003dlf#!/portia.a.boulger"", ""utc_offset"": -18000, ""time_zone"": ""Eastern Time (US \u0026 Canada)"", ""profile_use_background_image"": true, ""friends_count"": 1956, ""profile_sidebar_fill_color"": ""0e1621"", ""screen_name"": """+tweet.user.ScreenName+@""", ""id_str"": """+tweet.user.id+@""", ""show_all_inline_media"": true, ""profile_image_url"": ""http://a0.twimg.com/profile_images/1462979161/March_12__2011_Chillicothe_Rally_normal.jpg"", ""listed_count"": 44, ""is_translator"": false } }"; return s; }
private string CreateTweetJsonData(Tweet tweet) { if (tweet.RetweetedStatus != null) return CreateRetweetJsonData(tweet, tweet.RetweetedStatus); // Use an actual tweet from Twitter as the source data string s = @"{""id_str"":"""+tweet.id+@""", ""place"":null, ""geo"":{""coordinates"":[28.736,-25.7373],""type"":""Point""}, ""in_reply_to_user_id_str"":null, ""coordinates"":null, ""contributors"":null, ""possibly_sensitive"":false, ""created_at"":""Tue Nov 01 12:07:24 +0000 2011"", ""user"":{""id_str"":""" + tweet.user.id+@""", ""profile_text_color"":""333333"", ""protected"":false, ""profile_image_url_https"":""https:\/\/si0.twimg.com\/profile_images\/99627155\/me_normal.jpg"", ""profile_background_image_url"":""http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png"", ""followers_count"":250, ""profile_image_url"":""http:\/\/a1.twimg.com\/profile_images\/99627155\/me_normal.jpg"", ""name"":"""+tweet.user.Name+@""", ""listed_count"":11, ""contributors_enabled"":false, ""profile_link_color"":""0084B4"", ""show_all_inline_media"":true, ""utc_offset"":0, ""created_at"":""Tue Mar 17 11:52:29 +0000 2009"", ""description"":""Techie\/Startupreneur"", ""default_profile"":true, ""following"":true, ""profile_background_color"":""C0DEED"", ""verified"":false, ""notifications"":false, ""profile_background_tile"":false, ""default_profile_image"":false, ""profile_sidebar_fill_color"":""DDEEF6"", ""time_zone"":""London"", ""profile_background_image_url_https"":""https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png"", ""favourites_count"":8, ""profile_sidebar_border_color"":""C0DEED"", ""location"":""London"", ""screen_name"":"""+tweet.user.ScreenName+@""", ""follow_request_sent"":false, ""statuses_count"":586, ""geo_enabled"":true, ""friends_count"":480, ""id"":"+tweet.user.id+@", ""is_translator"":false, ""lang"":""en"", ""profile_use_background_image"":true, ""url"":""http:\/\/99layers.com\/chico""}, ""retweet_count"":"+tweet.RetweetCountString+@", ""in_reply_to_status_id"":null, ""favorited"":false, ""in_reply_to_screen_name"":null, ""truncated"":false, ""source"":""\u003Ca href=\""http:\/\/www.tweetdeck.com\"" rel=\""nofollow\""\u003ETweetDeck\u003C\/a\u003E"", ""retweeted"":false, ""id"":"+tweet.id+@", ""in_reply_to_status_id_str"":null, ""in_reply_to_user_id"":null, ""text"":""" +tweet.Text+@"""}"; return s; }
private string CreatTweetXmlData(Tweet tweet) { var tweetXml = new XmlDocument(); tweetXml.Load(StringUtils.SerializeToXml(tweet)); var tweetData = tweetXml.DocumentElement.OuterXml; return tweetData; }
private void TestCommentInfo(CommentInfo commentInfo, Tweet tweet) { Assert.AreEqual(tweet.Text, commentInfo.text); Assert.AreEqual(PostStyle.Style.tweet, commentInfo.PostStyle); Assert.AreEqual(tweet.user.Name, commentInfo.User.DisplayName); using (IDnaDataReader reader = _context.CreateDnaDataReader("")) { reader.ExecuteDEBUGONLY("select * from signinuseridmapping where TwitterUserID='" + tweet.user.id + "'"); Assert.IsTrue(reader.HasRows); reader.Read(); var dnaUserId = reader.GetInt32("DnaUserId"); Assert.AreEqual(commentInfo.User.UserId, dnaUserId); Assert.IsFalse(reader.Read()); // Check we only got one row back reader.ExecuteDEBUGONLY("select * from ThreadEntriesTweetInfo where ThreadEntryId=" + commentInfo.ID); Assert.IsTrue(reader.HasRows); reader.Read(); var tweetId = reader.GetInt64("TweetId"); Assert.AreEqual(tweet.id, tweetId); Assert.IsFalse(reader.Read()); // Check we only got one row back } }
private string PostTweet(Tweet tweet, ModerationStatus.ForumStatus modStatus) { var request = new DnaTestURLRequest(_sitename); var tweetData = CreateTweetJsonData(tweet); switch (modStatus) { case ModerationStatus.ForumStatus.PreMod: request.RequestPageWithFullURL(_tweetPostUrlPremod, tweetData, "application/json"); break; case ModerationStatus.ForumStatus.Reactive: request.RequestPageWithFullURL(_tweetPostUrlReactive, tweetData, "application/json"); break; default: Assert.Fail("Unknown modStatus setting"); break; } return request.GetLastResponseAsString(); }