sendPush method

Map<String, Object?> sendPush(
  1. String endUserId,
  2. KletsoAppNotification n
)

Builds the data map a push provider would deliver for n while the app is in the background: {'kletso': '<envelope json>'}. Hosts feed it to KletsoClient.handlePushPayload. Requires a registered push token. Nothing is sent over the socket, so the only way the app learns about it is through the push.

Implementation

Map<String, Object?> sendPush(String endUserId, KletsoAppNotification n) {
  if (!_pushTokens.containsKey(endUserId)) {
    throw const KletsoStateException('no push token registered for user');
  }
  final target = _conversationFor(endUserId);
  final envelope = KletsoEventEnvelope(
    id: _id('evt'),
    seq: target.seq == 0 ? 1 : target.seq,
    type: KletsoEventTypes.appNotify,
    ts: _now(),
    conversationId: target.id,
    data: n.toJson(),
  );
  _pushesSent++;
  return <String, Object?>{
    'kletso': jsonEncode(envelope.toJson()),
    'title': n.title,
    if (n.body != null) 'body': n.body,
  };
}