me property

User me

Implementation

User get me {
  if (_me == null) {
    throw StateError('Set the me property before using the Session object');
  } else {
    return _me!;
  }
}
void me=(User user)

Implementation

set me(User user) {
  if (_me != null) {
    throw StateError(
        'The me property has already been set for the Session object');
  } else {
    _me = user;

    // If the WebView has loaded the page, but didn't initialize the session because of
    // the missing `me` property, now is the time to initialize the session.
    if ((_webViewController != null) && (!_completer.isCompleted)) {
      _execute('const me = new Talk.User(${me.getJsonString()});');
      createSession(
        execute: _execute,
        session: this,
        variableName: 'me',
      );

      if (onMessage != null) {
        _execute(
            'session.onMessage((event) => window.flutter_inappwebview.callHandler("JSCOnMessage", JSON.stringify(event)));');
      }

      if ((unreads != null) && (unreads!.onChange != null)) {
        _execute(
            'session.unreads.onChange((event) => window.flutter_inappwebview.callHandler("JSCOnUnreadsChange", JSON.stringify(event)));');
      }

      if (enablePushNotifications != null) {
        _setOrUnsetPushRegistration(enablePushNotifications!);
      }

      _execute('const conversations = {};');

      // Execute any pending instructions
      for (var statement in _pending) {
        final controller = _webViewController!;

        if (kDebugMode) {
          print('📗 session.me _pending: $statement');
        }

        controller.evaluateJavascript(source: statement);
      }

      _completer.complete();
    }
  }
}