feat(conversations): finish message mutation parity
This commit is contained in:
@@ -3,6 +3,7 @@ package v1
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -61,9 +62,10 @@ func (h *MessageHandler) List(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
p := pagination.Parse(c)
|
||||
|
||||
messages, _, svcErr := h.svc.ListByConversation(c.Request.Context(), conversation.ID, p.Offset, p.PerPage)
|
||||
after, _ := strconv.ParseUint(c.Query("after"), 10, 64)
|
||||
before, _ := strconv.ParseUint(c.Query("before"), 10, 64)
|
||||
filterInternal := c.Query("filter_internal_messages") != ""
|
||||
messages, _, svcErr := h.svc.ListByConversationFinder(c.Request.Context(), conversation.ID, uint(after), uint(before), filterInternal)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
@@ -168,7 +170,8 @@ func (h *MessageHandler) Get(c *gin.Context) {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.OK(c, message)
|
||||
conversation, _ := h.svc.ResolveConversationForRoute(c.Request.Context(), accountID, message.ConversationID)
|
||||
c.JSON(http.StatusOK, serializeMessage(c.Request.Context(), h.svc.DB(), message, conversation))
|
||||
}
|
||||
|
||||
// Update updates a message's content.
|
||||
@@ -229,11 +232,13 @@ func (h *MessageHandler) Delete(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if svcErr := h.svc.Delete(c.Request.Context(), accountID, messageID); svcErr != nil {
|
||||
message, svcErr := h.svc.Delete(c.Request.Context(), accountID, messageID)
|
||||
if svcErr != nil {
|
||||
handleServiceError(c, svcErr)
|
||||
return
|
||||
}
|
||||
response.NoContent(c)
|
||||
conversation, _ := h.svc.ResolveConversationForRoute(c.Request.Context(), accountID, message.ConversationID)
|
||||
c.JSON(http.StatusOK, serializeMessage(c.Request.Context(), h.svc.DB(), message, conversation))
|
||||
}
|
||||
|
||||
// Search searches messages by content within an account.
|
||||
@@ -339,6 +344,17 @@ func bindCreateMessageRequest(c *gin.Context, req *service.CreateMessageRequest)
|
||||
if raw := c.PostForm("content_attributes"); raw != "" {
|
||||
req.ContentAttributes = []byte(raw)
|
||||
}
|
||||
if c.Request.MultipartForm != nil {
|
||||
for _, key := range []string{"attachments[]", "attachments"} {
|
||||
for _, file := range c.Request.MultipartForm.File[key] {
|
||||
req.Attachments = append(req.Attachments, service.MessageAttachmentInput{
|
||||
FileName: file.Filename,
|
||||
FileSize: int(file.Size),
|
||||
ContentType: file.Header.Get("Content-Type"),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user