(commentable Commentable, opts *CommentableOptions)
| 361 | } |
| 362 | |
| 363 | func deleteComment(commentable Commentable, opts *CommentableOptions) error { |
| 364 | comments := commentable.CurrentUserComments() |
| 365 | if len(comments) == 0 { |
| 366 | return errNoUserComments |
| 367 | } |
| 368 | |
| 369 | lastComment := comments[len(comments)-1] |
| 370 | |
| 371 | cs := opts.IO.ColorScheme() |
| 372 | |
| 373 | if opts.Interactive && !opts.DeleteLastConfirmed { |
| 374 | // This is not an ideal way of truncating a random string that may |
| 375 | // contain emojis or other kind of wide chars. |
| 376 | truncated := lastComment.Body |
| 377 | if len(lastComment.Body) > 40 { |
| 378 | truncated = lastComment.Body[:40] + "..." |
| 379 | } |
| 380 | |
| 381 | fmt.Fprintf(opts.IO.Out, "%s Deleted comments cannot be recovered.\n", cs.WarningIcon()) |
| 382 | ok, err := opts.ConfirmDeleteLastComment(truncated) |
| 383 | if err != nil { |
| 384 | return err |
| 385 | } |
| 386 | if !ok { |
| 387 | return errDeleteNotConfirmed |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | httpClient, err := opts.HttpClient() |
| 392 | if err != nil { |
| 393 | return err |
| 394 | } |
| 395 | |
| 396 | apiClient := api.NewClientFromHTTP(httpClient) |
| 397 | params := api.CommentDeleteInput{CommentId: lastComment.Identifier()} |
| 398 | deletionErr := api.CommentDelete(apiClient, opts.Host, params) |
| 399 | if deletionErr != nil { |
| 400 | return deletionErr |
| 401 | } |
| 402 | |
| 403 | if !opts.Quiet { |
| 404 | fmt.Fprintln(opts.IO.ErrOut, "Comment deleted") |
| 405 | } |
| 406 | |
| 407 | return nil |
| 408 | } |
| 409 | |
| 410 | func CommentableConfirmSubmitSurvey(p Prompt) func() (bool, error) { |
| 411 | return func() (bool, error) { |
no test coverage detected