getEventById method

Future<Event?> getEventById(
  1. String eventID
)

Searches for the event in the local cache and then on the server if not found. Returns null if not found anywhere.

Implementation

Future<Event?> getEventById(String eventID) async {
  try {
    final dbEvent = await client.database?.getEventById(eventID, this);
    if (dbEvent != null) return dbEvent;
    final sdnEvent = await client.getOneRoomEvent(id, eventID);
    final event = Event.fromSDNEvent(sdnEvent, this);
    if (event.type == EventTypes.Encrypted && client.encryptionEnabled) {
      // attempt decryption
      return await client.encryption?.decryptRoomEvent(
        id,
        event,
      );
    }
    return event;
  } on SDNException catch (err) {
    if (err.errcode == 'M_NOT_FOUND') {
      return null;
    }
    rethrow;
  }
}