fromJson static method

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

Creates a object from a json

Implementation

static ChatMember fromJson(Map<String, dynamic> json) {
  var isAdmin = json['status'] == 'administrator';
  var isCreator = json['status'] == 'creator';
  var isMember = json['status'] == 'member';
  return ChatMember(
    user: User.fromJson(json['user']!),
    status: json['status']!,
    customTitle: json['custom_title'],
    untilDate: json['until_date'],
    canBeEdited: json['can_be_edited'],
    canPostMessages: json['can_post_messages'] ?? isCreator,
    canEditMessages: json['can_edit_messages'] ?? isCreator,
    canDeleteMessages: json['can_delete_messages'] ?? isCreator,
    canRestrictMembers: json['can_restrict_members'] ?? isCreator,
    canPromoteMembers: json['can_promote_members'] ?? isCreator,
    canChangeInfo: json['can_change_info'] ?? isCreator,
    canInviteUsers: json['can_invite_users'] ?? isCreator,
    canPinMessages: json['can_pin_messages'] ?? isCreator,
    isMember: json['is_member'] ?? isCreator || isAdmin || isMember,
    canSendMessages: json['can_send_messages'] ?? isCreator,
    canSendMediaMessages: json['can_send_media_messages'] ?? isCreator,
    canSendPolls: json['can_send_polls'] ?? isCreator,
    canSendOtherMessages: json['can_send_other_messages'] ?? isCreator,
    canAddWebPagePreviews: json['can_add_web_page_previews'] ?? isCreator,
    canManageVideoChats: json['can_manage_video_chats'] ?? isCreator,
    canManageChat: json['can_manage_chat'] ?? isCreator,
    isAnonymous: json['is_anonymous'],
  );
}