createNotification static method

dynamic createNotification(
  1. ChatMessageModel message, {
  2. dynamic autoCancel = true,
})
  • Create notification when new chat message received
  • @parameter message Instance of ChatMessage in NotificationMessageModel

Implementation

static createNotification(ChatMessageModel message,
    {autoCancel = true}) async {
  int lastMessageTime = 0;
  var chatJid = message.chatUserJid;
  var lastMessageContent = StringBuffer();
  var notificationId = chatJid.hashCode;
  var messageId = message.messageId.hashCode;
  var topicId = message.topicId;
  var profileDetails = await getProfileDetails(chatJid);
  if (profileDetails.isMuted == true) {
    return;
  }

  if (!SessionManagement.getBool(AppConstants.enableLocalNotification)) {
    return;
  }
  // var isMessageRecalled = message.isMessageRecalled.checkNull();
  debugPrint("inside if notification");
  lastMessageContent.write(NotificationUtils.getMessageSummary(message));
  lastMessageTime = (message.messageSentTime.toString().length > 13)
      ? message.messageSentTime ~/ 1000
      : message.messageSentTime;
  await displayMessageNotification(
      notificationId,
      messageId,
      profileDetails,
      lastMessageContent.toString(),
      lastMessageTime,
      message.senderUserJid,
      autoCancel,
      topicId.checkNull());
}