Event.fromJson constructor

Event.fromJson(
  1. Map<String, dynamic> jsonPayload,
  2. Room room
)

Get a State event from a table row or from the event stream.

Implementation

factory Event.fromJson(
  Map<String, dynamic> jsonPayload,
  Room room,
) {
  final content = Event.getMapFromPayload(jsonPayload['content']);
  final unsigned = Event.getMapFromPayload(jsonPayload['unsigned']);
  final prevContent = Event.getMapFromPayload(jsonPayload['prev_content']);
  final originalSource =
      Event.getMapFromPayload(jsonPayload['original_source']);
  return Event(
      status: eventStatusFromInt(jsonPayload['status'] ??
          unsigned[messageSendingStatusKey] ??
          defaultStatus.intValue),
      stateKey: jsonPayload['state_key'],
      prevContent: prevContent,
      content: content,
      type: jsonPayload['type'],
      eventId: jsonPayload['event_id'] ?? '',
      senderId: jsonPayload['sender'],
      originServerTs: jsonPayload['origin_server_ts'] != null
          ? DateTime.fromMillisecondsSinceEpoch(
              jsonPayload['origin_server_ts'])
          : DateTime.now(),
      unsigned: unsigned,
      room: room,
      originalSource:
          originalSource.isEmpty ? null : SDNEvent.fromJson(originalSource));
}