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); } } } }
private static void updateTargetReplies(OpenComment c, int replies) { Type targetType = Entity.GetType(c.TargetDataType); ICommentTarget target = ndb.findById(targetType, c.TargetDataId) as ICommentTarget; if (target == null) { return; } target.Replies = replies; db.update(target); if (c.AppId <= 0) { return; } Type appType = target.GetAppType(); if (appType == null) { return; } ICommentApp app = ndb.findById(appType, c.AppId) as ICommentApp; if (app == null) { return; } int appCount = OpenComment.count("AppId=" + c.AppId + " and TargetDataType='" + c.TargetDataType + "'"); app.CommentCount = appCount; db.update(app); }
private void sendNotifications(OpenComment c) { List <int> sentIds = new List <int>(); if (c.ParentId > 0) { OpenComment p = OpenComment.findById(c.ParentId); if (p != null && p.Member != null) { sendNotificationsTo(sentIds, p, c); } } if (c.AtId > 0) { OpenComment at = OpenComment.findById(c.AtId); if (at != null && at.Member != null) { sendNotificationsTo(sentIds, at, c); } } if (c.TargetUserId > 0) { sendNotificationToRoot(sentIds, c); } }
//---------------------------------------------------------------------------------------------- private List <OpenComment> addSubList(List <OpenComment> list, Boolean isDesc) { String subIds = ""; foreach (OpenComment c in list) { if (isDesc) { subIds = strUtil.Join(subIds, c.LastReplyIds, ","); } else { subIds = strUtil.Join(subIds, c.FirstReplyIds, ","); } } subIds = subIds.Trim().TrimStart(',').TrimEnd(','); if (strUtil.IsNullOrEmpty(subIds)) { return(list); } List <OpenComment> totalSubList = OpenComment.find("Id in (" + subIds + ")").list(); foreach (OpenComment c in list) { c.SetReplyList(getSubListFromTotal(c, totalSubList)); } return(list); }
private static void updateParentReplies(OpenComment c) { if (c.ParentId == 0) { return; } OpenComment p = OpenComment.findById(c.ParentId); if (p == null) { c.ParentId = 0; c.update(); return; } //------------------------------------------------ p.Replies = OpenComment.count("ParentId=" + p.Id); //------------------------------------------------- List <OpenComment> subFirst = OpenComment.find("ParentId=" + p.Id + " order by Id asc").list(OpenComment.subCacheSize); List <OpenComment> subLast = OpenComment.find("ParentId=" + p.Id + " order by Id desc").list(OpenComment.subCacheSize); p.FirstReplyIds = strUtil.GetIds(subFirst); p.LastReplyIds = strUtil.GetIds(subLast); p.update(); }
public DataPage <OpenComment> GetByUrlAsc(String url) { DataPage <OpenComment> datas = OpenComment.findPage("TargetUrl='" + strUtil.SqlClean(url, 50) + "' and ParentId=0 order by Id asc"); datas.Results = addSubList(datas.Results, false); return(datas); }
public DataPage <OpenComment> GetByDataAsc(String dataType, int dataId) { DataPage <OpenComment> datas = OpenComment.findPage("TargetDataType='" + strUtil.SqlClean(dataType, 50) + "' and TargetDataId=" + dataId + " and ParentId=0 order by Id asc"); datas.Results = addSubList(datas.Results, false); return(datas); }
private void deleteSubComments(OpenComment c) { if (c.Replies == 0) { return; } db.deleteBatch <OpenComment>("ParentId=" + c.Id); }
public virtual DataPage <OpenComment> GetByUrlDesc(String url) { DataPage <OpenComment> datas = OpenComment.findPage("TargetUrl='" + strUtil.SqlClean(url, 50) + "' and ParentId=0"); datas.Results = addSubList(datas.Results, true); return(datas); }
public void Delete(OpenComment c) { if (c == null) { return; } db.delete(c); deleteSubComments(c); updateRootTargetReplies(c); }
public virtual DataPage <OpenComment> GetByMicroblogOwnerId(int ownerId) { int pageSize = 20; DataPage <OpenComment> datas = OpenComment.findPage("OwnerId=" + ownerId + " and FeedId>0 and ParentId=0", pageSize); datas.Results = addSubList(datas.Results, true); return(datas); }
public virtual DataPage <OpenComment> GetByDataAndOwnerId(string dataType, int ownerId) { int pageSize = 20; DataPage <OpenComment> datas = OpenComment.findPage("TargetDataType='" + strUtil.SqlClean(dataType, 50) + "' and OwnerId=" + ownerId + " and ParentId=0", pageSize); datas.Results = addSubList(datas.Results, true); return(datas); }
private static void insertCommentCount(OpenComment c, int replies) { OpenCommentCount objCount = new OpenCommentCount(); objCount.TargetUrl = c.TargetUrl; objCount.DataType = c.TargetDataType; objCount.DataId = c.TargetDataId; objCount.Replies = replies; objCount.insert(); }
private static void updateTargetReplies(OpenComment c, int replies) { Type targetType = Entity.GetType(c.TargetDataType); ICommentTarget target = ndb.findById(targetType, c.TargetDataId) as ICommentTarget; if (target == null) { return; } target.Replies = replies; db.update(target); }
public DataPage <OpenComment> GetByDataDesc(String dataType, int dataId, int pageSize) { if (pageSize <= 0 || pageSize > 500) { pageSize = 20; } DataPage <OpenComment> datas = OpenComment.findPage("TargetDataType='" + strUtil.SqlClean(dataType, 50) + "' and TargetDataId=" + dataId + " and ParentId=0", pageSize); datas.Results = addSubList(datas.Results, true); return(datas); }
private static Microblog getFeed(OpenComment c) { if (c.FeedId > 0) { return(Microblog.findById(c.FeedId)); } else { return(Microblog.find("DataId=:id and DataType=:dtype") .set("id", c.TargetDataId) .set("dtype", c.TargetDataType) .first()); } }
// 只是导入,并不发送通知 public Result Import(OpenComment c) { Result result = c.insert(); if (result.IsValid) { updateParentReplies(c); updateRootTargetReplies(c); return(result); } else { return(result); } }
public virtual Result CreateNoNotification(OpenComment c) { Result result = c.insert(); if (result.IsValid) { updateParentReplies(c); updateRootTargetReplies(c); return(result); } else { return(result); } }
public List <OpenComment> GetMore(int parentId, int startId, int replyPageSize, string sort) { String condition = ""; if (sort == "asc") { condition = "ParentId=" + parentId + " and Id>" + startId + " order by Id asc"; } else { condition = "ParentId=" + parentId + " and Id<" + startId + " order by Id desc"; } return(OpenComment.find(condition).list(replyPageSize)); }
public List <OpenComment> GetByApp(Type type, int appId, int listCount) { if (listCount <= 0) { listCount = 7; } String condition = "TargetDataType='" + type + "'"; if (appId > 0) { condition = condition + " and AppId=" + appId; } return(OpenComment.find(condition).list(listCount)); }
private void updateRootTargetReplies(OpenComment c) { int replies; OpenCommentCount objCount; if (c.TargetDataId > 0 && strUtil.HasText(c.TargetDataType)) { replies = OpenComment.find("TargetDataType=:dtype and TargetDataId=" + c.TargetDataId) .set("dtype", c.TargetDataType) .count(); objCount = OpenCommentCount.find("DataType=:dtype and DataId=" + c.TargetDataId) .set("dtype", c.TargetDataType) .first(); } else { if (c.TargetUrl == null) { replies = 0; objCount = null; } else { replies = OpenComment.find("TargetUrl=:url") .set("url", c.TargetUrl) .count(); objCount = OpenCommentCount.find("TargetUrl=:url") .set("url", c.TargetUrl) .first(); } } if (objCount == null) { insertCommentCount(c, replies); } else { updateCommentCount(objCount, replies); } updateTargetReplies(c, replies); }
private void sendNotificationsTo(List <int> sentIds, OpenComment comment, OpenComment c) { int receiverId = comment.Member.Id; if (c.Member != null && c.Member.Id == receiverId) { return; // 不用给自己发通知 } if (sentIds.Contains(receiverId)) { return; // 已经发过,不用重发 } String msg = c.Author + " 回复了你在 <a href=\"" + c.TargetUrl + "\">" + comment.TargetTitle + "</a> 的评论"; nfService.send(receiverId, typeof(User).FullName, msg, NotificationType.Comment); sentIds.Add(receiverId); }
public virtual IEntity GetTarget(OpenComment c) { if (strUtil.IsNullOrEmpty(c.TargetDataType)) { return(null); } if (c.TargetDataId <= 0) { return(null); } Type targetType = Entity.GetType(c.TargetDataType); if (targetType == null) { return(null); } return(ndb.findById(targetType, c.TargetDataId)); }
private List <OpenComment> getSubListFromTotal(OpenComment parent, List <OpenComment> totalSubList) { List <OpenComment> results = new List <OpenComment>(); int iCount = 0; foreach (OpenComment c in totalSubList) { if (iCount >= OpenComment.subCacheSize) { break; } if (c.ParentId == parent.Id) { results.Add(c); iCount = iCount + 1; } } return(results); }
public virtual IEntity GetTarget(OpenComment c) { Type targetType = Entity.GetType(c.TargetDataType); return(ndb.findById(targetType, c.TargetDataId)); }
public DataPage <OpenComment> GetPageAll(String condition) { return(OpenComment.findPage(condition)); }