fromJson static method

Chat? fromJson(
  1. Map<String, dynamic>? json
)

Implementation

static Chat? fromJson(Map<String, dynamic>? json) {
  if (json == null) {
    return null;
  }

  return Chat(
    id: (json['id'] as int?) ?? 0,
    type: ChatType.fromJson(tdMapFromJson(json['type'])),
    title: (json['title'] as String?) ?? '',
    photo: ChatPhotoInfo.fromJson(tdMapFromJson(json['photo'])),
    accentColorId: (json['accent_color_id'] as int?) ?? 0,
    backgroundCustomEmojiId:
        int.tryParse(
          (json['background_custom_emoji_id'] as dynamic)?.toString() ?? '',
        ) ??
        0,
    upgradedGiftColors: UpgradedGiftColors.fromJson(
      tdMapFromJson(json['upgraded_gift_colors']),
    ),
    profileAccentColorId: (json['profile_accent_color_id'] as int?) ?? 0,
    profileBackgroundCustomEmojiId:
        int.tryParse(
          (json['profile_background_custom_emoji_id'] as dynamic)
                  ?.toString() ??
              '',
        ) ??
        0,
    permissions: ChatPermissions.fromJson(tdMapFromJson(json['permissions'])),
    lastMessage: Message.fromJson(tdMapFromJson(json['last_message'])),
    positions: List<ChatPosition>.from(
      tdListFromJson(json['positions'])
          .map((item) => ChatPosition.fromJson(tdMapFromJson(item)))
          .whereType<ChatPosition>(),
    ),
    chatLists: List<ChatList>.from(
      tdListFromJson(json['chat_lists'])
          .map((item) => ChatList.fromJson(tdMapFromJson(item)))
          .whereType<ChatList>(),
    ),
    messageSenderId: MessageSender.fromJson(
      tdMapFromJson(json['message_sender_id']),
    ),
    blockList: BlockList.fromJson(tdMapFromJson(json['block_list'])),
    hasProtectedContent: (json['has_protected_content'] as bool?) ?? false,
    isTranslatable: (json['is_translatable'] as bool?) ?? false,
    isMarkedAsUnread: (json['is_marked_as_unread'] as bool?) ?? false,
    viewAsTopics: (json['view_as_topics'] as bool?) ?? false,
    hasScheduledMessages: (json['has_scheduled_messages'] as bool?) ?? false,
    canBeDeletedOnlyForSelf:
        (json['can_be_deleted_only_for_self'] as bool?) ?? false,
    canBeDeletedForAllUsers:
        (json['can_be_deleted_for_all_users'] as bool?) ?? false,
    canBeReported: (json['can_be_reported'] as bool?) ?? false,
    defaultDisableNotification:
        (json['default_disable_notification'] as bool?) ?? false,
    unreadCount: (json['unread_count'] as int?) ?? 0,
    lastReadInboxMessageId: (json['last_read_inbox_message_id'] as int?) ?? 0,
    lastReadOutboxMessageId:
        (json['last_read_outbox_message_id'] as int?) ?? 0,
    unreadMentionCount: (json['unread_mention_count'] as int?) ?? 0,
    unreadReactionCount: (json['unread_reaction_count'] as int?) ?? 0,
    unreadPollVoteCount: (json['unread_poll_vote_count'] as int?) ?? 0,
    notificationSettings: ChatNotificationSettings.fromJson(
      tdMapFromJson(json['notification_settings']),
    ),
    availableReactions: ChatAvailableReactions.fromJson(
      tdMapFromJson(json['available_reactions']),
    ),
    messageAutoDeleteTime: (json['message_auto_delete_time'] as int?) ?? 0,
    emojiStatus: EmojiStatus.fromJson(tdMapFromJson(json['emoji_status'])),
    background: ChatBackground.fromJson(tdMapFromJson(json['background'])),
    theme: ChatTheme.fromJson(tdMapFromJson(json['theme'])),
    actionBar: ChatActionBar.fromJson(tdMapFromJson(json['action_bar'])),
    businessBotManageBar: BusinessBotManageBar.fromJson(
      tdMapFromJson(json['business_bot_manage_bar']),
    ),
    videoChat: VideoChat.fromJson(tdMapFromJson(json['video_chat'])),
    pendingJoinRequests: ChatJoinRequestsInfo.fromJson(
      tdMapFromJson(json['pending_join_requests']),
    ),
    replyMarkupMessageId: (json['reply_markup_message_id'] as int?) ?? 0,
    draftMessage: DraftMessage.fromJson(tdMapFromJson(json['draft_message'])),
    clientData: (json['client_data'] as String?) ?? '',
  );
}