MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / appCreateComment

Method appCreateComment

internal/server/app_api_write.go:242–289  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

240}
241
242func (s *Server) appCreateComment(w http.ResponseWriter, r *http.Request) {
243 ac := appContextFrom(r)
244 item, _, ok := s.appVisibleItem(w, r)
245 if !ok {
246 return
247 }
248 if !s.requireEditPermission(w, r, ac.WorkspaceID, item.ID, item.CollectionID) {
249 return
250 }
251 var in AppCommentCreateRequest
252 if err := decodeAppJSON(r, &in); err != nil {
253 writeError(w, http.StatusBadRequest, "bad_request", err.Error())
254 return
255 }
256 if !s.appReadmitBeforeWrite(w, r, item.ID, item.CollectionID) {
257 return
258 }
259 as, err := s.appStore()
260 if err != nil {
261 writeInternalError(w, err)
262 return
263 }
264 // The author is server-set: the app's bot display name,
265 // read in the write's transaction (Author left empty). What the write
266 // publishes is the item as that transaction found it: a human may have
267 // moved it to another companion since this handler's read, and a
268 // notification naming the old collection would reach that collection's
269 // watchers.
270 cw, err := as.CreateCommentWrite(r.Context(), ac.appFenceSpec(), item.ID,
271 appstore.AppCommentCreate{Body: in.Body, ParentID: in.ParentCommentID}, appActor(ac))
272 if err != nil {
273 writeAppStoreError(w, err)
274 return
275 }
276 comment, at := cw.Comment, cw.Item
277 s.publishCommentEvent(sseCommentCreated, ac.WorkspaceID, at.ID, comment.ID, at.Title, at.CollectionSlug, appActorKind(ac), "app")
278 s.publishWatchNotification(watchevents.Notification{
279 WorkspaceID: ac.WorkspaceID,
280 ItemID: at.ID,
281 CollectionID: at.CollectionID,
282 ItemRef: at.Ref,
283 Kind: watchevents.KindComment,
284 Actor: appActorKind(ac),
285 ActorName: cw.ActorDisplay,
286 Summary: truncateForSummary(comment.Body, 120),
287 })
288 writeAppJSON(w, http.StatusCreated, appCommentDTO(comment, appCommentAuthorKind(ac)))
289}
290
291// appCommentOnItem resolves the comment for a PATCH or DELETE: the item
292// first, then the comment, which must be on THAT item, else the same 404 a

Callers

nothing calls this directly

Calls 15

appVisibleItemMethod · 0.95
requireEditPermissionMethod · 0.95
appReadmitBeforeWriteMethod · 0.95
appStoreMethod · 0.95
publishCommentEventMethod · 0.95
appContextFromFunction · 0.85
decodeAppJSONFunction · 0.85
writeErrorFunction · 0.85
writeInternalErrorFunction · 0.85
appActorFunction · 0.85
writeAppStoreErrorFunction · 0.85

Tested by

no test coverage detected