diff --git a/OpenTween/Twitter.cs b/OpenTween/Twitter.cs index 257a0d80a..b500c4010 100644 --- a/OpenTween/Twitter.cs +++ b/OpenTween/Twitter.cs @@ -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) @@ -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) @@ -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 GetStatusApi(TwitterStatusId id, bool firstLoad = false) @@ -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); } } @@ -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); } /// @@ -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) @@ -1299,7 +1249,7 @@ public async Task GetFavoritesApi(FavoritesTabModel tab, bool backward, bool fir } } - this.CreateFavoritePostsFromJson(statuses, firstLoad); + this.EnqueuePostsFromJson(statuses, tab, firstLoad); } ///