init method

dynamic init(
  1. BuildContext context, {
  2. String? jid,
  3. bool isUser = false,
  4. bool isFromStarred = false,
  5. String? messageId,
  6. required bool showChatDeliveryIndicator,
})

Implementation

init(
  BuildContext context, {
  String? jid,
  bool isUser = false,
  bool isFromStarred = false,
  String? messageId,
  required bool showChatDeliveryIndicator,
}) async {
  getAvailableFeatures();
  this.context = context;
  this.showChatDeliveryIndicator = showChatDeliveryIndicator;
  var userJid = SessionManagement.getChatJid().checkNull();
  if (jid != null) {
    nJid = jid;
    // debugPrint("parameter :$jid");
    if (nJid != null) {
      userJid = jid;
    }
    if (isFromStarred && messageId != null) {
      starredChatMessageId = messageId;
    }
  }

  // debugPrint('userJid $userJid');
  //make unreadMessageTypeMessageId
  if (Platform.isAndroid) {
    unreadMessageTypeMessageId = "M$userJid";
  } else if (Platform.isIOS) {
    unreadMessageTypeMessageId = "M_${getMobileNumberFromJid(userJid)}";
  }
  getProfileDetails(userJid).then((value) {
    if (value.jid != null) {
      SessionManagement.setChatJid(Constants.emptyString);
      profile_(value);
      ready();
      checkAdminBlocked();
    }
  }).catchError((o) {
    debugPrint('error $o');
  });

  setAudioPath();

  filteredPosition.bindStream(filteredPosition.stream);
  ever(filteredPosition, (callback) {
    lastPosition(callback.length);
    //chatList.refresh();
  });

  // chatList.bindStream(chatList.stream);
  // ever(chatList, (callback) {});
  isUserTyping.bindStream(isUserTyping.stream);

  ///Commenting this, bcz this executed only when value is changed to true or false. if started typing value changed to true.
  ///Then after some interval, if we type again the value remains true so this is not calling
  ///Changing to below messageController.addListener()
  /*ever(isUserTyping, (callback) {
    mirrorFlyLog("typing ", callback.toString());
    if (callback) {
      sendUserTypingStatus();
      DeBouncer(milliseconds: 2100).run(() {
        sendUserTypingGoneStatus();
      });
    } else {
      sendUserTypingGoneStatus();
    }
  });*/
  messageController.addListener(() {
    /*mirrorFlyLog("typing", "typing..");
    sendUserTypingStatus();
    debugPrint('User is typing');
    deBouncer.cancel();
    deBouncer.run(() {
      debugPrint("DeBouncer");
      sendUserTypingGoneStatus();
    });*/
  });
}