code.gitea.io/gitea@v1.21.7/services/forms/user_form_hidden_comments.go (about) 1 // Copyright 2021 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package forms 5 6 import ( 7 "math/big" 8 9 issues_model "code.gitea.io/gitea/models/issues" 10 "code.gitea.io/gitea/modules/context" 11 "code.gitea.io/gitea/modules/log" 12 ) 13 14 type hiddenCommentTypeGroupsType map[string][]issues_model.CommentType 15 16 // hiddenCommentTypeGroups maps the group names to comment types, these group names comes from the Web UI (appearance.tmpl) 17 var hiddenCommentTypeGroups = hiddenCommentTypeGroupsType{ 18 "reference": { 19 /*3*/ issues_model.CommentTypeIssueRef, 20 /*4*/ issues_model.CommentTypeCommitRef, 21 /*5*/ issues_model.CommentTypeCommentRef, 22 /*6*/ issues_model.CommentTypePullRef, 23 }, 24 "label": { 25 /*7*/ issues_model.CommentTypeLabel, 26 }, 27 "milestone": { 28 /*8*/ issues_model.CommentTypeMilestone, 29 }, 30 "assignee": { 31 /*9*/ issues_model.CommentTypeAssignees, 32 }, 33 "title": { 34 /*10*/ issues_model.CommentTypeChangeTitle, 35 }, 36 "branch": { 37 /*11*/ issues_model.CommentTypeDeleteBranch, 38 /*25*/ issues_model.CommentTypeChangeTargetBranch, 39 }, 40 "time_tracking": { 41 /*12*/ issues_model.CommentTypeStartTracking, 42 /*13*/ issues_model.CommentTypeStopTracking, 43 /*14*/ issues_model.CommentTypeAddTimeManual, 44 /*15*/ issues_model.CommentTypeCancelTracking, 45 /*26*/ issues_model.CommentTypeDeleteTimeManual, 46 }, 47 "deadline": { 48 /*16*/ issues_model.CommentTypeAddedDeadline, 49 /*17*/ issues_model.CommentTypeModifiedDeadline, 50 /*18*/ issues_model.CommentTypeRemovedDeadline, 51 }, 52 "dependency": { 53 /*19*/ issues_model.CommentTypeAddDependency, 54 /*20*/ issues_model.CommentTypeRemoveDependency, 55 }, 56 "lock": { 57 /*23*/ issues_model.CommentTypeLock, 58 /*24*/ issues_model.CommentTypeUnlock, 59 }, 60 "review_request": { 61 /*27*/ issues_model.CommentTypeReviewRequest, 62 }, 63 "pull_request_push": { 64 /*29*/ issues_model.CommentTypePullRequestPush, 65 }, 66 "project": { 67 /*30*/ issues_model.CommentTypeProject, 68 /*31*/ issues_model.CommentTypeProjectBoard, 69 }, 70 "issue_ref": { 71 /*33*/ issues_model.CommentTypeChangeIssueRef, 72 }, 73 } 74 75 // UserHiddenCommentTypesFromRequest parse the form to hidden comment types bitset 76 func UserHiddenCommentTypesFromRequest(ctx *context.Context) *big.Int { 77 bitset := new(big.Int) 78 for group, commentTypes := range hiddenCommentTypeGroups { 79 if ctx.FormBool(group) { 80 for _, commentType := range commentTypes { 81 bitset = bitset.SetBit(bitset, int(commentType), 1) 82 } 83 } 84 } 85 return bitset 86 } 87 88 // IsUserHiddenCommentTypeGroupChecked check whether a hidden comment type group is "enabled" (checked on UI) 89 func IsUserHiddenCommentTypeGroupChecked(group string, hiddenCommentTypes *big.Int) (ret bool) { 90 commentTypes, ok := hiddenCommentTypeGroups[group] 91 if !ok { 92 log.Critical("the group map for hidden comment types is out of sync, unknown group: %v", group) 93 return false 94 } 95 if hiddenCommentTypes == nil { 96 return false 97 } 98 for _, commentType := range commentTypes { 99 if hiddenCommentTypes.Bit(int(commentType)) == 1 { 100 return true 101 } 102 } 103 return false 104 }