Example #1
0
        // コメントのキャッシュまたはオンラインからの取得と更新
        public async Task <List <Chat> > GetComments()
        {
            if (CommentServerInfo == null)
            {
                return(new List <Chat>());
            }

            CommentResponse commentRes = null;

            try
            {
                commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                {
                    return(await this.HohoemaApp.NiconicoContext.Video
                           .GetCommentAsync(
                               (int)HohoemaApp.LoginUserId,
                               CommentServerInfo.ServerUrl,
                               CommentServerInfo.DefaultThreadId,
                               CommentServerInfo.ThreadKeyRequired
                               ));
                });
            }
            catch
            {
            }


            if (commentRes?.Chat.Count == 0)
            {
                try
                {
                    if (CommentServerInfo.CommunityThreadId.HasValue)
                    {
                        commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                        {
                            return(await this.HohoemaApp.NiconicoContext.Video
                                   .GetCommentAsync(
                                       (int)HohoemaApp.LoginUserId,
                                       CommentServerInfo.ServerUrl,
                                       CommentServerInfo.CommunityThreadId.Value,
                                       CommentServerInfo.ThreadKeyRequired
                                       ));
                        });
                    }
                }
                catch { }
            }

            if (commentRes != null)
            {
                CachedCommentResponse = commentRes;
                CommentDb.AddOrUpdate(RawVideoId, commentRes);
            }

            return(commentRes?.Chat);
        }