postComment method

Future<CommentResponse> postComment({
  1. required String comment,
  2. required bool spoiler,
  3. Movie? movie,
  4. Show? show,
  5. Season? season,
  6. Episode? episode,
  7. TraktList? list,
  8. CommentSharing? sharing,
})

Add a new comment to a movie, show, season, episode, or list. Make sure to allow and encourage spoilers to be indicated in your app and follow the rules listed above.

The sharing object is optional and will apply the user's settings if not sent. If sharing is sent, each key will override the user's setting for that social network. Send true to post or false to not post on the indicated social network. You can see which social networks a user has connected with the /users/settings method.

comment - Text for the comment. spoiler - Is this a spoiler? sharing - Control sharing to any connected social networks. movie, show, season, episode, list - The item to comment on.

🔒 OAuth Required 😁 Emojis

Implementation

Future<CommentResponse> postComment(
    {required String comment,
    required bool spoiler,
    Movie? movie,
    Show? show,
    Season? season,
    Episode? episode,
    TraktList? list,
    CommentSharing? sharing}) async {
  assert(
      (movie != null ||
          show != null ||
          season != null ||
          episode != null ||
          list != null),
      "A movie, show, season, episode, or list must be provided");
  final Map<String, dynamic> body = {"comment": comment, "spoiler": spoiler};

  if (movie != null) {
    body["movie"] = movie.metadata;
  }

  if (show != null) {
    body["show"] = show.metadata;
  }

  if (season != null) {
    body["season"] = season.metadata;
  }

  if (episode != null) {
    body["episode"] = episode.metadata;
  }

  if (list != null) {
    body["list"] = {
      "ids": list.ids,
    };
  }

  if (sharing != null) {
    body["sharing"] = sharing.toJson();
  }

  return await _manager._authenticatedPost<CommentResponse>("comments",
      body: jsonEncode(body));
}