private async Task FavRemoveAsyncInternal(IProgress<string> p, CancellationToken ct, IReadOnlyList<long> statusIds, TabModel tab)
{
if (ct.IsCancellationRequested)
return;
if (!CheckAccountValid())
throw new WebApiException("Auth error. Check your account");
var successIds = new List<long>();
await Task.Run(async () =>
{
//スレッド処理はしない
var allCount = 0;
var failedCount = 0;
foreach (var statusId in statusIds)
{
allCount++;
var post = tab.Posts[statusId];
p.Report(string.Format(Properties.Resources.GetTimelineWorker_RunWorkerCompletedText17, allCount, statusIds.Count, failedCount));
if (!post.IsFav)
continue;
try
{
await this.twitterApi.FavoritesDestroy(post.RetweetedId ?? post.StatusId)
.IgnoreResponse()
.ConfigureAwait(false);
}
catch (WebApiException)
{
failedCount++;
continue;
}
successIds.Add(statusId);
post.IsFav = false; // リスト再描画必要
if (this._statuses.ContainsKey(statusId))
{
this._statuses[statusId].IsFav = false;
}
// 検索,リスト,UserTimeline,Relatedの各タブに反映
foreach (var tb in this._statuses.GetTabsInnerStorageType())
{
if (tb.Contains(statusId))
tb.Posts[statusId].IsFav = false;
}
}
});
if (ct.IsCancellationRequested)
return;
var favTab = this._statuses.GetTabByType(MyCommon.TabUsageType.Favorites);
foreach (var statusId in successIds)
{
// ツイートが削除された訳ではないので IsDeleted はセットしない
favTab.EnqueueRemovePost(statusId, setIsDeleted: false);
}
this.RefreshTimeline();
if (this._curList != null && this._curTab != null && this._curTab.Text == tab.TabName)
{
if (tab.TabType == MyCommon.TabUsageType.Favorites)
{
// 色変えは不要
}
else
{
using (ControlTransaction.Update(this._curList))
{
foreach (var statusId in successIds)
{
var idx = tab.IndexOf(statusId);
if (idx == -1)
continue;
var post = tab.Posts[statusId];
this.ChangeCacheStyleRead(post.IsRead, idx);
}
}
if (successIds.Contains(this._curPost.StatusId))
await this.DispSelectedPost(true); // 選択アイテム再表示
}
}
}