EXPERIMENTAL: this endpoint is experimental and is subject to change. @Summary Edit chat message @ID edit-chat-message @Security CoderSessionToken @Tags Chats @Accept json @Produce json @Param chat path string true "Chat ID" format(uuid) @Param message path int true "Message ID" @Param request body
(rw http.ResponseWriter, r *http.Request)
| 3165 | // @Router /api/experimental/chats/{chat}/messages/{message} [patch] |
| 3166 | // @Description Experimental: this endpoint is subject to change. |
| 3167 | func (api *API) patchChatMessage(rw http.ResponseWriter, r *http.Request) { |
| 3168 | ctx := r.Context() |
| 3169 | apiKey := httpmw.APIKey(r) |
| 3170 | chat := httpmw.ChatParam(r) |
| 3171 | |
| 3172 | if !api.Authorize(r, policy.ActionUpdate, chat.RBACObject()) { |
| 3173 | httpapi.ResourceNotFound(rw) |
| 3174 | return |
| 3175 | } |
| 3176 | |
| 3177 | // Only the chat owner may edit messages. See postChatMessages |
| 3178 | // for the security rationale. |
| 3179 | if apiKey.UserID != chat.OwnerID { |
| 3180 | httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{ |
| 3181 | Message: "Only the chat owner may edit messages.", |
| 3182 | }) |
| 3183 | return |
| 3184 | } |
| 3185 | |
| 3186 | if chat.Archived { |
| 3187 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 3188 | Message: "Cannot edit messages in an archived chat.", |
| 3189 | }) |
| 3190 | return |
| 3191 | } |
| 3192 | |
| 3193 | if api.chatDaemon == nil { |
| 3194 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 3195 | Message: "Chat processor is unavailable.", |
| 3196 | Detail: "Chat processor is not configured.", |
| 3197 | }) |
| 3198 | return |
| 3199 | } |
| 3200 | |
| 3201 | messageIDStr := chi.URLParam(r, "message") |
| 3202 | messageID, err := strconv.ParseInt(messageIDStr, 10, 64) |
| 3203 | if err != nil || messageID <= 0 { |
| 3204 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 3205 | Message: "Invalid chat message ID.", |
| 3206 | Detail: "Message ID must be a positive integer.", |
| 3207 | }) |
| 3208 | return |
| 3209 | } |
| 3210 | |
| 3211 | var req codersdk.EditChatMessageRequest |
| 3212 | if !httpapi.Read(ctx, rw, r, &req) { |
| 3213 | return |
| 3214 | } |
| 3215 | |
| 3216 | contentBlocks, _, fileIDs, inputError := createChatInputFromParts(ctx, api.Database, req.Content, "content") |
| 3217 | if inputError != nil { |
| 3218 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 3219 | Message: inputError.Message, |
| 3220 | Detail: inputError.Detail, |
| 3221 | }) |
| 3222 | return |
| 3223 | } |
| 3224 |
nothing calls this directly
no test coverage detected