public boolean isCategoryModerated(List<Forum> forumsOfACategory) { for (Forum forum : forumsOfACategory) { if (this.roleExists(SecurityConstants.MODERATE_FORUM, forum.getId())) { return true; } } return false; }
/** * Check if some forum has unread messages. * * @param forum The forum to search for unread messages * @param tracking Tracking of the topics read by the user * @param lastVisit The last visit time of the current user */ public static void checkUnreadPosts(Forum forum, Map tracking, long lastVisit) { LOG.trace("checkUnreadPosts"); LastPostInfo lpi = forum.getLastPostInfo(); if (lpi == null) { return; } Integer topicId = new Integer(lpi.getTopicId()); if (tracking != null && tracking.containsKey(topicId)) { long readTime = ((Long) tracking.get(topicId)).longValue(); forum.setUnread(readTime > 0 && lpi.getPostTimeMillis() > readTime); } else { forum.setUnread(lpi.getPostTimeMillis() > lastVisit); } }
/** * Create a new topic. Saves a topic, as well the related first post. Date, user and subject of * the associated post are forced to be the same value used by the topic. * * @param topic the topic to save * @param pollOptions * @param attachments */ @Override public void addTopic(Topic topic, List<PollOption> pollOptions, List<AttachedFile> attachments) { this.performAddValidations(topic); if (topic.getDate() == null) { topic.setDate(new Date()); } Post post = topic.getFirstPost(); topic.setFirstPost(null); this.pollService.associatePoll(topic, pollOptions); topic.setHasAttachment(attachments.size() > 0); this.topicRepository.add(topic); post.setForum(topic.getForum()); post.setTopic(topic); post.setDate(topic.getDate()); post.setUser(topic.getUser()); post.setSubject(topic.getSubject()); this.attachmentService.insertAttachments(attachments, post); this.postRepository.add(post); topic.setFirstPost(post); topic.setLastPost(post); if (!topic.isWaitingModeration()) { Forum forum = this.forumRepository.get(topic.getForum().getId()); forum.setLastPost(post); int userTotalPosts = this.userRepository.getTotalPosts(post.getUser()); topic.getUser().setTotalPosts(userTotalPosts); } }