示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="low"></param>
        /// <exception cref="ParseException"></exception>
        /// <returns></returns>
        public static ICommentData Parse(LowObject.Comment low)
        {
            var(name, preThumbnailUrl, message) = SplitHtml(low.html);
            string thumbnailUrl;

            if (preThumbnailUrl.StartsWith("https://"))
            {
                thumbnailUrl = preThumbnailUrl;
            }
            else if (preThumbnailUrl.StartsWith("//"))
            {
                thumbnailUrl = "http:" + preThumbnailUrl;
            }
            else
            {
                throw new ParseException(low.html);
            }
            var data = new CommentData
            {
                Id              = low.id,
                UserId          = low.uid,
                Name            = ReplaceHtmlEntities(name),
                Message         = ParseMessage(message),
                ThumbnailUrl    = thumbnailUrl,
                ThumbnailHeight = 50,
                ThumbnailWidth  = 50,
                Date            = DateTime.Parse(low.date),//"Sat, 28 Apr 2018 02:21:28 +0900"
            };

            return(data);
        }
        private TwicasMessageContext CreateMessageContext(LowObject.Comment lowComment, bool isInitialComment, string raw)
        {
            var  commentData = Tools.Parse(lowComment);
            var  userId      = commentData.UserId;
            bool isFirstComment;

            if (_userCommentCountDict.ContainsKey(userId))
            {
                _userCommentCountDict[userId]++;
                isFirstComment = false;
            }
            else
            {
                _userCommentCountDict.AddOrUpdate(userId, 1, (s, n) => n);
                isFirstComment = true;
            }
            var user = GetUser(userId);

            var message = new TwicasComment(raw)
            {
                CommentItems = commentData.Message,
                Id           = commentData.Id.ToString(),
                NameItems    = new List <IMessagePart> {
                    MessagePartFactory.CreateMessageText(commentData.Name)
                },
                PostTime = commentData.Date.ToString("HH:mm:ss"),
                UserId   = commentData.UserId,
                UserIcon = new MessageImage
                {
                    Url    = commentData.ThumbnailUrl,
                    Alt    = null,
                    Height = commentData.ThumbnailHeight,
                    Width  = commentData.ThumbnailWidth,
                },
            };
            var metadata = new MessageMetadata(message, _options, _siteOptions, user, _cp, isFirstComment)
            {
                IsInitialComment = isInitialComment,
                SiteContextGuid  = SiteContextGuid,
            };
            var methods        = new TwicasMessageMethods();
            var messageContext = new TwicasMessageContext(message, metadata, methods);

            return(messageContext);
        }