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

Method CreateCommentWrite

internal/appstore/comments.go:53–85  ·  view source on GitHub ↗

CreateCommentWrite is CreateComment with the item and actor display. An empty Author is filled with the actor's display name, read in the transaction.

(ctx context.Context, spec store.FenceSpec, itemID string, in AppCommentCreate, actor store.FencedActor)

Source from the content-addressed store, hash-verified

51// empty Author is filled with the actor's display name, read in the
52// transaction.
53func (a *Store) CreateCommentWrite(ctx context.Context, spec store.FenceSpec, itemID string, in AppCommentCreate, actor store.FencedActor) (*CommentWrite, error) {
54 if err := refuseBlankBody(in.Body); err != nil {
55 return nil, err
56 }
57 ftx, err := a.s.BeginFenced(ctx, spec)
58 if err != nil {
59 return nil, err
60 }
61 defer func() { _ = ftx.Rollback() }()
62
63 who, err := ftx.ActorDisplay(actor)
64 if err != nil {
65 return nil, err
66 }
67 author := in.Author
68 if author == "" {
69 author = who
70 }
71 c, err := ftx.CreateComment(store.FencedCommentCreate{
72 ItemID: itemID, ParentID: in.ParentID, Body: in.Body, Author: author, Actor: actor,
73 })
74 if err != nil {
75 return nil, err
76 }
77 item, err := ftx.Item(itemID)
78 if err != nil {
79 return nil, err
80 }
81 if err := ftx.Commit(); err != nil {
82 return nil, err
83 }
84 return &CommentWrite{Comment: c, Item: item, ActorDisplay: who}, nil
85}
86
87// UpdateComment replaces the body of a comment this install wrote as this
88// actor, addressed through its item, in one FencedTx.

Callers 2

CreateCommentMethod · 0.95
appCreateCommentMethod · 0.80

Calls 7

refuseBlankBodyFunction · 0.85
BeginFencedMethod · 0.80
RollbackMethod · 0.80
ActorDisplayMethod · 0.80
ItemMethod · 0.80
CreateCommentMethod · 0.45
CommitMethod · 0.45

Tested by

no test coverage detected