Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort username for issue comments #1964

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/main/scala/gitbucket/core/controller/IndexController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ trait IndexControllerBase extends ControllerBase {
self: RepositoryService
with ActivityService
with AccountService
with IssuesService
with RepositorySearchService
with UsersAuthenticator
with ReferrerAuthenticator
Expand Down Expand Up @@ -194,18 +195,62 @@ trait IndexControllerBase extends ControllerBase {
contentType = formats("json")
val user = params("user").toBoolean
val group = params("group").toBoolean

val issueRe = (context.baseUrl + """/(\w+)/(\w+)/(?:issues|pull)/(\d+)""").r
val sortByFunc: Account => String = context.request.referrer match {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting repository and issue (or pull request) identifier from referrer is nice idea, but I think it's little tricky. It might be better to pass these information as optional query string parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I know, this request is called from helper/attached.scala.html through helper/preview.scala.html. preview.scala.html called from issue/pulls comment, wiki edit and release message edit. So it is complicated to add optional query string.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... Okay. It wasn't so easy. Anyway, I don't prefer kind of ad-hoc solution. I will try to find an another way. Sorry for keeping this pull request reviewing.

case Some(issueRe(owner, repo, num)) =>
val collabolatorNames = getCollaboratorUserNames(owner, repo)
val comments = getComments(owner, repo, num.toInt)
val commentIdMax =
if (comments.isEmpty) 0
else
comments.map { c =>
c.commentId
}.max
val userCommentMap = comments.groupBy(c => c.commentedUserName).mapValues { lst =>
lst.map { c =>
commentIdMax - c.commentId
}.max
}
val groupMembers = getGroupMembers(owner).map(_.userName)
val issue = getIssue(owner, repo, num).get
a: Account =>
{
val typeStr = if (Some(a.userName) == context.loginAccount.map(_.userName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.loginAccount.contains(a.userName) is much simpler.

"8"
} else if (userCommentMap.contains(a.userName)) {
f"""0${userCommentMap(a.userName)}%08d"""
} else if (a.userName == issue.openedUserName) {
"1"
} else if (a.userName == issue.assignedUserName) {
"2"
} else if (a.userName == owner || groupMembers.contains(a.userName)) {
"3"
} else if (collabolatorNames.contains(a.userName)) {
"4"
} else {
"9"
}
s"""${typeStr}${a.userName}"""
}
case _ =>
a: Account =>
a.userName
}

org.json4s.jackson.Serialization.write(
Map(
"options" -> (
getAllUsers(false)
.withFilter { t =>
.filter { t =>
(user, group) match {
case (true, true) => true
case (true, false) => !t.isGroupAccount
case (false, true) => t.isGroupAccount
case (false, false) => false
}
}
.sortBy(sortByFunc)
.map { t =>
Map(
"label" -> s"<b>@${t.userName}</b> ${t.fullName}",
Expand Down