From ecb10ed62fdff179e34f82b0ff2569da8390f4ad Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Sat, 22 Apr 2017 21:52:03 +0900 Subject: APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name (#6117) * APIv4 DELETE /users/{user_id}/posts/{post_id}/reactions/name * updated v3 deleteReaction endpoint * update parameter of app.DeleteReactionForPost() * update utils.IsValidAlphaNum, add utils.IsValidAlphaNumHyphenUnderscore, and add related tests --- app/reaction.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app/reaction.go') diff --git a/app/reaction.go b/app/reaction.go index eb542286f..cc57e1c4c 100644 --- a/app/reaction.go +++ b/app/reaction.go @@ -34,6 +34,23 @@ func GetReactionsForPost(postId string) ([]*model.Reaction, *model.AppError) { } } +func DeleteReactionForPost(reaction *model.Reaction) *model.AppError { + post, err := GetSinglePost(reaction.PostId) + if err != nil { + return err + } + + if result := <-Srv.Store.Reaction().Delete(reaction); result.Err != nil { + return result.Err + } else { + go sendReactionEvent(model.WEBSOCKET_EVENT_REACTION_REMOVED, reaction, post) + + InvalidateCacheForReactions(reaction.PostId) + } + + return nil +} + func sendReactionEvent(event string, reaction *model.Reaction, post *model.Post) { // send out that a reaction has been added/removed message := model.NewWebSocketEvent(event, "", post.ChannelId, "", nil) -- cgit v1.2.3-1-g7c22