Skip to content

Commit

Permalink
убрал число комментариев у закрытых топиков
Browse files Browse the repository at this point in the history
fixes #1035
  • Loading branch information
maxcom committed Aug 11, 2023
1 parent b6c8f18 commit f632b94
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
7 changes: 3 additions & 4 deletions src/main/java/ru/org/linux/tag/TagPageController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.springframework.web.servlet.ModelAndView
import org.springframework.web.servlet.view.RedirectView
import ru.org.linux.auth.AuthUtil
import ru.org.linux.gallery.ImageService
import ru.org.linux.group.GroupDao
import ru.org.linux.section.{Section, SectionService}
import ru.org.linux.site.Template
import ru.org.linux.tag.TagPageController.isRecent
Expand Down Expand Up @@ -56,7 +55,7 @@ object TagPageController {
@Controller
@RequestMapping(value = Array("/tag/{tag}"), params = Array("!section"))
class TagPageController(tagService: TagService, prepareService: TopicPrepareService, topicListService: TopicListService,
sectionService: SectionService, groupDao: GroupDao, userTagService: UserTagService, imageService: ImageService,
sectionService: SectionService, userTagService: UserTagService, imageService: ImageService,
actorSystem: ActorSystem) extends StrictLogging {

private implicit val akka: ActorSystem = actorSystem
Expand Down Expand Up @@ -178,7 +177,7 @@ class TagPageController(tagService: TagService, prepareService: TopicPrepareServ
(Map(
"fullNews" -> fullNews,
"addNews" -> AddTopicController.getAddUrl(newsSection, tag),
"briefNews" -> TopicListTools.split(briefNewsByDate.map(p => p._1 -> BriefTopicRef.fromTopicNoGroup(p._2)))
"briefNews" -> TopicListTools.split(briefNewsByDate.map(p => p._1 -> prepareService.prepareBrief(p._2, groupInTitle = false)))
) ++ more, newestDate)
}

Expand Down Expand Up @@ -226,7 +225,7 @@ class TagPageController(tagService: TagService, prepareService: TopicPrepareServ
(Map(
forumSection.getUrlName+"Add" -> AddTopicController.getAddUrl(forumSection, tag),
forumSection.getUrlName -> TopicListTools.split(
topicByDate.map(p => p._1 -> BriefTopicRef.fromTopic(p._2, groupDao.getGroup(p._2.groupId).getTitle)))
topicByDate.map(p => p._1 -> prepareService.prepareBrief(p._2, groupInTitle = true)))
) ++ more, newestDate)
}
}
3 changes: 1 addition & 2 deletions src/main/scala/ru/org/linux/spring/MainPageController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import ru.org.linux.topic.*
import ru.org.linux.user.MemoriesDao

import javax.servlet.http.HttpServletResponse
import scala.jdk.CollectionConverters.*

@Controller
class MainPageController(
Expand Down Expand Up @@ -68,7 +67,7 @@ class MainPageController(

mv.getModel.put(
"briefNews",
TopicListTools.split(briefNewsByDate.map(p => p._1 -> BriefTopicRef.fromTopicNoGroup(p._2))))
TopicListTools.split(briefNewsByDate.map(p => p._1 -> prepareService.prepareBrief(p._2, groupInTitle = false))))

if (tmpl.isSessionAuthorized) {
mv.getModel.put("hasDrafts", Boolean.box(topicDao.hasDrafts(AuthUtil.getCurrentUser)))
Expand Down
22 changes: 5 additions & 17 deletions src/main/scala/ru/org/linux/topic/BriefTopicRef.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 1998-2022 Linux.org.ru
* Copyright 1998-2023 Linux.org.ru
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -15,22 +15,10 @@

package ru.org.linux.topic

import ru.org.linux.util.StringUtil

import scala.beans.BeanProperty

case class BriefTopicRef(
@BeanProperty url:String,
@BeanProperty title:String,
@BeanProperty commentCount:Int,
@BeanProperty group:Option[String]
)

object BriefTopicRef {
def fromTopicNoGroup(input:Topic) =
BriefTopicRef(input.getLink, StringUtil.processTitle(input.title), input.commentCount, None)

def fromTopic(input:Topic, group:String) =
BriefTopicRef(input.getLink, StringUtil.processTitle(input.title), input.commentCount, Some(group))

}
@BeanProperty url: String,
@BeanProperty title: String,
@BeanProperty commentCount: Int,
@BeanProperty group: Option[String])
18 changes: 18 additions & 0 deletions src/main/scala/ru/org/linux/topic/TopicPrepareService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ru.org.linux.spring.SiteConfig
import ru.org.linux.spring.dao.{DeleteInfoDao, MessageText, MsgbaseDao, UserAgentDao}
import ru.org.linux.tag.TagRef
import ru.org.linux.user.*
import ru.org.linux.util.StringUtil

import javax.annotation.Nullable
import scala.jdk.CollectionConverters.*
Expand Down Expand Up @@ -215,4 +216,21 @@ class TopicPrepareService(sectionService: SectionService, groupDao: GroupDao, de
topicPermissionService.isCommentsAllowed(topic.group, topic.message, currentUser, false), deletable,
undeletable, groupPermissionService.canCommit(currentUser, topic.message), userpic.orNull, showComments)
}

def prepareBrief(topic: Topic, groupInTitle: Boolean): BriefTopicRef = {
val group = groupDao.getGroup(topic.groupId)

val postscore = topicPermissionService.getPostscore(group, topic)
val showComments = postscore != TopicPermissionService.POSTSCORE_HIDE_COMMENTS

val commentCount = if (showComments) topic.commentCount else 0

val groupTitle = if (groupInTitle) {
Some(group.getTitle)
} else {
None
}

BriefTopicRef(topic.getLink, StringUtil.processTitle(topic.title), commentCount, groupTitle)
}
}

0 comments on commit f632b94

Please sign in to comment.