Beispiel #1
0
        private void updateTargetReplies(OpenComment c, int replies)
        {
            ICommentTarget target = GetTarget(c) as ICommentTarget;

            if (target != null)
            {
                target.Replies = replies;
                db.update(target);
            }

            // feed replies
            Microblog mblog = getFeed(c);

            if (mblog != null)
            {
                mblog.Replies = replies;
                mblog.update();
            }

            if (c.AppId > 0 && target != null)
            {
                Type appType = target.GetAppType();
                if (appType != null)
                {
                    ICommentApp app = ndb.findById(appType, c.AppId) as ICommentApp;
                    if (app != null)
                    {
                        int appCount = OpenComment.count("AppId=" + c.AppId + " and TargetDataType='" + c.TargetDataType + "'");
                        app.CommentCount = appCount;
                        db.update(app);
                    }
                }
            }
        }
Beispiel #2
0
        private void updateComment(object[] args, object target)
        {
            ForumPost  post   = args[0] as ForumPost;
            User       editor = args[1] as User;
            ForumTopic topic  = ForumTopic.findById(post.TopicId);

            // 更新评论
            CommentSync objSync = CommentSync.find("PostId=" + post.Id).first();

            if (objSync == null)
            {
                return;
            }
            OpenComment comment = objSync.Comment;

            comment.Content = strUtil.ParseHtml(post.Content);
            comment.update();

            // 更新此ForumPost对应的Microblog
            Microblog mblog = Microblog.find("DataId=:id and DataType=:dtype")
                              .set("id", post.Id)
                              .set("dtype", typeof(ForumPost).FullName)
                              .first();

            if (mblog != null)
            {
                mblog.Content = getPostContent(post);
                mblog.update();
            }
        }
Beispiel #3
0
        public virtual void SaveLike(long mid)
        {
            if (ctx.viewer.IsLogin == false)
            {
                echoJsonMsg("请先登录", false, "");
                return;
            }

            if (mid <= 0)
            {
                echoText("mid=" + mid);
                return;
            }

            Microblog microblog = Microblog.findById(mid);

            if (microblog == null)
            {
                echoText("microblog is null. mid=" + mid);
                return;
            }

            // 检查是否已经like
            MicroblogLike flike = MicroblogLike.find("UserId=" + ctx.viewer.Id + " and MicroblogId=" + mid).first();

            if (flike != null)
            {
                echoText("您已经赞过");
                return;
            }

            microblog.Likes = microblog.Likes + 1;
            microblog.update();

            MicroblogLike microblogLike = new MicroblogLike();

            microblogLike.User      = ctx.viewer.obj as User;
            microblogLike.Microblog = microblog;
            microblogLike.Ip        = ctx.Ip;
            microblogLike.insert();

            // target likes
            if (strUtil.HasText(microblog.DataType))
            {
                Type targetType = Entity.GetType(microblog.DataType);
                if (targetType != null)
                {
                    ILike target = ndb.findById(targetType, microblog.DataId) as ILike;
                    if (target != null)
                    {
                        target.Likes = microblog.Likes;
                        db.update(target);
                    }
                }
            }

            echoAjaxOk();
        }
        public virtual void Insert(Microblog blog, int i)
        {
            String rcontent = blog.Content;

            MicroblogBinder smbinder = new MicroblogBinder();

            MicroblogParser mp = new MicroblogParser(blog.Content, smbinder);

            mp.Process();

            blog.Content = mp.ToString();

            blog.Content = processEmotions(blog.Content);

            Result result = blog.insert();

            if (i == 0)
            {
                // 保存tag
                TagService.SaveDataTag(blog, mp.GetTagList());

                // 发通知
                addNotification(smbinder.GetValidUsers(), blog);
            }

            // 转发需要刷新原帖的转发量
            if (blog.ParentId > 0)
            {
                Microblog parent = GetById(blog.ParentId);
                if (parent != null)
                {
                    parent.Reposts = Microblog.count("ParentId=" + parent.Id);
                    parent.update("Reposts");
                }
            }

            if (result.IsValid)
            {
                addFeedInfo(blog);
            }
        }