processEvent static method

void processEvent(
  1. PubSub pubSub,
  2. Map<String, dynamic> payload,
  3. ChaCha20Key? key
)

Implementation

static void processEvent(
    PubSub pubSub, Map<String, dynamic> payload, ChaCha20Key? key) {
  // Prevent handling duplicate events using the UUID.
  if (emittedEventForUUID.containsKey(payload["uuid"])) {
    return;
  }
  emittedEventForUUID[payload["uuid"]] = true;

  LocalityEvent localityEvent;

  // If a key is available, decrypt the payload.
  if (key != null) {
    localityEvent = LocalityEvent(
        uuid: payload["uuid"],
        event: payload["event"],
        channel: pubSub.getTopic(),
        payload: PayloadCipher.getDecodedPayload(payload["payload"],
            Nonce.fromString(payload["uuid"]), ChaCha20(key)),
        timestamp: payload["timestamp"],
        servertime: payload["servertime"]);
  } else {
    localityEvent = LocalityEvent(
        uuid: payload["uuid"],
        event: payload["event"],
        channel: pubSub.getTopic(),
        payload: jsonDecode(payload["payload"]),
        timestamp: payload["timestamp"],
        servertime: payload['servertime']);
  }

  // Notify the PubSub instance of the new event.
  pubSub.onReceive(localityEvent);

  // Cache the message if caching is enabled.
  if (cache != null) {
    cache!.setChannelFetchTime(pubSub.getTopic(), payload["servertime"]);
    cache!.upsertMessage(localityEvent);
  }
}