Reply to a specific message

Last modified by Sylvain Berfini on 2022/01/06 13:17

This feature has been added in 5.1.0 release of the SDK.

How to use it

User can now reply to a specific message using the following API:

 /**
 * Creates a reply message attached to the given chat room with a particular message.
 * @param chat_room the #LinphoneChatRoom object. @notnil
 * @param message #LinphoneChatMessage message to reply to. @notnil
 * @return a new #LinphoneChatMessage @notnil
 */

LINPHONE_PUBLIC LinphoneChatMessage *linphone_chat_room_create_reply_message (LinphoneChatRoom *chat_room, LinphoneChatMessage *message);

Here's how to access the reply information on the receiving end:

/**
 * Returns wether the chat message is a reply message or not.
 * @param message #LinphoneChatMessage object. @notnil
 * @return TRUE if it is a reply message, FALSE otherwise
 */

LINPHONE_PUBLIC bool_t linphone_chat_message_is_reply (LinphoneChatMessage *message);

/**
 * Returns the ID of the message this is a reply to.
 * @param message #LinphoneChatMessage object. @notnil
 * @return the original message id. @maybenil
 */

LINPHONE_PUBLIC const char* linphone_chat_message_get_reply_message_id(LinphoneChatMessage *message);

/**
 * Returns the ID of the message this is a reply to.
 * @param message #LinphoneChatMessage object. @notnil
 * @return the original message sender #LinphoneAddress. @maybenil
 */

const LINPHONE_PUBLIC LinphoneAddress* linphone_chat_message_get_reply_message_sender_address(LinphoneChatMessage *message);

Requirements

Our implementation is based on two CPIM headers.

CPIM is an IETF standard: https://datatracker.ietf.org/doc/html/rfc3862

Until 5.1.0 SDK CPIM was only enabled on Flexisip based chat rooms (group chat rooms and/or end-to-end encrypted chat rooms in our applications), but now you can enable CPIM messages in basic chat rooms in your account configuration:

/**
 * Indicates whether chat messages sent by this account in a #LinphoneChatRoomBackendBasic chat room will be using CPIM format or not.
 * @param params The #LinphoneAccountParams object. @notnil
 * @param enable TRUE to send messages in CPIM format, FALSE to keep using the SIP SIMPLE format.
 */

LINPHONE_PUBLIC void linphone_account_params_enable_cpim_in_basic_chat_room(LinphoneAccountParams *params, bool_t enable);

Any Basic chat room for which the LinphoneAccount that matches it's local address has the above property enabled will send all messages using CPIM format instead of SIP SIMPLE.

CPIM has been available in linphone-sdk for a few years now so you don't need the recipient of the reply to have the latest version of our SDK or app, however it won't be able to display it as a reply if not using at least a 5.1.0 SDK.

In case a reply message is sent in a basic chat room without CPIM, it will be sent as a SIP SIMPLE message without any reply information and displayed as a regular message on the receiving side.

How it works

This will add to the CPIM message two headers: Replying-To-Message-ID and Replying-To-Sender.
The first one is the reference on the message that we are replying to, the second one is the SIP address that has sent the message we are replying to.

The main advantage of this solution is to be very lightweight because as we do not send again the original message, but it's main downside is that if the recipient doesn't have the original message (deleted it, joined the chat room after, etc...) it won't be able to display along with the reply.
When that happens you will still be able to display the original message's sender SIP address as a fallback, if you want to.