toJson method

Map<String, dynamic> toJson()

Returns a JSON map for the request body.

Implementation

Map<String, dynamic> toJson() {
  final visibilityString = switch (visibility) {
    MastodonVisibility.public => 'public',
    MastodonVisibility.unlisted => 'unlisted',
    MastodonVisibility.private => 'private',
    MastodonVisibility.direct => 'direct',
  };

  final map = <String, dynamic>{
    'visibility': visibilityString,
    'sensitive': sensitive,
  };

  if (status != null) {
    map['status'] = status;
  }
  if (mediaIds != null) {
    map['media_ids'] = mediaIds;
  }
  if (inReplyToId != null) {
    map['in_reply_to_id'] = inReplyToId;
  }
  if (spoilerText != null) {
    map['spoiler_text'] = spoilerText;
  }
  if (poll != null) {
    map['poll'] = <String, dynamic>{
      'options': poll!.options,
      'expires_in': poll!.expiresIn,
      'multiple': poll!.multiple,
      'hide_totals': poll!.hideTotals,
    };
  }
  if (quotedStatusId != null) {
    map['quoted_status_id'] = quotedStatusId;
  }
  if (quoteApprovalPolicy != null) {
    map['quote_approval_policy'] = quoteApprovalPolicy;
  }
  if (language != null) {
    map['language'] = language;
  }
  if (scheduledAt != null) {
    map['scheduled_at'] = scheduledAt;
  }

  return map;
}