I am developing an chat base application with the help of QuickBlox.
There is an Api that returns chat dialogs where the last sent message and unread-messages count comes.
My problem is to mark messages as read. For this i got the working code like
[QBChat markMessagesAsRead:arrMessages dialogID:dialogId delegate:self]; // arrMessages is the array of message ids
It works well but sometime what happens some of message gets skipped and it always comes as unread messages in QBChatDialog
So My question is what should i do to mark all messages of it as read.
Or
How can i get those particular skipped messages that are unread. As it call the api to get messages it give only last one not that particular skipped.
You can mark all messages as read just passing nil as the array parameter
[QBChat markMessagesAsRead:nil dialogID:dialogId delegate:self];
In that case ALL your messages should be marked as read
Related
I want to display next to a chat channel the number of messages a channel has that have been unconsumed or unread (I assume this is what unconsumed means?)
Currently I send messages to a channel that two users are subscribed to , a private chat. Then before opening up the chat window I check the channel for unconsumed messages, but it always say 0 messages even if I call setNoMessagesConsumedWithCompletion.
I am using the Swift API...What do I need to do to find out how many messages in my channel have not been read yet? At what point do they become read? (when the user opens up a chat channel and requests to getLastWithCount?)
I read in the docs you have to set something called the consumption horizon to get unconsumed message, but I don't know how you do that in SWIFT API https://www.twilio.com/docs/chat/consumption-horizon also this was for Javascript API so perhaps it is easier with Swift Api?
I figured out the solution. As per the documentation you need to update the last consumed message index. So for example if the user has a chat window open you need to record for that user (or instance of the Chat Client) what was the last message they saw before they close their chat. I am storing all the messages in a message array and update the last consumed message index with the length of the array of messages:
generalChannel?.messages?.setLastConsumedMessageIndex(NSNumber.init(value: self.messages.count), completion: { (result, count) in
if !result.isSuccessful() {
print(result.error.debugDescription)
}
})
Then if you send messages to that channel when the user is not in the channel these will be recorded as unconsumed, you can get the number by calling:
channel.getUnconsumedMessagesCount(completion: { (results, numberUnconsumed) in
print(numberUnconsumed)
})
When didReceiveStatus is called after subscribing to a channel, We are not able to retrieve the channel(s) that was just subscribed.
PNSubscribeStatus.data.subscribedChannel or PNSubscribeStatus.data.actualChannel are always null and PNSubscribeStatus.subscribedChannels gives all currently subscribed channels and not the ones that triggered the didReceiveStatus callback.
What are we doing wrong here ?
In SDK 4.0, didReceiveStatus returns a PNStatus, which according to the class documentation doesn't contain that extra information unless there's an error condition. For our application, we use that handler to monitor connection status to the PubNub server.
PubNub Message Received Channel Name in iOS
You should be able to get the channel that you received the message on but getting it depends on whether you are subscribed to the channel or to a channel group that contains the channel. This is sample code from the PubNub Objective-C for iOS SDK subscribe API Reference:
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
// Handle new message stored in message.data.message
if (message.data.actualChannel) {
// Message has been received on channel group stored in
// message.data.subscribedChannel
}
else {
// Message has been received on channel stored in
// message.data.subscribedChannel
}
NSLog(#"Received message: %# on channel %# at %#", message.data.message,
message.data.subscribedChannel, message.data.timetoken);
}
If you need other channels that the client is subscribed to, you can call the where-now API.
If you need to be more dynamic about what the reply-to channel should be, then just include that channel name in the message when it is published, assuming the publisher has prior knowledge about which channel this is. Or you can do a just in time lookup on your server as to which channel to reply to.
Here is PubNub support answer on this :
Actually status.data.subscribedChannel and status.data.actualChannel
dedicated to presence events and messages receiving callbacks where
information about sources of event is important.
In -client:didReceiveStatus: client doesn’t give information about
particular channel on which client has been subscribed. If client will
start track this information, there is no guarantee what it will
return expected value (as developer expect some channels to be there).
In previous version (3.x) all this information has been tracked, but
because it can be modified at any moment – result sometimes was
unpredictable.
Subscribe can be done in sequence of methods (one after another) like:
subscribe A1, subscribe C1, subscribe B1 and B2, unsubscribe C1 and B1
– this as result will end up with single call of
-client:didReceiveStatus: with resulting set of channels.
It always best practice just to check whether your channels is in
s_tatus.subscribedChannels_.
My comments:
The point of having asynchronous process is exactly not to think this as sequence of methods... We can not have the guaranty that subscriptions are done in the exact same order as the subscription request unless we block other subscription request until the previous one is done.
I had integrated QuickBlox SDK in my chat application.
I am Bit frustrated with an issue of unread messages or say offline messages.
In offline messages QuickBlox do send the push notification. But some where it gets skipped to store at app side.
Like say if i got notification of 25 messages and i click on one of message from notification and app gets open but how can i get those 24 unread(Offline) messages.
There are few methods given by QuickBlox to retrieve messages.
For Group
[[QBChat instance] createOrJoinRoomWithJID:room.JID membersOnly:YES persistent:YES historyAttribute:#{#"maxstanzas": count}]; // Where count is the unread messages count which i get from the `QBChatDialog`, And this code gives me unread messages from the `XMPP` server.
Private and Group both from QuickBlox
NSMutableDictionary *extendedRequest = [NSMutableDictionary new];
extendedRequest[#"limit"] = #(limit);
if (offset) {
extendedRequest[#"skip"] = #([offset integerValue]);
}
extendedRequest[#"sort_desc"] = #"date_sent";
[QBChat messagesWithDialogID:dialogID extendedRequest:extendedRequest delegate:self];
Both of above method return me the messages from last. But some of messages in between gets skipped. So how can i get those perticular messages.
By short and simple i just want the messages that are unread without passing its count as count gives the messages that are from last.
So is there any method that QuickBlox have to retrieve only unread message.
At this moment you can save a datetime where your application has been closed( or moved to background ). Then when you receive push, you can load dialogs from previously saved datetime.
I'm having some trouble with Quickblox chat. Whenever two users are both logged in and both joined in the same chat room, messages that are sent between the two users are not marked as read. When I back out of the room to the dialogs list and the dialogs are refreshed, it says that there are unread messages even though I was in the room and I was receiving the messages live.
Is there a certain call that I must make to let it be known that the received messages should be marked as read? I am developing in iOS.
Thanks.
User has to read message to mark it as read
NSString *dialogID = #"53d10eede4b02f496c21549f";
NSArray *mesagesIDs = #[#"53aabe15e4b077ddd43e7fd3", #"53aabe15e4b077ddd43e7fd7"];
[QBChat markMessagesAsRead:mesagesIDs dialogID:dialogID delegate:self];
In iOS you can use:
QBRequest.markMessagesAsRead(Set<String>?, dialogID: String, successBlock:
{
(QBResponse) in code
})
{
(QBResponse) in code
}
I have an IMAP connection to fetch emails using Mule. I'm running into an issue.
Here are my 2 simple requirements:
I want to fetch emails in reverse order. (latest first)
Ignore SEEN messages but don't delete them.
I was looking at the code that mule (3.3.1) uses:
org.mule.transport.email.RetrieveMessageReceiver.poll().
The code seems to be fetching messages from message 1.
348: Message[] messages = folder.getMessages(1, batchSize);
The messages fetched here are processed in a loop in :
org.mule.transport.email.RetrieveMessageReceiver.messagesAdded(MessageCountEvent)
142: if (!messages[i].getFlags().contains(Flags.Flag.DELETED)
143: && !messages[i].getFlags().contains(Flags.Flag.SEEN))
What this whole logic is doing is that it is trying to read OLD unread messages. The code comes back to line 348 and executes
folder.getMessages(1, batchSize);
again, and gets the same messages and it keeps on waiting. How can i change the order of fetch.
FYI: Using MS Exchange for IMAP
Not sure why you say that Mule tried to read "OLD unread messages"? It actually just tries to read unread messages, ie not DELETED nor SEEN.
Anyway, theoretically the Mulesque way of sorting the messages would be to use resequencer. Unfortunately the mail message receivers do not set any of the required control properties to let Mule process the received messages as a single batch so that won't work.
So the only solution I can think of is to extend org.mule.transport.email.RetrieveMessageReceiver and register your custom version on the IMAP connector with a <service-overrides /> child element.