/** * Remove the post from the topic. * * @param postToRemove post to remove */ public void removePost(Post postToRemove) { posts.remove(postToRemove); Topic topic = postToRemove.getTopic(); if (postToRemove.getCreationDate().withMillisOfSecond(0) .equals(topic.getModificationDate().withMillisOfSecond(0))) { topic.recalculateModificationDate(); } }
/** * Extract topics that don't have modifications after marking all forum as read * or after marking their branch as read. * * @param currentUser the current user of application * @param sourceTopics the list of topics that must be processed * @return topics that don't have modification after marking all forum as read */ private List<Topic> extractNotModifiedTopicsSinceForumMarkedAsRead( JCUser currentUser, List<Topic> sourceTopics) { DateTime forumMarkAsReadDate = currentUser.getAllForumMarkedAsReadTime(); List<Topic> topics = new ArrayList<>(); if (!sourceTopics.isEmpty()) { Branch branch = sourceTopics.get(0).getBranch(); BranchReadedMarker markBranch = branchReadedMarkerDao.getMarkerFor(currentUser, branch); DateTime markTime = getLastMarkDateTime(markBranch, forumMarkAsReadDate); for (Topic topic : sourceTopics) { if (!topic.getBranch().equals(branch)) { branch = topic.getBranch(); markBranch = branchReadedMarkerDao.getMarkerFor(currentUser, branch); markTime = getLastMarkDateTime(markBranch, forumMarkAsReadDate); } if(markTime != null && topic.getModificationDate().isBefore(markTime)) { topics.add(topic); } } } return topics; }
/** * Stores last read post info into database for the particular topic and user. * * @param user user to save last read post data for * @param topic topic to store info for * @param lastPost last post in the topic (or in the last read page of the topic) */ private void saveLastReadPost(JCUser user, Topic topic, Post lastPost) { DateTime lastTimeForumWasMarkedRead = user.getAllForumMarkedAsReadTime(); DateTime topicModifiedDate = topic.getModificationDate(); if (lastTimeForumWasMarkedRead != null && topicModifiedDate.isBefore(lastTimeForumWasMarkedRead)) { return; } LastReadPost lastReadPost = lastReadPostDao.getLastReadPost(user, topic); if (lastReadPost == null) { lastReadPost = new LastReadPost(user, topic, lastPost.getCreationDate()); } else { if (lastPost.getCreationDate().isAfter(lastReadPost.getPostCreationDate())) { lastReadPost.setPostCreationDate(lastPost.getCreationDate()); } else { return; } } lastReadPostDao.saveOrUpdate(lastReadPost); }
/** * Create news item * * @param topic news topic * @param url building URL * @return item for news feed */ private Item createFeedItem(Topic topic, String url) { Item item = new Item(); Description description = new Description(); description.setType("text"); String postContent = topic.getLastPost().getPostContent(); postContent = RssUtils.skipInValidXMLChars(postContent); description.setValue(postContent); Content content = new Content(); item.setContent(content); item.setTitle(topic.getTitle()); item.setAuthor(topic.getLastPost().getUserCreated().getUsername()); item.setLink(url + "/posts/" + topic.getLastPost().getId()); item.setComments(topic.getTopicStarter().getSignature()); item.setDescription(description); item.setPubDate(topic.getModificationDate().toDate()); return item; }