How to implement one IM feature in an app offline message common analysis
In the process of developing IM functionality, one of the most basic scenarios is to receive and present messages from users. We assume that user A is the sender and that User B is the receiver (when the group chats, the client handles the information presentation like one-to-one chats).
Scenario 1:
When the client with User B client is on, B is turned on, the message is sent by the server to the client of B in real time.
Scenario 2:
When the User B client is offline and B is offline (the client for B is not connected to the IM server), all messages sent to B are saved on the server side. When B is online, all unread messages are fetched back by the client.
The second scenario, which we often call "receiving offline messages," below, describes a coding technique for receiving offline messages.
Specific implementation principle:
Generally get offline messages, because the data of offline messages can not determine the number, (generally the default number of offline messages are capped, perhaps 10 or 20, when the received offline message exceeds this number, there will be a part of the message can not be received.) Therefore, it is necessary to take a recursive approach to the acquisition of offline messages to realize the function of receiving all messages.
The specific implementation is as follows:
private void getofflinehistory () { Set<String> clientIds = new HashSet<String> (); clientids.add (User.clientid); Anim.getofflinehistory (clientids, currentclientid, page_limit, new ianimhistorycallback () { @Override public void onsuccess (List list, int count) { //processing Get offline message success if (!list.isempty ()) { AnIMMessage imMessage; for (Int i = 0; i < list.size (); i++) { immessage = (animmessage) list.get (i); // Operation of offline message data } // server also has redundant offline messages, continue to get if (count != 0) { getofflinehistory (); } // Offline Message acquisition complete, update interface else { } } } @Override public void onerror (final arrownockexception e) { &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;LOG.E ("Getofflinehistory", e.getmessage ()); //processing get offline message failure } } ); }
How to implement the IM feature series in the app article:
A common analysis of offline messages
The second fast realization of the offline message module
Three fast implementation of offline message push module
The four create a robust message sending module
The five rapid implementation of picture receiving and sending
The six fast realization of group chat advanced features
Seven fast implementation of chat list sorting module
This article from "Arrow Buckle technology Arrownock" blog, reproduced please contact the author!
How to implement one of the IM features in an app offline message common analysis--arrow Buckle technology Arrownock