2024-09-12 05:53:40 +02:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
2024-12-04 15:57:50 +01:00
|
|
|
"slices"
|
2024-09-12 05:53:40 +02:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/user"
|
|
|
|
)
|
|
|
|
|
|
|
|
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
|
|
|
|
if doer != nil {
|
2024-12-04 15:57:50 +01:00
|
|
|
idx := slices.IndexFunc(users, func(u *user.User) bool {
|
|
|
|
return u.ID == doer.ID
|
2024-09-12 05:53:40 +02:00
|
|
|
})
|
2024-12-04 15:57:50 +01:00
|
|
|
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
|
|
|
|
}
|
2024-09-12 05:53:40 +02:00
|
|
|
}
|
|
|
|
return users
|
|
|
|
}
|