private PostClass CreatePostsFromStatusData(TwitterStatus status, bool favTweet)
{
var post = new PostClass();
TwitterEntities entities;
string sourceHtml;
post.StatusId = status.Id;
if (status.RetweetedStatus != null)
{
var retweeted = status.RetweetedStatus;
post.CreatedAt = MyCommon.DateTimeParse(retweeted.CreatedAt);
//Id
post.RetweetedId = retweeted.Id;
//本文
post.TextFromApi = retweeted.FullText;
entities = retweeted.MergedEntities;
sourceHtml = retweeted.Source;
//Reply先
post.InReplyToStatusId = retweeted.InReplyToStatusId;
post.InReplyToUser = retweeted.InReplyToScreenName;
post.InReplyToUserId = status.InReplyToUserId;
if (favTweet)
{
post.IsFav = true;
}
else
{
//幻覚fav対策
var tc = TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites);
post.IsFav = tc.Contains(retweeted.Id);
}
if (retweeted.Coordinates != null)
post.PostGeo = new PostClass.StatusGeo(retweeted.Coordinates.Coordinates[0], retweeted.Coordinates.Coordinates[1]);
//以下、ユーザー情報
var user = retweeted.User;
if (user != null)
{
post.UserId = user.Id;
post.ScreenName = user.ScreenName;
post.Nickname = user.Name.Trim();
post.ImageUrl = user.ProfileImageUrlHttps;
post.IsProtect = user.Protected;
}
else
{
post.UserId = 0L;
post.ScreenName = "?????";
post.Nickname = "Unknown User";
}
//Retweetした人
if (status.User != null)
{
post.RetweetedBy = status.User.ScreenName;
post.RetweetedByUserId = status.User.Id;
post.IsMe = post.RetweetedBy.ToLowerInvariant().Equals(_uname);
}
else
{
post.RetweetedBy = "?????";
post.RetweetedByUserId = 0L;
}
}
else
{
post.CreatedAt = MyCommon.DateTimeParse(status.CreatedAt);
//本文
post.TextFromApi = status.FullText;
entities = status.MergedEntities;
sourceHtml = status.Source;
post.InReplyToStatusId = status.InReplyToStatusId;
post.InReplyToUser = status.InReplyToScreenName;
post.InReplyToUserId = status.InReplyToUserId;
if (favTweet)
{
post.IsFav = true;
}
else
{
//幻覚fav対策
var tc = TabInformations.GetInstance().GetTabByType(MyCommon.TabUsageType.Favorites);
post.IsFav = tc.Contains(post.StatusId) && TabInformations.GetInstance()[post.StatusId].IsFav;
}
if (status.Coordinates != null)
post.PostGeo = new PostClass.StatusGeo(status.Coordinates.Coordinates[0], status.Coordinates.Coordinates[1]);
//以下、ユーザー情報
var user = status.User;
if (user != null)
{
post.UserId = user.Id;
post.ScreenName = user.ScreenName;
post.Nickname = user.Name.Trim();
post.ImageUrl = user.ProfileImageUrlHttps;
post.IsProtect = user.Protected;
post.IsMe = post.ScreenName.ToLowerInvariant().Equals(_uname);
}
else
{
post.UserId = 0L;
post.ScreenName = "?????";
post.Nickname = "Unknown User";
}
}
//HTMLに整形
string textFromApi = post.TextFromApi;
post.Text = CreateHtmlAnchor(textFromApi, post.ReplyToList, entities, post.Media);
post.TextFromApi = textFromApi;
post.TextFromApi = this.ReplaceTextFromApi(post.TextFromApi, entities);
post.TextFromApi = WebUtility.HtmlDecode(post.TextFromApi);
post.TextFromApi = post.TextFromApi.Replace("<3", "\u2661");
post.AccessibleText = this.CreateAccessibleText(textFromApi, entities, (status.RetweetedStatus ?? status).QuotedStatus);
post.AccessibleText = WebUtility.HtmlDecode(post.AccessibleText);
post.AccessibleText = post.AccessibleText.Replace("<3", "\u2661");
post.QuoteStatusIds = GetQuoteTweetStatusIds(entities)
.Where(x => x != post.StatusId && x != post.RetweetedId)
.Distinct().ToArray();
post.ExpandedUrls = entities.OfType<TwitterEntityUrl>()
.Select(x => new PostClass.ExpandedUrlInfo(x.Url, x.ExpandedUrl))
.ToArray();
// メモリ使用量削減 (同一のテキストであれば同一の string インスタンスを参照させる)
if (post.Text == post.TextFromApi)
post.Text = post.TextFromApi;
if (post.AccessibleText == post.TextFromApi)
post.AccessibleText = post.TextFromApi;
// 他の発言と重複しやすい (共通化できる) 文字列は string.Intern を通す
post.ScreenName = string.Intern(post.ScreenName);
post.Nickname = string.Intern(post.Nickname);
post.ImageUrl = string.Intern(post.ImageUrl);
post.RetweetedBy = post.RetweetedBy != null ? string.Intern(post.RetweetedBy) : null;
//Source整形
var source = ParseSource(sourceHtml);
post.Source = string.Intern(source.Item1);
post.SourceUri = source.Item2;
post.IsReply = post.ReplyToList.Contains(_uname);
post.IsExcludeReply = false;
if (post.IsMe)
{
post.IsOwl = false;
}
else
{
if (followerId.Count > 0) post.IsOwl = !followerId.Contains(post.UserId);
}
post.IsDm = false;
return post;
}