コード例 #1
0
 public static Comment CreateComment(CommentAddVM vm, string parent_id, ModelType parent_type, string avatar = null)
 {
     return(new Comment {
         Creator = new BaseCreator {
             UserName = vm.UName,
             UUID = vm.UID,
             AvatarUrl = avatar
         },
         Mentioned = (vm.MContent == null) ? null :new BaseCreator {
             UUID = vm.MContent.UUID,
             UserName = vm.MContent.UserName
         },
         CommentContent = vm.Content,
         ParentID = parent_id,
         ParentType = parent_type
     });
 }
コード例 #2
0
        public async Task <JsonResult> AddCommentAsync(string id, [FromBody] CommentAddVM vm)
        {
            if (vm == null)
            {
                return(this.JsonFormat(false, JsonStatus.BodyFormIsNull));
            }

            var creator = this.GetUser();

            if (creator.UUID == null)
            {
                return(this.JsonFormat(false, JsonStatus.UserNotLogin));
            }
            if (creator.UUID != vm.UID)
            {
                return(this.JsonFormat(false, JsonStatus.UserNotMatched));
            }
            if (vm.UName == null)
            {
                vm.UName = creator.UserName;
            }

            var model = default(Comment);

            var(status, error) = default((JsonStatus, Model.Utils.Error));
            if (vm.IsReply)
            {
                (status, error) = await this.status.Comments.AddReplyForCommentAsync(
                    vm.MContent.CommentID, model = ModelCreator.CreateComment(vm, vm.MContent.CommentID, ModelType.Comment, creator.AvatarUrl));
            }
            else
            {
                (status, error) = await this.status.AddCommentAsync(
                    id, model = ModelCreator.CreateComment(vm, id, ModelType.Status, creator.AvatarUrl));
            }
            if (status != JsonStatus.Succeed)
            {
                return(this.JsonFormat(false, status, error.Read()));
            }

            // send message
            var(entry, status02, error02) = await this.status.GetStatusDetailsAsync(id);

            var target = default(BaseCreator);

            if (vm.IsReply)
            {
                target = new BaseCreator {
                    UUID = vm?.MContent?.UUID, UserName = vm?.MContent?.UserName
                }
            }
            ;
            else
            {
                target = new BaseCreator {
                    UUID = entry.Creator.UUID, UserName = entry.Creator.UserName
                }
            };
            if (creator.UUID != target.UUID)
            {
                var source = new MessageSource {
                    Type           = ModelType.Comment,
                    HostID         = id,
                    TargetID       = model.ID,
                    HostType       = ModelType.Status,
                    HostAbstract   = status02 == JsonStatus.Succeed ? entry.Content : null,
                    Abstract       = model.CommentContent,
                    ParentID       = vm?.MContent?.CommentID,
                    ParentAbstract = vm?.MContent?.Content
                };
                if (vm.IsReply)
                {
                    await this.message.CreateMessageAsync(creator, target, MessageType.Reply, null, source);
                }
                else
                {
                    await this.message.CreateMessageAsync(creator, target, MessageType.Comment, null, source);
                }
            }

            return(this.JsonFormat(true, content: model));
        }