aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/shared
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-12-04 22:57:50 +0800
committerGitHub <noreply@github.com>2024-12-04 22:57:50 +0800
commit4142397b0bd97c72da2af99292340b7bc68c3f49 (patch)
tree7a9923bfb621066494cd9ef0f7d77d4f9015a958 /routers/web/shared
parent838653d1dfa0fbc6313b0bba682075baba385a5e (diff)
downloadgitea-4142397b0bd97c72da2af99292340b7bc68c3f49.tar.gz
gitea-4142397b0bd97c72da2af99292340b7bc68c3f49.zip
Fix mentionable users when writing issue comments (#32715)
Fix #32702
Diffstat (limited to 'routers/web/shared')
-rw-r--r--routers/web/shared/user/helper.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/routers/web/shared/user/helper.go b/routers/web/shared/user/helper.go
index 6186b9b9ff..dfd65420c1 100644
--- a/routers/web/shared/user/helper.go
+++ b/routers/web/shared/user/helper.go
@@ -4,19 +4,23 @@
package user
import (
- "sort"
+ "slices"
"code.gitea.io/gitea/models/user"
)
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
if doer != nil {
- sort.Slice(users, func(i, j int) bool {
- if users[i].ID == users[j].ID {
- return false
- }
- return users[i].ID == doer.ID // if users[i] is self, put it before others, so less=true
+ idx := slices.IndexFunc(users, func(u *user.User) bool {
+ return u.ID == doer.ID
})
+ if idx > 0 {
+ newUsers := make([]*user.User, len(users))
+ newUsers[0] = users[idx]
+ copy(newUsers[1:], users[:idx])
+ copy(newUsers[idx+1:], users[idx+1:])
+ return newUsers
+ }
}
return users
}