mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 16:44:26 +00:00
parent
838653d1df
commit
4142397b0b
@ -637,8 +637,12 @@ func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment,
|
|||||||
return attachHTML
|
return attachHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
// get all teams that current user can mention
|
// handleMentionableAssigneesAndTeams gets all teams that current user can mention, and fills the assignee users to the context data
|
||||||
func handleTeamMentions(ctx *context.Context) {
|
func handleMentionableAssigneesAndTeams(ctx *context.Context, assignees []*user_model.User) {
|
||||||
|
// TODO: need to figure out how many places this is really used, and rename it to "MentionableAssignees"
|
||||||
|
// at the moment it is used on the issue list page, for the markdown editor mention
|
||||||
|
ctx.Data["Assignees"] = assignees
|
||||||
|
|
||||||
if ctx.Doer == nil || !ctx.Repo.Owner.IsOrganization() {
|
if ctx.Doer == nil || !ctx.Repo.Owner.IsOrganization() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -715,9 +715,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
|
|||||||
ctx.ServerError("GetRepoAssignees", err)
|
ctx.ServerError("GetRepoAssignees", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["Assignees"] = shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers)
|
handleMentionableAssigneesAndTeams(ctx, shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers))
|
||||||
|
|
||||||
handleTeamMentions(ctx)
|
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ func (d *IssuePageMetaData) retrieveAssigneesDataForIssueWriter(ctx *context.Con
|
|||||||
d.AssigneesData.SelectedAssigneeIDs = strings.Join(ids, ",")
|
d.AssigneesData.SelectedAssigneeIDs = strings.Join(ids, ",")
|
||||||
}
|
}
|
||||||
// FIXME: this is a tricky part which writes ctx.Data["Mentionable*"]
|
// FIXME: this is a tricky part which writes ctx.Data["Mentionable*"]
|
||||||
handleTeamMentions(ctx)
|
handleMentionableAssigneesAndTeams(ctx, d.AssigneesData.CandidateAssignees)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *IssuePageMetaData) retrieveProjectsDataForIssueWriter(ctx *context.Context) {
|
func (d *IssuePageMetaData) retrieveProjectsDataForIssueWriter(ctx *context.Context) {
|
||||||
|
@ -840,9 +840,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
|
|||||||
ctx.ServerError("GetRepoAssignees", err)
|
ctx.ServerError("GetRepoAssignees", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx.Data["Assignees"] = shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers)
|
handleMentionableAssigneesAndTeams(ctx, shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers))
|
||||||
|
|
||||||
handleTeamMentions(ctx)
|
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,19 +4,23 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"slices"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/user"
|
"code.gitea.io/gitea/models/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
|
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
|
||||||
if doer != nil {
|
if doer != nil {
|
||||||
sort.Slice(users, func(i, j int) bool {
|
idx := slices.IndexFunc(users, func(u *user.User) bool {
|
||||||
if users[i].ID == users[j].ID {
|
return u.ID == doer.ID
|
||||||
return false
|
|
||||||
}
|
|
||||||
return users[i].ID == doer.ID // if users[i] is self, put it before others, so less=true
|
|
||||||
})
|
})
|
||||||
|
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
|
return users
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user