Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "com.github.matterpoll.matterpoll",
"name": "Matterpoll",
"description": "Polling feature for Mattermost's custom slash command",
"version": "1.0.3",
"version": "1.0.3.2",
"min_server_version": "5.6.0",
"server": {
"executables": {
Expand Down
25 changes: 23 additions & 2 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (

voteCounted = "Your vote has been counted."
voteUpdated = "Your vote has been updated."
unVote = "Your vote has been remove."

// Parameter: Question, Permalink
endPollSuccessfullyFormat = "The poll **%s** has ended and the original post have been updated. You can jump to it by pressing [here](%s)."
Expand Down Expand Up @@ -103,24 +104,44 @@ func (p *MatterpollPlugin) handleVote(w http.ResponseWriter, r *http.Request) {
}

hasVoted := poll.HasVoted(userID)
isUnvote := poll.DuplicatedVote(userID, optionNumber)

if err = poll.UpdateVote(userID, optionNumber); err != nil {
response.EphemeralText = commandGenericError
writePostActionIntegrationResponse(w, response)
return
}

if hasVoted {
if isUnvote {
if err = poll.Unvote(userID, optionNumber); err != nil {
response.EphemeralText = commandGenericError
writePostActionIntegrationResponse(w, response)
return
}
} else {
if err = poll.UpdateVote(userID, optionNumber); err != nil {
response.EphemeralText = commandGenericError
writePostActionIntegrationResponse(w, response)
return
}
}
}

if err = p.Store.Poll().Save(poll); err != nil {
response.EphemeralText = commandGenericError
writePostActionIntegrationResponse(w, response)
return
}

post := &model.Post{}
model.ParseSlackAttachment(post, poll.ToPostActions(*p.ServerConfig.ServiceSettings.SiteURL, PluginId, displayName))
model.ParseSlackAttachment(post, poll.ToPostActions(*p.ServerConfig.ServiceSettings.SiteURL, PluginId, displayName, p.ConvertUserIDToDisplayName))
response.Update = post

if hasVoted {
response.EphemeralText = voteUpdated
} else if isUnvote {
response.EphemeralText = unVote
} else {
response.EphemeralText = voteCounted
}
Expand Down Expand Up @@ -180,7 +201,7 @@ func (p *MatterpollPlugin) handleAddOption(w http.ResponseWriter, r *http.Reques
return
}

model.ParseSlackAttachment(post, poll.ToPostActions(*p.ServerConfig.ServiceSettings.SiteURL, PluginId, displayName))
model.ParseSlackAttachment(post, poll.ToPostActions(*p.ServerConfig.ServiceSettings.SiteURL, PluginId, displayName, p.ConvertUserIDToDisplayName))
if _, appErr = p.API.UpdatePost(post); appErr != nil {
p.API.LogError("failed to update post", "err", appErr.Error())
p.SendEphemeralPost(request.ChannelId, request.UserId, commandGenericError)
Expand Down
Loading