Message Expiration

How to Determine Expiration Time of a Received Message

Every received Message has an expireIn value which represent the seconds until the message expires and should not be shown anymore. We use this value to calculate the expiration time for the message in the following way:

message.expiresAt = Date.now() + message.expireIn * 1000

Conversation Behavior on Message Expiration

Each of our models emit events during their lifetimes to help integrators react to model changes (addition, deletion, updates, etc.).

To listen for message expiration, you will need to listen for the afterEject event which is emitted after the model is removed. The event can be used to determine when a message has been deleted, and therefore should be removed from view.

Here is an example with a callback that prints out the ID of the deleted message:

this.host.models.Message.on('afterEject', (resource, message) => {
console.log('message deleted: ' + message.id);
});

Once a message is deleted, it is ejected from the store and in turn emits the afterEject event. The listener may respond to the event by re-rendering the conversation without the expired message.

If the expiring message is the last message or first the expiring message, the latest values will be fetched from server. This will update the roster tile for last message and also the badge count.