I am trying to implement the ’sent’ status using JSQMessagesViewController
I have a message queue and a Chat view controller. When the message queue sends a particular message successfully I want to be able to reload a particular cell in the ChatViewController.
How do I do this kind of communication between the message queue and the ChatVC?
Here is what I have been able to do -
This is my message queue -
var unsentMessages = [String]() {
didSet {
// Check if a new value is being added or removed
// If a new value is added then the oldValue will anve less elements than the original unsentMessages list
if oldValue.count < unsentMessages.count {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
newValue in
let messageID = unsentMessages.last
let realm = try! Realm()
for i in 1...10 {
if channel.subscribed {
let message = realm.objectForPrimaryKey(Message.self, key: messageID)
channel.trigger("client-message", data: (message?.pusherMessage())!)
unsentMessages.popLast()
break
} else {
let time = 2 << UInt(i)
sleep(UInt32(time))
}
}
})
Now what i need to do is call the following code - self.collectionView.reloadItemsAtIndexPaths()
from somewhere inside the ChatViewController. This is automatically reload the message cell and update the status.
How can I invoke code inside the ChatViewController and pass data (the messageID) from the message queue.
Why don't you just call reload()
on your chatVC once the message sent is successful.