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

Add RHS informations card to show users votes #431

Merged
merged 9 commits into from
Jul 16, 2022
12 changes: 11 additions & 1 deletion assets/i18n/active.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"command.help.text.pollSetting.multi-vote": "Allow users to vote for X options",
"command.help.text.pollSetting.progress": "During the poll, show how many votes each answer option got",
"command.help.text.pollSetting.public-add-option": "Allow all users to add additional options",
"command.help.text.pollSetting.show-voters": "Show extra informations on who voted for what during poll",
"command.help.text.simple": "To create a poll with the answer options \"{{.Yes}}\" and \"{{.No}}\" type `/{{.Trigger}} \"Question\"`",
"dialog.addOption.element.displayName": "Option",
"dialog.addOption.submitLabel": "Add",
Expand All @@ -28,6 +29,7 @@
"dialog.end.title": "Confirm Poll End",
"poll.addAnswerOption.duplicate": "Duplicate option: {{.Option}}",
"poll.addAnswerOption.empty": "Empty option not allowed",
"poll.validateShowVotersOption.error": "Poll can't be Anonymous and Show Voters",
"poll.button.addOption": "Add Option",
"poll.button.deletePoll": "Delete Poll",
"poll.button.endPoll": "End Poll",
Expand Down Expand Up @@ -67,5 +69,13 @@
"one": "Your vote has been counted. You have {{.Remains}} vote left.",
"other": "Your vote has been counted. You have {{.Remains}} votes left."
},
"response.vote.updated": "Your vote has been updated."
"response.vote.updated": "Your vote has been updated.",
"rhs.card.poll.answer.heading": {
"few": "{{.Answer}} ({{.Count}} votes)",
"many": "{{.Answer}} ({{.Count}} votes)",
"one": "{{.Answer}} ({{.Count}} vote)",
"other": "{{.Answer}} ({{.Count}} votes)"
},
"rhs.card.poll.createdBy": "Create by",
"rhs.card.poll.voter.seperator": "and"
}
14 changes: 14 additions & 0 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ func (p *MatterpollPlugin) handleCreatePoll(_ map[string]string, request *model.
"poll_id": poll.ID,
},
}

model.ParseSlackAttachment(post, actions)
if poll.Settings.ShowVoters {
post.AddProp("card", poll.ToCard(p.bundle, p.ConvertCreatorIDToDisplayName))
kaakaa marked this conversation as resolved.
Show resolved Hide resolved
}

rPost, appErr := p.API.CreatePost(post)
if appErr != nil {
Expand Down Expand Up @@ -381,6 +385,9 @@ func (p *MatterpollPlugin) handleVote(vars map[string]string, request *model.Pos
post := &model.Post{}
model.ParseSlackAttachment(post, poll.ToPostActions(p.bundle, manifest.Id, displayName))
post.AddProp("poll_id", poll.ID)
if poll.Settings.ShowVoters {
post.AddProp("card", poll.ToCard(p.bundle, p.ConvertCreatorIDToDisplayName))
}

if poll.IsMultiVote() {
// Multi Answer Mode
Expand Down Expand Up @@ -451,6 +458,9 @@ func (p *MatterpollPlugin) handleResetVotes(vars map[string]string, request *mod
post := &model.Post{}
model.ParseSlackAttachment(post, poll.ToPostActions(p.bundle, manifest.Id, displayName))
post.AddProp("poll_id", poll.ID)
if poll.Settings.ShowVoters {
post.AddProp("card", poll.ToCard(p.bundle, p.ConvertCreatorIDToDisplayName))
}

return &i18n.LocalizeConfig{
DefaultMessage: &i18n.Message{
Expand Down Expand Up @@ -557,6 +567,10 @@ func (p *MatterpollPlugin) handleAddOptionConfirm(vars map[string]string, reques
}

model.ParseSlackAttachment(post, poll.ToPostActions(p.bundle, manifest.Id, displayName))
if poll.Settings.ShowVoters {
post.AddProp("card", poll.ToCard(p.bundle, p.ConvertCreatorIDToDisplayName))
}

if _, appErr = p.API.UpdatePost(post); appErr != nil {
return commandErrorGeneric, nil, errors.Wrap(appErr, "failed to update post")
}
Expand Down