private async Task GoInReplyToPostTree()
{
if (_curPost == null) return;
TabModel curTabClass = _statuses.Tabs[_curTab.Text];
if (curTabClass.TabType == MyCommon.TabUsageType.PublicSearch && _curPost.InReplyToStatusId == null && _curPost.TextFromApi.Contains("@"))
{
try
{
var post = await tw.GetStatusApi(false, _curPost.StatusId);
_curPost.InReplyToStatusId = post.InReplyToStatusId;
_curPost.InReplyToUser = post.InReplyToUser;
_curPost.IsReply = post.IsReply;
this.PurgeListViewItemCache();
_curList.RedrawItems(_curItemIndex, _curItemIndex, false);
}
catch (WebApiException ex)
{
this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
}
}
if (!(this.ExistCurrentPost && _curPost.InReplyToUser != null && _curPost.InReplyToStatusId != null)) return;
if (replyChains == null || (replyChains.Count > 0 && replyChains.Peek().InReplyToId != _curPost.StatusId))
{
replyChains = new Stack<ReplyChain>();
}
replyChains.Push(new ReplyChain(_curPost.StatusId, _curPost.InReplyToStatusId.Value, _curTab));
int inReplyToIndex;
string inReplyToTabName;
long inReplyToId = _curPost.InReplyToStatusId.Value;
string inReplyToUser = _curPost.InReplyToUser;
//Dictionary<long, PostClass> curTabPosts = curTabClass.Posts;
var inReplyToPosts = from tab in _statuses.Tabs.Values
orderby tab != curTabClass
from post in tab.Posts.Values
where post.StatusId == inReplyToId
let index = tab.IndexOf(post.StatusId)
where index != -1
select new {Tab = tab, Index = index};
var inReplyPost = inReplyToPosts.FirstOrDefault();
if (inReplyPost == null)
{
try
{
await Task.Run(async () =>
{
var post = await tw.GetStatusApi(false, _curPost.InReplyToStatusId.Value)
.ConfigureAwait(false);
post.IsRead = true;
_statuses.AddPost(post);
_statuses.DistributePosts();
});
}
catch (WebApiException ex)
{
this.StatusLabel.Text = $"Err:{ex.Message}(GetStatus)";
await this.OpenUriInBrowserAsync(MyCommon.GetStatusUrl(inReplyToUser, inReplyToId));
return;
}
this.RefreshTimeline();
inReplyPost = inReplyToPosts.FirstOrDefault();
if (inReplyPost == null)
{
await this.OpenUriInBrowserAsync(MyCommon.GetStatusUrl(inReplyToUser, inReplyToId));
return;
}
}
inReplyToTabName = inReplyPost.Tab.TabName;
inReplyToIndex = inReplyPost.Index;
TabPage tabPage = this.ListTab.TabPages.Cast<TabPage>().First((tp) => { return tp.Text == inReplyToTabName; });
DetailsListView listView = (DetailsListView)tabPage.Tag;
if (_curTab != tabPage)
{
this.ListTab.SelectTab(tabPage);
}
this.SelectListItem(listView, inReplyToIndex);
listView.EnsureVisible(inReplyToIndex);
}