playNotificationSound method

  1. @override
dynamic playNotificationSound(
  1. BaseMessage message
)
override

Implementation

@override
playNotificationSound(BaseMessage message) {
  //Write all conditions here to stop sound
  if (message.type == MessageTypeConstants.custom &&
      (message.metadata?[UpdateSettingsConstant.incrementUnreadCount] !=
          true)) {
    return;
  } //not playing sound in case message type is custom and increment counter is not true

  ///checking if [CometChatConversations] is at the top of the navigation stack
  if (context != null && ModalRoute.of(context!)!.isCurrent) {
    //reset active conversation
    if (activeConversation != null) {
      activeConversation = null;
    }
  }
  if (activeConversation == null) {
    //if no message list is open
    CometChatUIKit.soundManager.play(
        sound: Sound.incomingMessageFromOther,
        customSound: customSoundForMessages);
  } else {
    if (activeConversation != message.conversationId) {
      //if open message list has different conversation id then message received conversation id
      CometChatUIKit.soundManager.play(
          sound: Sound.incomingMessage, customSound: customSoundForMessages);
    }
  }
}