MessageOrigin.fromJson constructor

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

Creates a new MessageOrigin instance from a JSON object.

Implementation

factory MessageOrigin.fromJson(Map<String, dynamic> json) {
  switch (json['type']) {
    case 'user':
      return MessageOriginUser.fromJson(json);
    case 'hidden_user':
      return MessageOriginHiddenUser.fromJson(json);
    case 'chat':
      return MessageOriginChat.fromJson(json);
    case 'channel':
      return MessageOriginChannel.fromJson(json);
    default:
      throw TeleverseException(
        "Unknown message origin type",
        description:
            "The given JSON object does not match any MessageOrigin type.",
        type: TeleverseExceptionType.invalidParameter,
      );
  }
}