subscribe method

Implementation

Future<Stream<List<NotificationObject>>?> subscribe() async {
  assert(_partition.length != 0);

  // Subscribe into manager
  NotificationManager manager = NotificationManager.instance(_channel)!;
  manager.addCallHandler(uniqueListenerId, this);

  var sorted = _sorted;
  Map<dynamic, dynamic> map =
      await _channel.invokeMethod(Action.subscribe.name, <String, dynamic>{
    'query': query,
    'limit': _limit,
    'listenId': uniqueListenerId,
    'sorted': sorted == null ? null : sorted.sortArray(),
    'type': T.toString(),
    'identity': _syncUser.identity,
    'appId': _appId,
    'partition': _partition,
  });
  if (map["error"] != null) {
    throw Exception("fetch list finished with exception ${map["error"]}");
  }

  _streamController = new StreamController<List<NotificationObject>>();
  return _streamController?.stream;
}