gitea/routers/web/shared/user/helper.go
wxiaoguang 4142397b0b
Some checks are pending
release-nightly / nightly-binary (push) Waiting to run
release-nightly / nightly-docker-rootful (push) Waiting to run
release-nightly / nightly-docker-rootless (push) Waiting to run
Fix mentionable users when writing issue comments (#32715)
Fix #32702
2024-12-04 22:57:50 +08:00

27 lines
549 B
Go

// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package user
import (
"slices"
"code.gitea.io/gitea/models/user"
)
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
if doer != nil {
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
}