fix: chat accepts posts
This commit is contained in:
@@ -36,6 +36,8 @@ func writeChatError(w http.ResponseWriter, err error) {
|
||||
response.Error(w, http.StatusNotFound, "conversation not found")
|
||||
case errors.Is(err, service.ErrAvatarUnset):
|
||||
response.Error(w, http.StatusNotFound, err.Error())
|
||||
case errors.Is(err, service.ErrChatBadEntity):
|
||||
response.Error(w, http.StatusBadRequest, err.Error())
|
||||
case errors.Is(err, service.ErrChatBadQuote):
|
||||
response.Error(w, http.StatusBadRequest, err.Error())
|
||||
case errors.Is(err, service.ErrChatBadAvatarKey):
|
||||
@@ -190,8 +192,11 @@ type sendReq struct {
|
||||
Attachments []mediaReq `json:"attachments"`
|
||||
// quote is a passage shared from the library. `path` must be app-relative;
|
||||
// the service refuses anything that could navigate off-site.
|
||||
Quote *quoteReq `json:"quote"`
|
||||
ReplyToID *string `json:"reply_to_id"`
|
||||
Quote *quoteReq `json:"quote"`
|
||||
// entity shares something else in the app — a post — as a card. Only the
|
||||
// reference; the BFF resolves the contents and re-checks visibility.
|
||||
Entity *entityReq `json:"entity"`
|
||||
ReplyToID *string `json:"reply_to_id"`
|
||||
// forward_from_id is deliberately NOT accepted yet: forwarding lands with
|
||||
// its own "can the caller see the source?" check in a later phase, and
|
||||
// accepting an unvalidated message reference in the meantime would let a
|
||||
@@ -221,12 +226,17 @@ func (h *ChatHandler) Send(w http.ResponseWriter, r *http.Request) {
|
||||
Path: req.Quote.Path, Title: req.Quote.Title, Text: req.Quote.Text,
|
||||
}
|
||||
}
|
||||
var entity *service.EntityAttachment
|
||||
if req.Entity != nil {
|
||||
entity = &service.EntityAttachment{Type: req.Entity.Type, ID: req.Entity.ID}
|
||||
}
|
||||
msg, err := h.svc.Send(r.Context(), userID, convID, service.SendRequest{
|
||||
Body: req.Body,
|
||||
ClientMsgID: req.ClientMsgID,
|
||||
ReplyToID: req.ReplyToID,
|
||||
PreviewURL: req.PreviewURL,
|
||||
Quote: quote,
|
||||
Entity: entity,
|
||||
Attachments: media,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -566,6 +576,11 @@ func (h *ChatHandler) UpdateGroup(w http.ResponseWriter, r *http.Request) {
|
||||
response.NoContent(w)
|
||||
}
|
||||
|
||||
type entityReq struct {
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type quoteReq struct {
|
||||
Path string `json:"path"`
|
||||
Title string `json:"title"`
|
||||
|
||||
Reference in New Issue
Block a user