From 25a6524d143c620a0546c20a810dfc45524f92e4 Mon Sep 17 00:00:00 2001
From: Sylvain Berfini <sylvain.berfini@belledonne-communications.com>
Date: Fri, 16 Dec 2016 11:08:19 +0100
Subject: [PATCH] Fix chat message stored encrypted in database making it
 displayed as xml in mobile apps

---
 coreapi/chat.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/coreapi/chat.c b/coreapi/chat.c
index 86005269e5..da49ebfa0b 100644
--- a/coreapi/chat.c
+++ b/coreapi/chat.c
@@ -351,6 +351,12 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
 		LinphoneCall *call=NULL;
 		char *content_type;
 		const char *identity = NULL;
+		char *message_not_encrypted = NULL;
+		
+		if (msg->message) {
+			message_not_encrypted = ms_strdup(msg->message);
+		}
+		
 		// add to transient list
 		cr->transient_messages = bctbx_list_append(cr->transient_messages, linphone_chat_message_ref(msg));
 		msg->time = ms_time(0);
@@ -416,6 +422,11 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
 			 */
 			linphone_address_destroy(msg->from);
 		}
+		if (msg->message && message_not_encrypted && strcmp(msg->message, message_not_encrypted) != 0) {
+			// We replace the encrypted message by the original one so it can be correctly stored and displayed by the application
+			ms_free(msg->message);
+			msg->message = ms_strdup(message_not_encrypted);
+		}
 		msg->from = linphone_address_new(identity);
 		msg->storage_id = linphone_chat_message_store(msg);
 
@@ -437,7 +448,9 @@ void _linphone_chat_room_send_message(LinphoneChatRoom *cr, LinphoneChatMessage
 			return;
 		}
 
-
+		if (message_not_encrypted) {
+			ms_free(message_not_encrypted);
+		}
 	}
 	// if operation failed, we should not change message state
 	if (msg->dir == LinphoneChatMessageOutgoing) {
-- 
GitLab