Chat message display method and deviceTechnical Field
The present invention relates to the field of instant messaging technologies, and in particular, to a method and an apparatus for displaying a chat message.
Background
An Instant chat tool (IM for short) is an application program for transmitting Instant messages between users, and is convenient for users to communicate. For messages received by a user during offline, the prior art adopts a scheme that offline buffering is performed through a server, all buffered messages are pushed to a user terminal at one time when the user is online, after the user terminal receives the messages, a 'reached' receipt is sent, and the server removes the corresponding messages from the buffer so as to ensure that the messages are not lost. Currently, for the message push received by the user during online, the following push algorithm is generally adopted: the server processes the delivery sequence of the push message and then pushes the push message to the user terminal, and although the scheme can ensure that the message is not lost, the concurrency efficiency of the server is reduced.
Disclosure of Invention
The invention aims to provide a method and equipment for displaying chat messages, which can ensure that the chat messages are displayed on a user terminal in order without reducing the concurrency efficiency of a server.
In order to achieve the above object, an aspect of the present invention provides a method for displaying a chat message, including:
receiving a plurality of chat messages sent by a server based on a session, wherein the chat messages comprise message contents, message timestamps and message sequence numbers marked in sequence based on the message timestamps;
identifying whether a plurality of chat messages in the session are continuous, extracting the continuous chat messages from the session and storing the continuous chat messages in a terminal memory, or adding the discontinuous chat messages into a temporary window cache;
initiating a request to a server based on the missing chat messages, adding the pulled chat messages into the temporary window cache until the chat messages cached in the temporary window are continuously matched with the chat messages in the terminal memory, and transferring the chat messages of the continuously matched part to the terminal memory;
and calling the message content from the terminal memory according to the time sequence of the message time stamp to display to the user.
Preferably, when a chat message is added into the temporary window buffer, the timer is restarted until the timing of the timer is reset to zero, and all chat message buffers in the temporary window are transferred to the terminal memory.
Preferably, the timer is started when the first chat message is cached in the temporary window, and all chat message caches in the temporary window in a preset time period are stored in the terminal memory.
Preferably, for the chat messages that are still missing after the current timer is closed, if the chat messages are reproduced in the subsequent request pulling process, the corresponding missing chat messages are directly transferred to the terminal memory through the temporary window.
Preferably, whether the buffer in the temporary window triggers the upper limit is monitored, and if the upper limit removal timer is triggered, all the chat message buffers in the temporary window are simultaneously transferred to the terminal memory.
Optionally, before initiating the request to the server based on the missing chat message, the method further includes:
and setting a quantity threshold of the content of the messages displayed by the terminal, and pulling only the missing chat messages corresponding to the message sequence numbers in the range of the threshold interval after the terminal is online.
Specifically, the method for identifying whether a plurality of chat messages in a conversation are continuous comprises the following steps:
and identifying whether the message serial numbers of the adjacent chat messages are continuous, wherein when the message serial numbers continuously indicate that the corresponding chat messages are continuous, otherwise, the corresponding chat messages are discontinuous.
Compared with the prior art, the chat message display method provided by the invention has the following beneficial effects:
in the chat message display method provided by the invention, each chat message comprises three parts of message content, message timestamp and message serial number, and the message serial number is marked according to the time sequence, so that when terminal equipment receives a plurality of chat messages in the same session, whether the plurality of chat messages are continuous or not can be judged by identifying the message serial number, then the continuous chat messages are directly stored in a memory of the terminal equipment, the discontinuous chat messages are added into a temporary window cache, then a request is made to a server side based on the missing chat messages alone, the missing chat messages pulled can be supplemented into the temporary window to be fused with the previous discontinuous chat messages, and finally whether a part which is continuously matched with the latest chat message in the terminal memory exists in the fused chat messages or not is judged, if the chat messages exist, the chat messages of the continuous matching part are transferred to the terminal memory, meanwhile, the remaining discontinuous chat messages in the temporary window are reserved to be pulled by a subsequent continuous request, and finally, the message content is called from the terminal memory according to the time sequence of the message timestamp to be displayed to the user.
Therefore, the invention can lead the terminal equipment to judge whether a plurality of chat messages are continuous or not based on the message serial number by carrying out the timestamp marking and the sequential serial number marking on the message content, further directly store the continuous chat messages in the terminal memory for calling and displaying, and cache the discontinuous chat messages in the temporary window, wait for the missing chat messages to be supplemented and then for calling and displaying until the plurality of chat messages are continuously stored in the terminal memory, thereby ensuring the ordered display of the plurality of chat messages on the user terminal.
A second aspect of the present invention provides a method for displaying a chat message, including:
correspondingly marking the message timestamps on a plurality of chat contents in the session and sequentially marking the message serial numbers on the chat contents to generate chat messages;
and sending a plurality of chat messages to the terminal equipment.
A third aspect of the present invention provides a terminal device, comprising:
a receiving unit, configured to receive a plurality of chat messages sent by a server based on a session, where the chat messages include message contents, message timestamps, and message sequence numbers sequentially marked based on the message timestamps;
the identification unit is used for identifying whether a plurality of chat messages in the conversation are continuous or not, extracting the continuous chat messages from the conversation and storing the continuous chat messages in a terminal memory, or adding the discontinuous chat messages into a temporary window cache;
the missing pulling unit is used for initiating a request to the server side based on the missing chat messages, adding the pulled chat messages into the temporary window cache until the chat messages cached in the temporary window are continuously matched with the chat messages in the terminal memory, and transferring the chat messages of the continuously matched part to the terminal memory;
and the display unit is used for calling the message content from the terminal memory according to the time sequence of the message time stamp and displaying the message content to the user.
Preferably, the method further comprises the following steps:
the timer unit is used for restarting the timer when the chat messages are added into the temporary window cache until the timing of the timer returns to zero, and then all the chat message caches in the temporary window are stored to the terminal memory; or,
and the timer is used for starting the timer when the first chat message is cached in the temporary window, and transferring all chat message caches in the temporary window in a preset time period to the terminal memory.
Preferably, the method further comprises the following steps:
and the missing post-processing unit is used for directly transferring the corresponding missing chat messages to the terminal memory through the temporary window if the chat messages which are still missing after the current timer is closed are reproduced in the subsequent request pulling process.
Further, still include:
and the display quantity setting unit is used for setting a quantity threshold of the content of the display messages of the terminal and pulling only the missing chat messages corresponding to the message serial numbers in the threshold interval range after the terminal is online.
A fourth aspect of the present invention provides a server apparatus, including:
the marking unit is used for correspondingly marking the message timestamps on a plurality of chat contents in the conversation and sequentially marking the message serial numbers on the chat contents to generate chat messages;
and the sending unit is used for sending a plurality of chat messages to the terminal equipment.
Drawings
The accompanying drawings, which are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the invention and not to limit the invention. In the drawings:
fig. 1 is a flowchart illustrating a chat message display method according to an embodiment of the present invention;
fig. 2 is a schematic diagram illustrating a request initiated to a server based on a missing chat message in a session according to an embodiment of the present invention;
fig. 3 is a schematic diagram illustrating a temporary window waiting for caching of chat messages based on a miss in a session according to an embodiment of the present invention.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present invention comprehensible, embodiments accompanied with figures are described in detail below. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example one
Referring to fig. 1, the present embodiment provides a method for displaying a chat message, including:
receiving a plurality of chat messages sent by a server based on a session, wherein the chat messages comprise message contents, message timestamps and message sequence numbers marked in sequence based on the message timestamps; identifying whether a plurality of chat messages in the session are continuous, extracting the continuous chat messages from the session and storing the continuous chat messages in a terminal memory, or adding the discontinuous chat messages into a temporary window cache; initiating a request to a server based on the missing chat messages, adding the pulled chat messages into the temporary window cache until the chat messages cached in the temporary window are continuously matched with the chat messages in the terminal memory, and transferring the chat messages of the continuously matched part to the terminal memory; and calling the message content from the terminal memory according to the time sequence of the message time stamp to display to the user.
In the chat message display method provided by this embodiment, each chat message includes three parts, i.e., a message content, a message timestamp, and a message serial number, and the message serial numbers are labeled according to a time sequence order, so that when receiving multiple chat messages in the same session, a terminal device can determine whether the multiple chat messages are continuous by identifying the message serial numbers, then directly store the continuous chat messages in a memory of the terminal device, wherein the discontinuous chat messages are added into a temporary window for caching, and then request a server based on the missing chat messages alone, so that the missing chat messages pulled can be added into the temporary window to be merged with the previous discontinuous chat messages, and finally determine whether a part continuously matched with the latest chat message in the terminal memory exists in the merged chat messages, if the chat messages exist, the chat messages of the continuous matching part are transferred to the terminal memory, meanwhile, the remaining discontinuous chat messages in the temporary window are reserved to be pulled by a subsequent continuous request, and finally, the message content is called from the terminal memory according to the time sequence of the message timestamp to be displayed to the user.
It can be seen that in the embodiment, by performing timestamp marking and sequential serial number marking on message content, the terminal device can determine whether a plurality of chat messages are continuous based on the message serial number, and then directly store the continuous chat messages in the terminal memory for retrieval and display, and place the discontinuous chat messages in the temporary window cache, wait for the retrieval of missing chat messages to be supplemented and then for retrieval and display, until the plurality of chat messages are continuously stored in the terminal memory, thereby ensuring the ordered display of the plurality of chat messages on the user terminal. The method for identifying whether a plurality of chat messages in a conversation are continuous comprises the following steps: and identifying whether the message serial numbers of the adjacent chat messages are continuous, wherein when the message serial numbers continuously indicate that the corresponding chat messages are continuous, otherwise, the corresponding chat messages are discontinuous.
Exemplarily, referring to fig. 2, the user terminal has three chat sessions, namely a small-definition session, a overseas group buying session and a girlfried chat group session, wherein for the small-definition session, the chat messages corresponding to the message sequence numbers 33, 36-44 and 50 are not continuous and are temporarily stored in a temporary window for caching, the chat messages corresponding to the message sequence numbers 34-35 and 45-49 are missing, and when requesting from the server again, only the missing chat messages are correspondingly pulled; similarly, the chat messages corresponding to the message sequence numbers 102, 104, 110 and 200 in the session of the overseas shopping group are not continuous and are temporarily stored in the temporary window for caching, and the chat messages corresponding to the message sequence numbers 103 and 105 and 109 are lacked, and only the chat messages corresponding to the message sequence numbers 103 and 105 and 109 are correspondingly pulled when the request is made to the server again.
In order to avoid the situation that the chat messages in the same session are repeatedly displayed, the chat messages also comprise global unique identifiers uuid of message contents, long-type seq serial numbers can be selected for the message serial numbers, the seq numbering rule is based on session independent numbering, the seq serial numbers are required to be numbered from 1 according to a time stamp sequence, and the message time stamps can be correspondingly marked as ts1, ts2 and the like according to the successive occurrence time of the message contents.
In order to reduce the time waiting for the completion in the temporary window, in the above embodiment, when a chat message is added to the temporary window buffer, the timer is restarted until the timer is reset to zero, and all chat message buffers in the temporary window are transferred to the terminal memory. Or starting a timer when the first chat message is cached in the temporary window, and transferring all chat message caches in the temporary window in a preset time period to the terminal memory.
In the specific implementation process, in order to reduce the waiting time for the user to view the chat content, the former scheme is preferably used, as shown in fig. 3, for the chat messages corresponding to the message sequence numbers 102 and 104 cached in the session temporary window of the overseas shopping group, the chat message corresponding to the message sequence number 103 is missing, at this time, the pull request is initiated to the server again based on the missing message sequence number 103, meanwhile, the timer is restarted to count down when the chat message corresponding to the message sequence number 102 is received, for example, 3 seconds, if the chat message corresponding to the message sequence number 103 is pulled before the timer is zeroed, the chat messages corresponding to the message sequence numbers 102, 103 and 104 are together stored in the terminal memory (the chat messages corresponding to the stored message sequence numbers 1-101), and if the chat message corresponding to the message sequence number 103 is not pulled before the timer is zeroed, the chat message corresponding to the message sequence number 102, 103, 102, 104, b, 104, the chat messages are transferred and stored in the terminal memory, and the temporary window corresponding to the overseas shopping group session is emptied and cached.
Further, if the chat message still lacks in the temporary window after the current timer is closed, the temporary window does not continue to wait for the completion, but directly transfers the missing chat message to the terminal memory through the temporary window if the missing chat message reappears in the subsequent request pulling process. Therefore, by adopting the design scheme of the timer, the user can see the non-repeated and orderly chat messages in as short a time as possible, the situation of message loss is avoided, and the user experience is improved.
It should be noted that, the temporary window and the timer are configured in a one-to-one correspondence manner based on the number of sessions, so that the reliability of session execution is ensured.
Optionally, in the above embodiment, it is further required to monitor whether the buffer in the temporary window triggers an upper limit, and if the upper limit removal timer is triggered, all the chat message buffers in the temporary window are transferred to the terminal memory. The temporary window buffer upper limit is set to avoid the situation of program disk collapse caused by huge temporary window buffer amount, when the buffer triggers the upper limit, the buffer is actively transferred for storage, and the buffer of the previous temporary window is emptied after the transfer is finished.
Considering that when a terminal which is not online for a long time is suddenly online, all offline messages are pushed to the terminal at one time, which easily causes terminal equipment jam, waste of traffic and inconvenience for a user to read, the embodiment further includes, before initiating a request to the server based on a missing chat message:
and setting a quantity threshold of the content of the messages displayed by the terminal, and pulling only the missing chat messages corresponding to the message sequence numbers in the range of the threshold interval after the terminal is online. In specific implementation, a quantity threshold for pushing the offline messages may be freely set by an engineer, which is not limited in this embodiment, and the quantity threshold is taken as 300, for example, when the total quantity of the offline messages exceeds 300, the latest 300 offline messages are preferentially pushed online at the instant of the terminal, the remaining offline messages are pushed again after the user finishes reading the 300 chat messages, and if the user does not finish reading the 300 offline messages that are preferentially pushed, the subsequent offline messages are not pushed any more.
Example two
The embodiment provides a chat message display method, which comprises the following steps:
correspondingly marking the message timestamps on a plurality of chat contents in the session and sequentially marking the message serial numbers on the chat contents to generate chat messages;
and sending a plurality of chat messages to the terminal equipment.
Compared with the prior art, the beneficial effects of the method for displaying the chat message provided by the embodiment of the invention are the same as those of the method for displaying the chat message provided by the first embodiment, and are not repeated herein.
EXAMPLE III
The present embodiment provides a terminal device, including:
a receiving unit, configured to receive a plurality of chat messages sent by a server based on a session, where the chat messages include message contents, message timestamps, and message sequence numbers sequentially marked based on the message timestamps;
the identification unit is used for identifying whether a plurality of chat messages in the conversation are continuous or not, extracting the continuous chat messages from the conversation and storing the continuous chat messages in a terminal memory, or adding the discontinuous chat messages into a temporary window cache;
the missing pulling unit is used for initiating a request to the server side based on the missing chat messages, adding the pulled chat messages into the temporary window cache until the chat messages cached in the temporary window are continuously matched with the chat messages in the terminal memory, and transferring the chat messages of the continuously matched part to the terminal memory;
and the display unit is used for calling the message content from the terminal memory according to the time sequence of the message time stamp and displaying the message content to the user.
Preferably, the method further comprises the following steps:
the timer unit is used for restarting the timer when the chat messages are added into the temporary window cache until the timing of the timer returns to zero, and then all the chat message caches in the temporary window are stored to the terminal memory; or,
and the timer is used for starting the timer when the first chat message is cached in the temporary window, and transferring all chat message caches in the temporary window in a preset time period to the terminal memory.
Preferably, the method further comprises the following steps:
and the missing post-processing unit is used for directly transferring the corresponding missing chat messages to the terminal memory through the temporary window if the chat messages which are still missing after the current timer is closed are reproduced in the subsequent request pulling process.
Preferably, the method further comprises the following steps:
and the display quantity setting unit is used for setting a quantity threshold of the content of the display messages of the terminal and pulling only the missing chat messages corresponding to the message serial numbers in the threshold interval range after the terminal is online.
Compared with the prior art, the beneficial effects of the terminal device provided by the embodiment of the present invention are the same as the beneficial effects of the chat message display method provided by the first embodiment, and are not described herein again.
Example four
The present embodiment provides a server device, including:
the marking unit is used for correspondingly marking the message timestamps on a plurality of chat contents in the conversation and sequentially marking the message serial numbers on the chat contents to generate chat messages;
and the sending unit is used for sending a plurality of chat messages to the terminal equipment.
Compared with the prior art, the beneficial effects of the server device provided by the embodiment of the present invention are the same as the beneficial effects of the chat message display method provided by the first embodiment, and are not described herein again.
It will be understood by those skilled in the art that all or part of the steps in the method for implementing the invention may be implemented by hardware instructions related to a program, the program may be stored in a computer-readable storage medium, and when executed, the program includes the steps of the method of the embodiment, and the storage medium may be: ROM/RAM, magnetic disks, optical disks, memory cards, and the like.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the appended claims.