TEAMtalk Android Code Analysis (business process)---the overall logical description of message sending and receiving

Source: Internet
Author: User
Tags teamtalk

The first record of things, there is no special order, think of where to draw a bit, follow-up will continue to organize ~

6.2 Message Page Action flow

General idea of 6.2.1 Message page initialization

1. Fill updates for page data are requested directly from the local database by the main thread of the page

2. Population of database data is requested asynchronously from the network by a background thread

3. The foreground thread reads the database data according to the 18 records each time, the background thread requests the data from the network each time 18*3

4. Background thread data requests by the main thread to meet certain conditions after sending bus events, processed in Oneventbackgroudthread, the specific conditions (or relationships) are as follows:

1> First time Request

2> The local database is not loaded into the data

The number of 3> requests is a multiple of 3 (in order to satisfy local data to be read in time)

5. Background asynchronous thread Read Network information There are currently two interfaces, respectively, are

1>cid_msg_list_request_value that is: passing in a last message ID (lastmsgid) and the number of requests (MSGCNT), requesting data from the server

2>cid_msg_get_by_msg_id_req_value is the list of message IDs that are passed in to request, requesting data from the server

Current mode of Use:

[first] request from the database [when the screen message list (18 or less)], all are [local send failed] message, in the first way, a large number and the number of requests to the server to pull the data, otherwise, according to the last success message MsgId and the number of requests (18* 3) as a condition, read the list of messages from the local database (Beginid-Endid), and then filter out the msgid that are not locally according to the list and the MsgId and msgid-18*3 intervals, and then go to the server to request data in the second way. (Since the server is pulled in reverse message)

6. Pull down when the first message entity that passes in the current page (MsgId the latest entity) and the pull count (pulltimes) as parameters, reads the new data from the local database, and when the data gets successful, the number of pulls plus 1.

6.2.2 Logical Description of message reception

1> Overall Essence: The PB data received from the server is converted to Greendao generated entity class messageentity and its subclasses, which are divided into textmessage,imagemessage,audiomessage in terms of presentation and business, mixmessage[), and subclasses use fields such as rewrite messageentity getcontent to get the method), and store messageentity messages to the database, update the database and local cache Sessionmap in a timely manner, It then sends the event that receives the message, notifies the UI thread to reread the data and refreshes the interface, and, of course, updates the session as well as the database and interface data.

The difference of 2>messageentity subclasses mainly lies in the classification according to the business and presentation forms, the specific subclass expands the field according to the concrete form, for example: Imagemessage, needs to expand the field path,url,loadstatus. The advantage of the ORM framework is that it is serialized as JSON when the database is stored, stored in a content field, and then deserialized into a different message object when it is read from the database.

3> need to know, the current voice message is sent through the socket, so directly stored, the image is sent a URL, in the page display, then to request the address.

6.2.3 Logical description of message sending

1> Building a Send object (textmessage,imagemessage,audiomessage)

2> storing message objects to the database

3> Update or create session cache and store database, and send event notification to update session related UI

4> Update Message interface (text messages are updated directly, others are more complex)

5> sends a message to the server and adds a detection queue.

6>ack processing after return

(1) Updating the local messaging database

(2) Update session correlation (SESSIONMAP and DB)

(3) Send bus event (messageevent), notification interface update.

6.2.4 the sending process of picture messages

TEAMtalk Android Code Analysis (business process)---the overall logical description of message sending and receiving

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.