Skip to content

Commit ab60759

Browse files
committed
fix
1 parent 838653d commit ab60759

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

routers/web/repo/issue.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ func attachmentsHTML(ctx *context.Context, attachments []*repo_model.Attachment,
637637
return attachHTML
638638
}
639639

640-
// get all teams that current user can mention
641-
func handleTeamMentions(ctx *context.Context) {
640+
// handleMarkdownEditorMentions gets all teams that current user can mention, and fills the assignee users to the context data
641+
func handleMarkdownEditorMentions(ctx *context.Context, assignees []*user_model.User) {
642642
if ctx.Doer == nil || !ctx.Repo.Owner.IsOrganization() {
643643
return
644644
}
@@ -672,6 +672,7 @@ func handleTeamMentions(ctx *context.Context) {
672672
}
673673
}
674674

675+
ctx.Data["Assignees"] = assignees // TODO: need to figure out how many places this is really used, and rename it to "MentionableAssignees"
675676
ctx.Data["MentionableTeams"] = teams
676677
ctx.Data["MentionableTeamsOrg"] = ctx.Repo.Owner.Name
677678
ctx.Data["MentionableTeamsOrgAvatar"] = ctx.Repo.Owner.AvatarLink(ctx)

routers/web/repo/issue_list.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
715715
ctx.ServerError("GetRepoAssignees", err)
716716
return
717717
}
718-
ctx.Data["Assignees"] = shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers)
719-
720-
handleTeamMentions(ctx)
718+
handleMarkdownEditorMentions(ctx, shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers))
721719
if ctx.Written() {
722720
return
723721
}

routers/web/repo/issue_page_meta.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (d *IssuePageMetaData) retrieveAssigneesDataForIssueWriter(ctx *context.Con
148148
d.AssigneesData.SelectedAssigneeIDs = strings.Join(ids, ",")
149149
}
150150
// FIXME: this is a tricky part which writes ctx.Data["Mentionable*"]
151-
handleTeamMentions(ctx)
151+
handleMarkdownEditorMentions(ctx, d.AssigneesData.CandidateAssignees)
152152
}
153153

154154
func (d *IssuePageMetaData) retrieveProjectsDataForIssueWriter(ctx *context.Context) {

routers/web/repo/pull.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,9 +840,7 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
840840
ctx.ServerError("GetRepoAssignees", err)
841841
return
842842
}
843-
ctx.Data["Assignees"] = shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers)
844-
845-
handleTeamMentions(ctx)
843+
handleMarkdownEditorMentions(ctx, shared_user.MakeSelfOnTop(ctx.Doer, assigneeUsers))
846844
if ctx.Written() {
847845
return
848846
}

routers/web/shared/user/helper.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,23 @@
44
package user
55

66
import (
7-
"sort"
7+
"slices"
88

99
"code.gitea.io/gitea/models/user"
1010
)
1111

1212
func MakeSelfOnTop(doer *user.User, users []*user.User) []*user.User {
1313
if doer != nil {
14-
sort.Slice(users, func(i, j int) bool {
15-
if users[i].ID == users[j].ID {
16-
return false
17-
}
18-
return users[i].ID == doer.ID // if users[i] is self, put it before others, so less=true
14+
idx := slices.IndexFunc(users, func(u *user.User) bool {
15+
return u.ID == doer.ID
1916
})
17+
if idx != -1 {
18+
newUsers := make([]*user.User, len(users))
19+
newUsers[0] = users[idx]
20+
copy(newUsers[1:], users[:idx])
21+
copy(newUsers[idx+1:], users[idx+1:])
22+
return newUsers
23+
}
2024
}
2125
return users
2226
}

0 commit comments

Comments
 (0)