Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Custom Reactions #8886

Merged
merged 23 commits into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ SHOW_USER_EMAIL = true
DEFAULT_THEME = gitea
; All available themes. Allow users select personalized themes regardless of the value of `DEFAULT_THEME`.
THEMES = gitea,arc-green
; All available reactions. Allow users react with different emoji's
: For the whole list look at https://gitea.com/gitea/gitea.com/issues/8
REACTIONS = +1, -1, laugh, hooray, confused, heart, rocket, eyes
6543 marked this conversation as resolved.
Show resolved Hide resolved
; Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
DEFAULT_SHOW_FULL_NAME = false
; Whether to search within description at repository search on explore page.
Expand Down
9 changes: 9 additions & 0 deletions docs/content/doc/advanced/customizing-gitea.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ Locales may change between versions, so keeping track of your customized locales

To add a custom Readme, add a markdown formatted file (without an `.md` extension) to `custom/options/readme`

### Reactions

To change reaction emoji's you can set allowed reactions at app.ini
```
[ui]
REACTIONS = +1, -1, laugh, confused, heart, hooray, eyes
```
A full list of supported emoji's is at [emoji list](https://gitea.com/gitea/gitea.com/issues/8)

## Customizing the look of Gitea

As of version 1.6.0 Gitea has built-in themes. The two built-in themes are, the default theme `gitea`, and a dark theme `arc-green`. To change the look of your Gitea install change the value of `DEFAULT_THEME` in the [ui](https://docs.gitea.io/en-us/config-cheat-sheet/#ui-ui) section of `app.ini` to another one of the available options.
Expand Down
26 changes: 26 additions & 0 deletions integrations/issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,32 @@ func TestIssueCommentClose(t *testing.T) {
assert.Equal(t, "Description", val)
}

func TestIssueReaction(t *testing.T) {
defer prepareTestEnv(t)()
session := loginUser(t, "user2")
issueURL := testNewIssue(t, session, "user2", "repo1", "Title", "Description")

req := NewRequest(t, "GET", issueURL)
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)

req = NewRequestWithValues(t, "POST", path.Join(issueURL, "/reactions/react"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
"content": "8ball",
})
session.MakeRequest(t, req, http.StatusInternalServerError)
req = NewRequestWithValues(t, "POST", path.Join(issueURL, "/reactions/react"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
"content": "eyes",
})
session.MakeRequest(t, req, http.StatusOK)
req = NewRequestWithValues(t, "POST", path.Join(issueURL, "/reactions/unreact"), map[string]string{
"_csrf": htmlDoc.GetCSRF(),
"content": "eyes",
})
session.MakeRequest(t, req, http.StatusOK)
}

func TestIssueCrossReference(t *testing.T) {
defer prepareTestEnv(t)()

Expand Down
2 changes: 1 addition & 1 deletion modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors)

// ReactionForm form for adding and removing reaction
type ReactionForm struct {
Content string `binding:"Required;In(+1,-1,laugh,confused,heart,hooray)"`
Content string `binding:"Required"`
}

// Validate validates the fields
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ var (
DefaultShowFullName bool
DefaultTheme string
Themes []string
Reactions []string
SearchRepoDescription bool
UseServiceWorker bool

Expand Down Expand Up @@ -198,6 +199,7 @@ var (
MaxDisplayFileSize: 8388608,
DefaultTheme: `gitea`,
Themes: []string{`gitea`, `arc-green`},
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
Admin: struct {
UserPagingNum int
RepoPagingNum int
Expand Down
13 changes: 13 additions & 0 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ func ViewIssue(ctx *context.Context) {
}
}
ctx.Data["IssueWatch"] = iw
ctx.Data["AllowedReactions"] = setting.UI.Reactions

issue.RenderedContent = string(markdown.Render([]byte(issue.Content), ctx.Repo.RepoLink,
ctx.Repo.Repository.ComposeMetas()))
Expand Down Expand Up @@ -1447,6 +1448,12 @@ func ChangeIssueReaction(ctx *context.Context, form auth.ReactionForm) {

switch ctx.Params(":action") {
case "react":
if !util.IsStringInSlice(form.Content, setting.UI.Reactions) {
err := fmt.Errorf("ChangeIssueReaction: '%s' is not an allowed reaction", form.Content)
ctx.ServerError(err.Error(), err)
return
}

reaction, err := models.CreateIssueReaction(ctx.User, issue, form.Content)
if err != nil {
log.Info("CreateIssueReaction: %s", err)
Expand Down Expand Up @@ -1542,6 +1549,12 @@ func ChangeCommentReaction(ctx *context.Context, form auth.ReactionForm) {

switch ctx.Params(":action") {
case "react":
if !util.IsStringInSlice(form.Content, setting.UI.Reactions) {
err := fmt.Errorf("ChangeIssueReaction: '%s' is not an allowed reaction", form.Content)
ctx.ServerError(err.Error(), err)
return
}

reaction, err := models.CreateCommentReaction(ctx.User, comment.Issue, comment, form.Content)
if err != nil {
log.Info("CreateCommentReaction: %s", err)
Expand Down
1 change: 1 addition & 0 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare

ctx.Data["NumCommits"] = compareInfo.Commits.Len()
ctx.Data["NumFiles"] = compareInfo.NumFiles
ctx.Data["AllowedReactions"] = setting.UI.Reactions
return compareInfo
}

Expand Down
2 changes: 1 addition & 1 deletion templates/repo/diff/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{{$reactions := .Reactions.GroupByType}}
{{if $reactions}}
<div class="ui attached segment reactions">
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions }}
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.root.RepoLink .ID) "Reactions" $reactions "AllowedReactions" $.AllowedReactions }}
</div>
{{end}}
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/repo/issue/view_content.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{{end}}
{{if not $.Repository.IsArchived}}
<div class="ui right actions">
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) }}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "AllowedReactions" $.AllowedReactions}}
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" .Issue "delete" false "diff" false }}
</div>
{{end}}
Expand All @@ -47,7 +47,7 @@
{{$reactions := .Issue.Reactions.GroupByType}}
{{if $reactions}}
<div class="ui attached segment reactions">
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "Reactions" $reactions }}
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/issues/%d/reactions" $.RepoLink .Issue.Index) "Reactions" $reactions "AllowedReactions" $.AllowedReactions}}
</div>
{{end}}
{{if .Issue.Attachments}}
Expand Down
15 changes: 9 additions & 6 deletions templates/repo/issue/view_content/add_reaction.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
<div class="menu has-emoji">
<div class="header">{{ .ctx.i18n.Tr "repo.pick_reaction"}}</div>
<div class="divider"></div>
<div class="item" data-content="+1">:+1:</div>
<div class="item" data-content="-1">:-1:</div>
<div class="item" data-content="laugh">:laughing:</div>
<div class="item" data-content="confused">:confused:</div>
<div class="item" data-content="heart">:heart:</div>
<div class="item" data-content="hooray">:tada:</div>
{{range $value := .AllowedReactions}}
{{if eq $value "hooray"}}
<div class="item" data-content="hooray">:tada:</div>
{{else if eq $value "laugh"}}
<div class="item" data-content="laugh">:laughing:</div>
{{else}}
<div class="item" data-content="{{$value}}">:{{$value}}:</div>
{{end}}
{{end}}
</div>
</div>
{{end}}
4 changes: 2 additions & 2 deletions templates/repo/issue/view_content/comments.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{{end}}
</div>
{{end}}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) }}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) "AllowedReactions" $.AllowedReactions}}
{{template "repo/issue/view_content/context_menu" Dict "ctx" $ "item" . "delete" true "diff" false }}
</div>
{{end}}
Expand All @@ -55,7 +55,7 @@
{{$reactions := .Reactions.GroupByType}}
{{if $reactions}}
<div class="ui attached segment reactions">
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions }}
{{template "repo/issue/view_content/reactions" Dict "ctx" $ "ActionURL" (Printf "%s/comments/%d/reactions" $.RepoLink .ID) "Reactions" $reactions "AllowedReactions" $.AllowedReactions}}
</div>
{{end}}
{{if .Attachments}}
Expand Down
12 changes: 6 additions & 6 deletions templates/repo/issue/view_content/reactions.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<a class="ui label basic{{if $value.HasUser $.ctx.SignedUserID}} blue{{end}}{{if not $.ctx.IsSigned}} disabled{{end}} has-emoji" data-title="{{$value.GetFirstUsers}}{{if gt ($value.GetMoreUserCount) 0}} {{ $.ctx.i18n.Tr "repo.reactions_more" $value.GetMoreUserCount}}{{end}}" data-content="{{ $key }}" data-action-url="{{ $.ActionURL }}">
{{if eq $key "hooray"}}
:tada:
{{else if eq $key "laugh"}}
:laughing:
{{else}}
{{if eq $key "laugh"}}
:laughing:
{{else}}
:{{$key}}:
{{end}}
:{{$key}}:
{{end}}
{{len $value}}
</a>
{{end}}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $.ctx "ActionURL" .ActionURL }}
{{if $.AllowedReactions}}
{{template "repo/issue/view_content/add_reaction" Dict "ctx" $.ctx "ActionURL" .ActionURL "AllowedReactions" $.AllowedReactions}}
{{end}}