Пример #1
0
		public CommentResult GetThreadComments(int threadK, int pageNumber, bool getCommentsOnly)
		{
			Thread thread = new Thread(threadK);
			GroupUsr groupUsr = null;
			if (Usr.Current != null && thread.Group != null)
			{
				groupUsr = thread.Group.GetGroupUsr(Usr.Current);
			}
			ThreadUsr threadUsr = null;
			if (Usr.Current != null && thread.CheckPermissionRead(Usr.Current))
			{
				try
				{
					threadUsr = new ThreadUsr(thread.K, Usr.Current.K);
				}
				catch (BobNotFound)
				{
				}
			}


			CommentResult result = new CommentResult();

			if (pageNumber <= 0)
			{
				pageNumber = (result.firstUnreadPage > 0) ? result.firstUnreadPage : 1;
			}

			result.comments = thread.ChildComments().Page(pageNumber, Vars.CommentsPerPage).ConvertAll(c => CreateCommentStub(c, threadUsr, groupUsr)).ToArray();
			if (result.comments.Length == 0)
			{
				throw new Exception("No comments to retrieve.");
			}

			result.firstUnreadPage = !getCommentsOnly && threadUsr != null && threadUsr.ViewCommentsInUse > 0 ?
					(threadUsr.ViewCommentsInUse / Vars.CommentsPerPage) + 1 : 0;
			result.lastPage = !getCommentsOnly ? thread.LastPage : 0;
			result.currentPage = pageNumber;
			result.initialComment = (!getCommentsOnly && pageNumber > 1) ? CreateCommentStub(thread.ChildComments()[0], threadUsr, groupUsr) : null;
			result.viewComments = !getCommentsOnly && threadUsr != null ? threadUsr.ViewCommentsInUse : 0;
			result.totalComments = !getCommentsOnly ? thread.TotalComments : 0;

			return result;
		}
Пример #2
0
		public CommentStub[] CreateReply(int discussableObjectType, int discussableObjectK, int threadK, string duplicateGuid, string rawCommentHtml, bool formatting, int lastKnownCommentK, string[] inviteUsrOptions)
		{
			Thread thread = new Thread(threadK);
			Comment.MakerReturn makerReturn = Thread.CreateReply(thread, new Guid(duplicateGuid),
				Comment.ParseCommentHtml(rawCommentHtml, formatting, true), GetUsrKsFromOptions(inviteUsrOptions).ToList());

			if (makerReturn.Success)
			{
				IDiscussable discussable = Bob.Get((Model.Entities.ObjectType)discussableObjectType, discussableObjectK) as IDiscussable;
				if (discussable != null)
				{
					discussable.UpdateTotalComments(null);
				}

				return thread.ChildComments().Page(thread.LastPage, Vars.CommentsPerPage).ToList().Where(c => c.K > lastKnownCommentK).ToList()
					.ConvertAll(c => CreateCommentStub(c, thread.GetThreadUsr(Usr.Current), null)).ToArray();
			}
			else if (makerReturn.Duplicate)
				return null;
			else throw new Exception("Error");
		}