/** * 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); }
copy.setSendPmNotification(user.isSendPmNotification()); copy.setAvatarLastModificationTime(user.getAvatarLastModificationTime()); copy.setAllForumMarkedAsReadTime(user.getAllForumMarkedAsReadTime()); copy.setUuid(user.getUuid());