Example #1
0
        public async Task <NMSG_Response> GetCommentsFromNMSG()
        {
            if (LastAccessDmcWatchResponse == null)
            {
                return(null);
            }

            var res = await Context.Video.GetNMSGCommentAsync(LastAccessDmcWatchResponse);

            if (res != null && DefaultThreadSubmitInfo == null)
            {
                DefaultThreadSubmitInfo              = new CommentSubmitInfo();
                DefaultThreadSubmitInfo.Ticket       = res.Threads.First(x => x.Thread == CommentServerInfo.DefaultThreadId.ToString()).Ticket;
                DefaultThreadSubmitInfo.CommentCount = LastAccessDmcWatchResponse.Thread.CommentCount + 1;
                DefaultThreadSubmitInfo.ThreadType   = res.ThreadType;
                if (CommentServerInfo.CommunityThreadId.HasValue)
                {
                    var communityThreadId = CommentServerInfo.CommunityThreadId.Value.ToString();
                    var communityThread   = res.Threads.FirstOrDefault(x => x.Thread == communityThreadId);
                    if (communityThread != null)
                    {
                        CommunityThreadSubmitInfo = new CommentSubmitInfo()
                        {
                            Ticket       = communityThread.Ticket,
                            CommentCount = communityThread.LastRes,
                            ThreadType   = res.ThreadType
                        };
                    }
                }
            }

            return(res);
        }
Example #2
0
        private async Task <List <Chat> > GetComments()
        {
            if (CommentServerInfo == null)
            {
                return(new List <Chat>());
            }

            CommentResponse commentRes = null;

            try
            {
                commentRes = await ConnectionRetryUtil.TaskWithRetry(async() =>
                {
                    return(await ContextActionAsync(async context =>
                    {
                        return await context.Video
                        .GetCommentAsync(
                            (int)CommentServerInfo.ViewerUserId,
                            CommentServerInfo.ServerUrl,
                            CommentServerInfo.DefaultThreadId,
                            CommentServerInfo.ThreadKeyRequired
                            );
                    }));
                });
            }
            catch
            {
            }


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

            if (commentRes != null)
            {
                CachedCommentResponse = commentRes;
                Database.VideoCommentDb.AddOrUpdate(RawVideoId, commentRes.Chat);
            }

            if (commentRes != null && DefaultThreadSubmitInfo == null)
            {
                DefaultThreadSubmitInfo        = new CommentSubmitInfo();
                DefaultThreadSubmitInfo.Ticket = commentRes.Thread.Ticket;
                if (int.TryParse(commentRes.Thread.CommentCount, out int count))
                {
                    DefaultThreadSubmitInfo.CommentCount = count + 1;
                }
            }

            return(commentRes?.Chat);
        }