change remove property to DELETE

This commit is contained in:
René Filip
2021-11-02 20:10:52 +01:00
parent 73f251906b
commit 5aebc46fa6

View File

@@ -62,7 +62,6 @@ type Reaction struct {
Reaction string `json:"reaction"` Reaction string `json:"reaction"`
TargetAuthor string `json:"target_author"` TargetAuthor string `json:"target_author"`
Timestamp int64 `json:"timestamp"` Timestamp int64 `json:"timestamp"`
Remove bool `json:"remove,omitempty"`
} }
type SendMessageV1 struct { type SendMessageV1 struct {
@@ -895,9 +894,9 @@ func (a *Api) QuitGroup(c *gin.Context) {
c.Status(http.StatusNoContent) c.Status(http.StatusNoContent)
} }
// @Summary Send or remove a reaction. // @Summary Send a reaction.
// @Tags Reactions // @Tags Reactions
// @Description React to a message or remove it. // @Description React to a message
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 204 {string} OK // @Success 204 {string} OK
@@ -905,7 +904,7 @@ func (a *Api) QuitGroup(c *gin.Context) {
// @Param data body Reaction true "Reaction" // @Param data body Reaction true "Reaction"
// @Router /v1/react/{number} [post] // @Router /v1/react/{number} [post]
func (a *Api) SendReaction(c *gin.Context) { func (a *Api) SendReaction(c *gin.Context) {
req := Reaction{Remove: false} var req Reaction
err := c.BindJSON(&req) err := c.BindJSON(&req)
if err != nil { if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"}) c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
@@ -935,7 +934,55 @@ func (a *Api) SendReaction(c *gin.Context) {
return return
} }
err = a.signalClient.SendReaction(number, req.Recipient, req.Reaction, req.TargetAuthor, req.Timestamp, req.Remove) err = a.signalClient.SendReaction(number, req.Recipient, req.Reaction, req.TargetAuthor, req.Timestamp, false)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
c.Status(http.StatusNoContent)
}
// @Summary Remove a reaction.
// @Tags Reactions
// @Description Remove a reaction
// @Accept json
// @Produce json
// @Success 204 {string} OK
// @Failure 400 {object} Error
// @Param data body Reaction true "Reaction"
// @Router /v1/react/{number} [delete]
func (a *Api) RemoveReaction(c *gin.Context) {
var req Reaction
err := c.BindJSON(&req)
if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
log.Error(err.Error())
return
}
number := c.Param("number")
if req.Recipient == "" {
c.JSON(400, Error{Msg: "Couldn't process request - recipient missing"})
return
}
if req.Reaction == "" {
c.JSON(400, Error{Msg: "Couldn't process request - reaction missing"})
return
}
if req.TargetAuthor == "" {
c.JSON(400, Error{Msg: "Couldn't process request - target_author missing"})
return
}
if req.Timestamp == 0 {
c.JSON(400, Error{Msg: "Couldn't process request - timestamp missing"})
return
}
err = a.signalClient.SendReaction(number, req.Recipient, req.Reaction, req.TargetAuthor, req.Timestamp, true)
if err != nil { if err != nil {
c.JSON(400, Error{Msg: err.Error()}) c.JSON(400, Error{Msg: err.Error()})
return return