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)
| 51 | // empty Author is filled with the actor's display name, read in the |
| 52 | // transaction. |
| 53 | func (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. |
no test coverage detected