Refactor commentTags functionality (#17558)
* feat: Allow multiple tags on comments - Allow for multiples tags(Currently Poster + {Owner, Writer}). - Utilize the Poster tag within the commentTag function and remove the checking from templates. - Use bitwise on CommentTags to enable specific tags. - Don't show poster tag(view_content.tmpl) on the initial issue comment. * Change parameters naming * Change function name * refactor variable wording * Merge 'master' branch into 'tags-comments' branch * Change naming * `tag` -> `role` Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
a4dc0c5a82
commit
492e1c2fbd
5 changed files with 112 additions and 75 deletions
|
@ -71,7 +71,7 @@ type Issue struct {
|
|||
IsLocked bool `xorm:"NOT NULL DEFAULT false"`
|
||||
|
||||
// For view issue page.
|
||||
ShowTag CommentTag `xorm:"-"`
|
||||
ShowRole RoleDescriptor `xorm:"-"`
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -105,17 +105,43 @@ const (
|
|||
CommentTypeDismissReview
|
||||
)
|
||||
|
||||
// CommentTag defines comment tag type
|
||||
type CommentTag int
|
||||
// RoleDescriptor defines comment tag type
|
||||
type RoleDescriptor int
|
||||
|
||||
// Enumerate all the comment tag types
|
||||
// Enumerate all the role tags.
|
||||
const (
|
||||
CommentTagNone CommentTag = iota
|
||||
CommentTagPoster
|
||||
CommentTagWriter
|
||||
CommentTagOwner
|
||||
RoleDescriptorNone RoleDescriptor = iota
|
||||
RoleDescriptorPoster
|
||||
RoleDescriptorWriter
|
||||
RoleDescriptorOwner
|
||||
)
|
||||
|
||||
// WithRole enable a specific tag on the RoleDescriptor.
|
||||
func (rd RoleDescriptor) WithRole(role RoleDescriptor) RoleDescriptor {
|
||||
rd |= (1 << role)
|
||||
return rd
|
||||
}
|
||||
|
||||
func stringToRoleDescriptor(role string) RoleDescriptor {
|
||||
switch role {
|
||||
case "Poster":
|
||||
return RoleDescriptorPoster
|
||||
case "Writer":
|
||||
return RoleDescriptorWriter
|
||||
case "Owner":
|
||||
return RoleDescriptorOwner
|
||||
default:
|
||||
return RoleDescriptorNone
|
||||
}
|
||||
}
|
||||
|
||||
// HasRole returns if a certain role is enabled on the RoleDescriptor.
|
||||
func (rd RoleDescriptor) HasRole(role string) bool {
|
||||
roleDescriptor := stringToRoleDescriptor(role)
|
||||
bitValue := rd & (1 << roleDescriptor)
|
||||
return (bitValue > 0)
|
||||
}
|
||||
|
||||
// Comment represents a comment in commit and issue page.
|
||||
type Comment struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
|
@ -174,7 +200,7 @@ type Comment struct {
|
|||
Reactions ReactionList `xorm:"-"`
|
||||
|
||||
// For view issue page.
|
||||
ShowTag CommentTag `xorm:"-"`
|
||||
ShowRole RoleDescriptor `xorm:"-"`
|
||||
|
||||
Review *Review `xorm:"-"`
|
||||
ReviewID int64 `xorm:"index"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue