onMessagesRead delegate not getting called

After reading message from other users using CometChat.markAsRead() method. onMessagesRead not getting called but onMessagesDelivered delegate is called all the time.

Please verify this.

@pushpsen.airekar please verify this/

Hello @Pawan_Ramteke,

Can you share the code snippet of how you’re marking the messages as read?

Also to mark the message, please follow the below guidelines.

  1. CometChat.markAsRead’ the method requires only last message Id and it will mark all the above messages as read. Please use the below code snippet to mark the messages while fetching.

messageRequest?.fetchPrevious(onSuccess: { (fetchedMessages) in
guard let messages = fetchedMessages else{
return
}
guard let lastMessage = messages.last else {
return
}
CometChat.markAsRead(messageId: lastMessage.id, receiverId: self.receiver!, receiverType: .user)
self.messages.append(contentsOf: messages)
DispatchQueue.main.async {
self.tableView.reloadData()
}
}, onError: { (error) in
print("error while fetching messages for user: ")
})

  1. Also, make sure you’re marking the messages as read for real time message i.e messages received in onTextMessageReceived(), onMediaMessageReceived()
1 Like

here is my code snippet:

func applicationdidReceiveNewMessage(message: BaseMessage) {
    
    let senderUID = (appEntity is User) ? (appEntity as! User).uid : (appEntity as! Group).guid
    if message.receiverType == .user {
        if message.senderUid == senderUID {
            addMessageToList(message: message)
        }
        else {
            updateUnreadMsgCountToNavigation()
        }
    }
    else {
        if message.receiverUid == senderUID {
            addMessageToList(message: message)
        }
        else {
            updateUnreadMsgCountToNavigation()
        }
    }
    
    NotificationCenter.default.post(name:NSNotification.Name(rawValue: REFRESH_CHAT_NOTIFICATION), object: nil)
}

func addMessageToList(message:BaseMessage) {
    DispatchQueue.main.async {
        self.arrMsgsList.add(message)
        self.tblViewList.beginUpdates()
        self.tblViewList.insertRows(at: [IndexPath(row: self.arrMsgsList.count > 0 ? self.arrMsgsList.count - 1 : 0, section: 0)], with: .none)
        self.tblViewList.endUpdates()
        self.tblViewList.layoutIfNeeded()
        self.scrollToBottom(animated: true)
    }
            
    CometChat.markAsRead(messageId: message.id, receiverId: message.receiverUid, receiverType: message.receiverType)
    DispatchQueue.main.async {
        CCCoreDataHandler.updateReadAtToMessage(messageId: message.id, readAt: Int(Date().timeIntervalSince1970))
    }
}

@pushpsen.airekar on runtime its not working… oneMessagesRead not called so that sender read status not updating.

Hi @Pawan_Ramteke,

I have checked the issue related to marking of messages and it is running as expected. I have checked this in our iOS Swift Chat App where superhero1 sent a message to superhero2 and superhero2 marked that message read in onTextMessageReceived event.

Incase if you want to refer our Swift Chat App, here is the link:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.