From 1e8fb3180589d8009d612833b8bc2b02556677d7 Mon Sep 17 00:00:00 2001 From: Kimura Youichi Date: Tue, 17 May 2016 00:37:59 +0900 Subject: [PATCH] =?utf8?q?TweenMain=E3=82=AF=E3=83=A9=E3=82=B9=E5=86=85?= =?utf8?q?=E3=81=A7=E8=A1=8C=E3=81=A3=E3=81=A6=E3=81=84=E3=82=8B=E5=90=84?= =?utf8?q?=E3=82=BF=E3=83=96=E3=81=AE=E6=9B=B4=E6=96=B0=E5=87=A6=E7=90=86?= =?utf8?q?=E3=82=92TabModel=E3=81=AE=E6=B4=BE=E7=94=9F=E3=82=AF=E3=83=A9?= =?utf8?q?=E3=82=B9=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- OpenTween/Models/DirectMessagesTabModel.cs | 20 ++ OpenTween/Models/FavoritesTabModel.cs | 18 ++ OpenTween/Models/FilterTabModel.cs | 7 + OpenTween/Models/HomeTabModel.cs | 22 ++ OpenTween/Models/ListTimelineTabModel.cs | 21 ++ OpenTween/Models/LocalSearchTabModel.cs | 3 + OpenTween/Models/MentionsTabModel.cs | 18 ++ OpenTween/Models/MuteTabModel.cs | 3 + OpenTween/Models/PublicSearchTabModel.cs | 21 ++ OpenTween/Models/RelatedPostsTabModel.cs | 21 ++ OpenTween/Models/TabModel.cs | 2 + OpenTween/Models/UserTimelineTabModel.cs | 21 ++ OpenTween/Tween.cs | 400 ++++------------------------- 13 files changed, 223 insertions(+), 354 deletions(-) diff --git a/OpenTween/Models/DirectMessagesTabModel.cs b/OpenTween/Models/DirectMessagesTabModel.cs index f6f8e6f2..f2426a29 100644 --- a/OpenTween/Models/DirectMessagesTabModel.cs +++ b/OpenTween/Models/DirectMessagesTabModel.cs @@ -45,5 +45,25 @@ namespace OpenTween.Models public DirectMessagesTabModel(string tabName) : base(tabName) { } + + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8, backward ? -1 : 1)); + + await tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, backward) + .ConfigureAwait(false); + await tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, backward) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11); + } } } diff --git a/OpenTween/Models/FavoritesTabModel.cs b/OpenTween/Models/FavoritesTabModel.cs index 900a2c84..10983eb2 100644 --- a/OpenTween/Models/FavoritesTabModel.cs +++ b/OpenTween/Models/FavoritesTabModel.cs @@ -45,5 +45,23 @@ namespace OpenTween.Models public FavoritesTabModel(string tabName) : base(tabName) { } + + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19); + + await tw.GetFavoritesApi(read, backward) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20); + } } } diff --git a/OpenTween/Models/FilterTabModel.cs b/OpenTween/Models/FilterTabModel.cs index d71a3d07..c14752bb 100644 --- a/OpenTween/Models/FilterTabModel.cs +++ b/OpenTween/Models/FilterTabModel.cs @@ -169,5 +169,12 @@ namespace OpenTween.Models } } } + + public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + var homeTab = TabInformations.GetInstance().GetTabByType(); + + return homeTab.RefreshAsync(tw, backward, startup, progress); + } } } diff --git a/OpenTween/Models/HomeTabModel.cs b/OpenTween/Models/HomeTabModel.cs index cfa607c8..2a8af335 100644 --- a/OpenTween/Models/HomeTabModel.cs +++ b/OpenTween/Models/HomeTabModel.cs @@ -60,6 +60,28 @@ namespace OpenTween.Models this.UpdateTimelineSpeed(post.CreatedAt); } + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5, backward ? -1 : 1)); + + await tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Timeline, backward, startup) + .ConfigureAwait(false); + + // 新着時未読クリア + if (SettingCommon.Instance.ReadOldPosts) + TabInformations.GetInstance().SetReadHomeTab(); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1); + } + /// /// タイムラインに追加された発言件数を反映し、タイムラインの流速を更新します /// diff --git a/OpenTween/Models/ListTimelineTabModel.cs b/OpenTween/Models/ListTimelineTabModel.cs index 97f558fb..22861b83 100644 --- a/OpenTween/Models/ListTimelineTabModel.cs +++ b/OpenTween/Models/ListTimelineTabModel.cs @@ -45,5 +45,26 @@ namespace OpenTween.Models { this.ListInfo = list; } + + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + if (this.ListInfo == null || this.ListInfo.Id == 0) + return; + + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report("List refreshing..."); + + await tw.GetListStatus(read, this, backward, startup) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report("List refreshed"); + } } } diff --git a/OpenTween/Models/LocalSearchTabModel.cs b/OpenTween/Models/LocalSearchTabModel.cs index b75900ae..26e6402a 100644 --- a/OpenTween/Models/LocalSearchTabModel.cs +++ b/OpenTween/Models/LocalSearchTabModel.cs @@ -37,5 +37,8 @@ namespace OpenTween.Models public LocalSearchTabModel(string tabName) : base(tabName) { } + + public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + => Task.FromResult(0); // 何もしない } } diff --git a/OpenTween/Models/MentionsTabModel.cs b/OpenTween/Models/MentionsTabModel.cs index 6ae31168..525a99fa 100644 --- a/OpenTween/Models/MentionsTabModel.cs +++ b/OpenTween/Models/MentionsTabModel.cs @@ -45,5 +45,23 @@ namespace OpenTween.Models public MentionsTabModel(string tabName) : base(tabName) { } + + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4, backward ? -1 : 1)); + + await tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Reply, backward, startup) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9); + } } } diff --git a/OpenTween/Models/MuteTabModel.cs b/OpenTween/Models/MuteTabModel.cs index e0390947..fd0c88f6 100644 --- a/OpenTween/Models/MuteTabModel.cs +++ b/OpenTween/Models/MuteTabModel.cs @@ -43,5 +43,8 @@ namespace OpenTween.Models public override void AddPostQueue(PostClass post) { } + + public override Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + => Task.FromResult(0); // 何もしない } } diff --git a/OpenTween/Models/PublicSearchTabModel.cs b/OpenTween/Models/PublicSearchTabModel.cs index 1bee7502..554133eb 100644 --- a/OpenTween/Models/PublicSearchTabModel.cs +++ b/OpenTween/Models/PublicSearchTabModel.cs @@ -64,5 +64,26 @@ namespace OpenTween.Models public PublicSearchTabModel(string tabName) : base(tabName) { } + + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + if (string.IsNullOrEmpty(this.SearchWords)) + return; + + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report("Search refreshing..."); + + await tw.GetSearch(read, this, backward) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report("Search refreshed"); + } } } diff --git a/OpenTween/Models/RelatedPostsTabModel.cs b/OpenTween/Models/RelatedPostsTabModel.cs index 086988eb..8b29b90a 100644 --- a/OpenTween/Models/RelatedPostsTabModel.cs +++ b/OpenTween/Models/RelatedPostsTabModel.cs @@ -47,5 +47,26 @@ namespace OpenTween.Models { this.TargetPost = targetPost; } + + public Task RefreshAsync(Twitter tw, bool startup, IProgress progress) + => this.RefreshAsync(tw, false, startup, progress); + + public override async Task RefreshAsync(Twitter tw, bool _, bool startup, IProgress progress) + { + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report("Related refreshing..."); + + await tw.GetRelatedResult(read, this) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report("Related refreshed"); + } } } diff --git a/OpenTween/Models/TabModel.cs b/OpenTween/Models/TabModel.cs index 827539da..43956c9b 100644 --- a/OpenTween/Models/TabModel.cs +++ b/OpenTween/Models/TabModel.cs @@ -80,6 +80,8 @@ namespace OpenTween.Models this.TabName = tabName; } + public abstract Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress); + private struct TemporaryId { public long StatusId { get; } diff --git a/OpenTween/Models/UserTimelineTabModel.cs b/OpenTween/Models/UserTimelineTabModel.cs index 6dafdea0..72c13dac 100644 --- a/OpenTween/Models/UserTimelineTabModel.cs +++ b/OpenTween/Models/UserTimelineTabModel.cs @@ -45,5 +45,26 @@ namespace OpenTween.Models { this.ScreenName = screenName; } + + public override async Task RefreshAsync(Twitter tw, bool backward, bool startup, IProgress progress) + { + if (string.IsNullOrEmpty(this.ScreenName)) + return; + + bool read; + if (!SettingCommon.Instance.UnreadManage) + read = true; + else + read = startup && SettingCommon.Instance.Read; + + progress.Report("UserTimeline refreshing..."); + + await tw.GetUserTimelineApi(read, this.ScreenName, this, backward) + .ConfigureAwait(false); + + TabInformations.GetInstance().DistributePosts(); + + progress.Report("UserTimeline refreshed"); + } } } diff --git a/OpenTween/Tween.cs b/OpenTween/Tween.cs index b4a70dc2..2d585d86 100644 --- a/OpenTween/Tween.cs +++ b/OpenTween/Tween.cs @@ -262,6 +262,7 @@ namespace OpenTween private const int MAX_WORKER_THREADS = 20; private SemaphoreSlim workerSemaphore = new SemaphoreSlim(MAX_WORKER_THREADS); private CancellationTokenSource workerCts = new CancellationTokenSource(); + private IProgress workerProgress; private int UnreadCounter = -1; private int UnreadAtCounter = -1; @@ -2243,9 +2244,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + var homeTab = this._statuses.GetTabByType(); + await homeTab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetHomeTimelineAsyncInternal(progress, this.workerCts.Token, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2258,42 +2260,6 @@ namespace OpenTween } } - private async Task GetHomeTimelineAsyncInternal(IProgress p, CancellationToken ct, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText5, loadMore ? -1 : 1)); - - await Task.Run(async () => - { - await this.tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Timeline, loadMore, this._initial) - .ConfigureAwait(false); - - // 新着時未読クリア - if (this._cfgCommon.ReadOldPosts) - this._statuses.SetReadHomeTab(); - - var addCount = this._statuses.DistributePosts(); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText1); - - this.RefreshTimeline(); - } - private Task GetReplyAsync() { return this.GetReplyAsync(loadMore: false); @@ -2305,9 +2271,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + var replyTab = this._statuses.GetTabByType(); + await replyTab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetReplyAsyncInternal(progress, this.workerCts.Token, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2320,38 +2287,6 @@ namespace OpenTween } } - private async Task GetReplyAsyncInternal(IProgress p, CancellationToken ct, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText4, loadMore ? -1 : 1)); - - await Task.Run(async () => - { - await this.tw.GetTimelineApi(read, MyCommon.WORKERTYPE.Reply, loadMore, this._initial) - .ConfigureAwait(false); - - this._statuses.DistributePosts(); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText9); - - this.RefreshTimeline(); - } - private Task GetDirectMessagesAsync() { return this.GetDirectMessagesAsync(loadMore: false); @@ -2363,9 +2298,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + var dmTab = this._statuses.GetTabByType(); + await dmTab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetDirectMessagesAsyncInternal(progress, this.workerCts.Token, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2378,40 +2314,6 @@ namespace OpenTween } } - private async Task GetDirectMessagesAsyncInternal(IProgress p, CancellationToken ct, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText8, loadMore ? -1 : 1)); - - await Task.Run(async () => - { - await this.tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeRcv, loadMore) - .ConfigureAwait(false); - await this.tw.GetDirectMessageApi(read, MyCommon.WORKERTYPE.DirectMessegeSnt, loadMore) - .ConfigureAwait(false); - - this._statuses.DistributePosts(); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText11); - - this.RefreshTimeline(); - } - private Task GetFavoritesAsync() { return this.GetFavoritesAsync(loadMore: false); @@ -2423,9 +2325,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + var favTab = this._statuses.GetTabByType(); + await favTab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetFavoritesAsyncInternal(progress, this.workerCts.Token, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2438,38 +2341,6 @@ namespace OpenTween } } - private async Task GetFavoritesAsyncInternal(IProgress p, CancellationToken ct, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText19); - - await Task.Run(async () => - { - await this.tw.GetFavoritesApi(read, loadMore) - .ConfigureAwait(false); - - this._statuses.DistributePosts(); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText20); - - this.RefreshTimeline(); - } - private Task GetPublicSearchAllAsync() { var tabs = this._statuses.GetTabsByType(); @@ -2493,9 +2364,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + foreach (var tab in tabs) + await tab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetPublicSearchAsyncInternal(progress, this.workerCts.Token, tabs, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2508,60 +2380,6 @@ namespace OpenTween } } - private async Task GetPublicSearchAsyncInternal(IProgress p, CancellationToken ct, IEnumerable tabs, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report("Search refreshing..."); - - await Task.Run(async () => - { - WebApiException lastException = null; - - foreach (var tab in tabs) - { - try - { - if (string.IsNullOrEmpty(tab.SearchWords)) - continue; - - await this.tw.GetSearch(read, tab, false) - .ConfigureAwait(false); - - if (loadMore) - await this.tw.GetSearch(read, tab, true) - .ConfigureAwait(false); - } - catch (WebApiException ex) - { - lastException = ex; - } - } - - this._statuses.DistributePosts(); - - if (lastException != null) - throw new WebApiException(lastException.Message, lastException); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report("Search refreshed"); - - this.RefreshTimeline(); - } - private Task GetUserTimelineAllAsync() { var tabs = this._statuses.GetTabsByType(); @@ -2585,9 +2403,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + foreach (var tab in tabs) + await tab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetUserTimelineAsyncInternal(progress, this.workerCts.Token, tabs, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2600,56 +2419,6 @@ namespace OpenTween } } - private async Task GetUserTimelineAsyncInternal(IProgress p, CancellationToken ct, IEnumerable tabs, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report("UserTimeline refreshing..."); - - await Task.Run(async () => - { - WebApiException lastException = null; - - foreach (var tab in tabs) - { - try - { - if (string.IsNullOrEmpty(tab.ScreenName)) - continue; - - await this.tw.GetUserTimelineApi(read, tab.ScreenName, tab, loadMore) - .ConfigureAwait(false); - } - catch (WebApiException ex) - { - lastException = ex; - } - } - - this._statuses.DistributePosts(); - - if (lastException != null) - throw new WebApiException(lastException.Message, lastException); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report("UserTimeline refreshed"); - - this.RefreshTimeline(); - } - private Task GetListTimelineAllAsync() { var tabs = this._statuses.GetTabsByType(); @@ -2673,9 +2442,10 @@ namespace OpenTween try { - var progress = new Progress(x => this.StatusLabel.Text = x); + foreach (var tab in tabs) + await tab.RefreshAsync(this.tw, loadMore, this._initial, this.workerProgress); - await this.GetListTimelineAsyncInternal(progress, this.workerCts.Token, tabs, loadMore); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2688,65 +2458,15 @@ namespace OpenTween } } - private async Task GetListTimelineAsyncInternal(IProgress p, CancellationToken ct, IEnumerable tabs, bool loadMore) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report("List refreshing..."); - - await Task.Run(async () => - { - WebApiException lastException = null; - - foreach (var tab in tabs) - { - try - { - if (tab.ListInfo == null || tab.ListInfo.Id == 0) - continue; - - await this.tw.GetListStatus(read, tab, loadMore, this._initial) - .ConfigureAwait(false); - } - catch (WebApiException ex) - { - lastException = ex; - } - } - - this._statuses.DistributePosts(); - - if (lastException != null) - throw new WebApiException(lastException.Message, lastException); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report("List refreshed"); - - this.RefreshTimeline(); - } - private async Task GetRelatedTweetsAsync(RelatedPostsTabModel tab) { await this.workerSemaphore.WaitAsync(); try { - var progress = new Progress(x => this.StatusLabel.Text = x); + await tab.RefreshAsync(this.tw, this._initial, this.workerProgress); - await this.GetRelatedTweetsAsyncInternal(progress, this.workerCts.Token, tab); + this.RefreshTimeline(); } catch (WebApiException ex) { @@ -2759,55 +2479,6 @@ namespace OpenTween } } - private async Task GetRelatedTweetsAsyncInternal(IProgress p, CancellationToken ct, RelatedPostsTabModel tab) - { - if (ct.IsCancellationRequested) - return; - - if (!CheckAccountValid()) - throw new WebApiException("Auth error. Check your account"); - - bool read; - if (!this._cfgCommon.UnreadManage) - read = true; - else - read = this._initial && this._cfgCommon.Read; - - p.Report("Related refreshing..."); - - await Task.Run(async () => - { - await this.tw.GetRelatedResult(read, tab) - .ConfigureAwait(false); - - this._statuses.DistributePosts(); - }); - - if (ct.IsCancellationRequested) - return; - - p.Report("Related refreshed"); - - this.RefreshTimeline(); - - var tabPage = this.ListTab.TabPages.Cast() - .FirstOrDefault(x => x.Text == tab.TabName); - - if (tabPage != null) - { - // TODO: 非同期更新中にタブが閉じられている場合を厳密に考慮したい - - var listView = (DetailsListView)tabPage.Tag; - var index = tab.IndexOf(tab.TargetPost.RetweetedId ?? tab.TargetPost.StatusId); - - if (index != -1 && index < listView.Items.Count) - { - listView.SelectedIndices.Add(index); - listView.Items[index].Focused = true; - } - } - } - private async Task FavAddAsync(long statusId, TabModel tab) { await this.workerSemaphore.WaitAsync(); @@ -12476,6 +12147,8 @@ namespace OpenTween this.ImageSelector.Enabled = false; this.ImageSelector.FilePickDialog = OpenFileDialog1; + this.workerProgress = new Progress(x => this.StatusLabel.Text = x); + this.ReplaceAppName(); this.InitializeShortcuts(); } @@ -12750,9 +12423,10 @@ namespace OpenTween this._statuses.AddTab(tabRelated); this.AddNewTab(tabRelated, startup: false); + TabPage tabPage; for (int i = 0; i < this.ListTab.TabPages.Count; i++) { - var tabPage = this.ListTab.TabPages[i]; + tabPage = this.ListTab.TabPages[i]; if (tabName == tabPage.Text) { this.ListTab.SelectedIndex = i; @@ -12761,6 +12435,24 @@ namespace OpenTween } await this.GetRelatedTweetsAsync(tabRelated); + + tabPage = this.ListTab.TabPages.Cast() + .FirstOrDefault(x => x.Text == tabRelated.TabName); + + if (tabPage != null) + { + // TODO: 非同期更新中にタブが閉じられている場合を厳密に考慮したい + + var listView = (DetailsListView)tabPage.Tag; + var targetPost = tabRelated.TargetPost; + var index = tabRelated.IndexOf(targetPost.RetweetedId ?? targetPost.StatusId); + + if (index != -1 && index < listView.Items.Count) + { + listView.SelectedIndices.Add(index); + listView.Items[index].Focused = true; + } + } } private void CacheInfoMenuItem_Click(object sender, EventArgs e) -- 2.11.0