Skip to content

Commit

Permalink
use extended entities for 280 tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-ward committed Nov 16, 2017
1 parent 00c95e0 commit 7697811
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 4 deletions.
Binary file modified tweetz/.vs/tweetz5/v15/Server/sqlite3/storage.ide
Binary file not shown.
3 changes: 3 additions & 0 deletions tweetz/tweetz5/Model/Status.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ public class ExtendedTweet
{
[DataMember(Name = "full_text")]
public string FullText { get; set; }

[DataMember(Name = "entities")]
public Entities Entities { get; set; }
}

[DataContract]
Expand Down
11 changes: 7 additions & 4 deletions tweetz/tweetz5/Model/TweetUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public static Tweet CreateTweet(this Status status, TweetClassification tweetTyp
var isDirectMessage = false;
var username = new OAuth().ScreenName;
var displayStatus = status.RetweetedStatus ?? status;
var entities = displayStatus.ExtendedTweet?.Entities ?? displayStatus.Entities;
var text = displayStatus?.ExtendedTweet?.FullText ?? displayStatus.FullText ?? displayStatus.Text;

// Direct messages don't have a User. Instead, dm's use sender and recipient collections.
if (displayStatus.User == null)
Expand All @@ -22,30 +24,31 @@ public static Tweet CreateTweet(this Status status, TweetClassification tweetTyp
displayStatus.User = status.Recipient.ScreenName == username ? status.Sender : status.Recipient;
}

if (status.Entities?.Mentions != null && status.Entities.Mentions.Any(m => m.ScreenName == username))
if (entities?.Mentions != null && entities.Mentions.Any(m => m.ScreenName == username))
{
isMention = true;
}

var createdAt = DateTime.ParseExact(status.CreatedAt, "ddd MMM dd HH:mm:ss zzz yyyy",
CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);


var tweet = new Tweet
{
StatusId = status.Id,
Name = displayStatus.User.Name,
ScreenName = displayStatus.User.ScreenName,
ProfileImageUrl = displayStatus.User.ProfileImageUrl,
Text = displayStatus.Text,
MarkupNodes = BuildMarkupNodes(displayStatus?.ExtendedTweet?.FullText ?? displayStatus.FullText ?? displayStatus.Text, displayStatus.Entities),
MarkupNodes = BuildMarkupNodes(text, entities),
CreatedAt = createdAt,
TimeAgo = TimeAgo(createdAt),
IsRetweet = status.Retweeted,
RetweetedBy = RetweetedBy(status, username),
RetweetedByScreenName = RetweetedByScreenName(status, username),
RetweetStatusId = status.RetweetedStatus != null ? status.RetweetedStatus.Id : string.Empty,
MediaLinks = status.Entities?.Media?.Select(m => m.MediaUrl).ToArray() ?? new string[0],
Urls = status.Entities?.Urls.Select(u => u.ExpandedUrl).ToArray() ?? new string[0],
MediaLinks = entities?.Media?.Select(m => m.MediaUrl).ToArray() ?? new string[0],
Urls = entities?.Urls.Select(u => u.ExpandedUrl).ToArray() ?? new string[0],
IsMyTweet = displayStatus.User.ScreenName == username,
IsHome = tweetType == TweetClassification.Home,
IsMention = tweetType == TweetClassification.Mention | isMention,
Expand Down
Loading

0 comments on commit 7697811

Please sign in to comment.