private async Task doStatusDelete()
{
if (this._curTab == null || this._curList == null)
return;
if (this._curList.SelectedIndices.Count == 0)
return;
var posts = this._curList.SelectedIndices.Cast<int>()
.Select(x => this.GetCurTabPost(x))
.ToArray();
// 選択されたツイートの中に削除可能なものが一つでもあるか
if (!posts.Any(x => x.CanDeleteBy(this.tw.UserId)))
return;
var ret = MessageBox.Show(this,
string.Format(Properties.Resources.DeleteStripMenuItem_ClickText1, Environment.NewLine),
Properties.Resources.DeleteStripMenuItem_ClickText2,
MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (ret != DialogResult.OK)
return;
var focusedIndex = this._curList.FocusedItem?.Index ?? this._curList.TopItem?.Index ?? 0;
using (ControlTransaction.Cursor(this, Cursors.WaitCursor))
{
Exception lastException = null;
foreach (var post in posts)
{
if (!post.CanDeleteBy(this.tw.UserId))
continue;
try
{
if (post.IsDm)
{
await this.twitterApi.DirectMessagesDestroy(post.StatusId)
.IgnoreResponse();
}
else
{
if (post.RetweetedByUserId == this.tw.UserId)
{
// 自分が RT したツイート (自分が RT した自分のツイートも含む)
// => RT を取り消し
await this.twitterApi.StatusesDestroy(post.StatusId)
.IgnoreResponse();
}
else
{
if (post.UserId == this.tw.UserId)
{
if (post.RetweetedId != null)
// 他人に RT された自分のツイート
// => RT 元の自分のツイートを削除
await this.twitterApi.StatusesDestroy(post.RetweetedId.Value)
.IgnoreResponse();
else
// 自分のツイート
// => ツイートを削除
await this.twitterApi.StatusesDestroy(post.StatusId)
.IgnoreResponse();
}
}
}
}
catch (WebApiException ex)
{
lastException = ex;
continue;
}
this._statuses.RemovePostFromAllTabs(post.StatusId, setIsDeleted: true);
}
if (lastException == null)
this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText4; // 成功
else
this.StatusLabel.Text = Properties.Resources.DeleteStripMenuItem_ClickText3; // 失敗
this.PurgeListViewItemCache();
this._curPost = null;
this._curItemIndex = -1;
foreach (var tabPage in this.ListTab.TabPages.Cast<TabPage>())
{
var listView = (DetailsListView)tabPage.Tag;
var tab = this._statuses.Tabs[tabPage.Text];
using (ControlTransaction.Update(listView))
{
listView.VirtualListSize = tab.AllCount;
if (tabPage == this._curTab)
{
listView.SelectedIndices.Clear();
if (tab.AllCount != 0)
{
int selectedIndex;
if (tab.AllCount - 1 > focusedIndex && focusedIndex > -1)
selectedIndex = focusedIndex;
else
selectedIndex = tab.AllCount - 1;
listView.SelectedIndices.Add(selectedIndex);
listView.EnsureVisible(selectedIndex);
listView.FocusedItem = listView.Items[selectedIndex];
}
}
}
if (this._cfgCommon.TabIconDisp && tab.UnreadCount == 0)
{
if (tabPage.ImageIndex == 0)
tabPage.ImageIndex = -1; // タブアイコン
}
}
if (!this._cfgCommon.TabIconDisp)
this.ListTab.Refresh();
}
}