Skip to content

Commit

Permalink
タブの種類別に分かれていたCreatePostsFromJsonメソッドを統合
Browse files Browse the repository at this point in the history
  • Loading branch information
upsilon committed May 4, 2024
1 parent 2c58d52 commit f1a3493
Showing 1 changed file with 16 additions and 66 deletions.
82 changes: 16 additions & 66 deletions OpenTween/Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public async Task GetHomeTimelineApi(HomeTabModel tab, bool more, bool firstLoad
}
}

this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Timeline, tab, firstLoad);
this.EnqueuePostsFromJson(statuses, tab, firstLoad);
}

public async Task GetMentionsTimelineApi(MentionsTabModel tab, bool more, bool firstLoad)
Expand Down Expand Up @@ -733,7 +733,7 @@ public async Task GetMentionsTimelineApi(MentionsTabModel tab, bool more, bool f
}
}

this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.Reply, tab, firstLoad);
this.EnqueuePostsFromJson(statuses, tab, firstLoad);
}

public async Task GetUserTimelineApi(UserTimelineTabModel tab, bool more, bool firstLoad)
Expand Down Expand Up @@ -787,7 +787,7 @@ public async Task GetUserTimelineApi(UserTimelineTabModel tab, bool more, bool f
}
}

this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.UserTimeline, tab, firstLoad);
this.EnqueuePostsFromJson(statuses, tab, firstLoad);
}

public async Task<PostClass> GetStatusApi(TwitterStatusId id, bool firstLoad = false)
Expand Down Expand Up @@ -828,76 +828,26 @@ private PostClass CreatePostsFromStatusData(TwitterStatus status, bool firstLoad
return post;
}

private void CreatePostsFromJson(TwitterStatus[] items, MyCommon.WORKERTYPE gType, TabModel? tab, bool firstLoad)
private void EnqueuePostsFromJson(TwitterStatus[] items, TabModel tab, bool firstLoad)
{
var posts = items.Select(x => this.CreatePostsFromStatusData(x, firstLoad)).ToArray();

TwitterPostFactory.AdjustSortKeyForPromotedPost(posts);

foreach (var post in posts)
if (tab is not UserTimelineTabModel)
{
// 二重取得回避
lock (this.lockObj)
{
var id = post.StatusId;
if (tab == null)
{
if (TabInformations.GetInstance().ContainsKey(id)) continue;
}
else
{
if (tab.Contains(id)) continue;
}
}

// RT禁止ユーザーによるもの
if (gType != MyCommon.WORKERTYPE.UserTimeline &&
post.RetweetedByUserId != null && this.noRTId.Contains(post.RetweetedByUserId.Value)) continue;

if (tab != null && tab is InternalStorageTabModel)
tab.AddPostQueue(post);
else
TabInformations.GetInstance().AddPost(post);
// RT 禁止ユーザーによる RT を除外
posts = posts.Where(
x => x.RetweetedByUserId == null || this.noRTId.Contains(x.RetweetedByUserId.Value)
).ToArray();
}
}

private void CreatePostsFromSearchJson(TwitterStatus[] statuses, PublicSearchTabModel tab, bool firstLoad)
{
var posts = statuses.Select(x => this.CreatePostsFromStatusData(x, firstLoad)).ToArray();

TwitterPostFactory.AdjustSortKeyForPromotedPost(posts);

foreach (var post in posts)
{
// 二重取得回避
lock (this.lockObj)
{
if (tab.Contains(post.StatusId))
continue;
}

tab.AddPostQueue(post);
}
}

private void CreateFavoritePostsFromJson(TwitterStatus[] items, bool firstLoad)
{
var favTab = TabInformations.GetInstance().FavoriteTab;

foreach (var status in items)
{
var statusId = new TwitterStatusId(status.IdStr);

// 二重取得回避
lock (this.lockObj)
{
if (favTab.Contains(statusId))
continue;
}

var post = this.CreatePostsFromStatusData(status, firstLoad, favTweet: true);

TabInformations.GetInstance().AddPost(post);
if (tab is InternalStorageTabModel)
tab.AddPostQueue(post);
else
TabInformations.GetInstance().AddPost(post);
}
}

Expand Down Expand Up @@ -942,7 +892,7 @@ public async Task GetListStatus(ListTimelineTabModel tab, bool more, bool firstL
}
}

this.CreatePostsFromJson(statuses, MyCommon.WORKERTYPE.List, tab, firstLoad);
this.EnqueuePostsFromJson(statuses, tab, firstLoad);
}

/// <summary>
Expand Down Expand Up @@ -1179,7 +1129,7 @@ public async Task GetSearch(PublicSearchTabModel tab, bool more, bool firstLoad)
if (!TabInformations.GetInstance().ContainsTab(tab))
return;

this.CreatePostsFromSearchJson(statuses, tab, firstLoad);
this.EnqueuePostsFromJson(statuses, tab, firstLoad);
}

public async Task GetDirectMessageEvents(DirectMessagesTabModel dmTab, bool backward, bool firstLoad)
Expand Down Expand Up @@ -1299,7 +1249,7 @@ public async Task GetFavoritesApi(FavoritesTabModel tab, bool backward, bool fir
}
}

this.CreateFavoritePostsFromJson(statuses, firstLoad);
this.EnqueuePostsFromJson(statuses, tab, firstLoad);
}

/// <summary>
Expand Down

0 comments on commit f1a3493

Please sign in to comment.