How to implement one of the IM features in an app offline message common analysis--arrow Buckle technology Arrownock

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.