diff --git a/coreapi/chat.c b/coreapi/chat.c index 19b49caf0..e93226220 100644 --- a/coreapi/chat.c +++ b/coreapi/chat.c @@ -750,6 +750,10 @@ LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const cr->unread_count = 1; else cr->unread_count++; + /* Mark the message as pending so that if linphone_core_chat_room_mark_as_read() is called + in the linphone_chat_room_message_received() callback, it will effectively be marked as + being read before being stored. */ + cr->pending_message = msg; } linphone_chat_room_message_received(cr, lc, msg); @@ -758,6 +762,8 @@ LinphoneReason linphone_core_message_received(LinphoneCore *lc, SalOp *op, const msg->storage_id = linphone_chat_message_store(msg); } + cr->pending_message = NULL; + end: linphone_address_unref(addr); if (msg != NULL) linphone_chat_message_unref(msg); diff --git a/coreapi/message_storage.c b/coreapi/message_storage.c index 211230b76..d07bcf525 100644 --- a/coreapi/message_storage.c +++ b/coreapi/message_storage.c @@ -456,6 +456,11 @@ void linphone_chat_room_mark_as_read(LinphoneChatRoom *cr){ sqlite3_free(buf); ms_free(peer); + if (cr->pending_message) { + linphone_chat_message_set_state(cr->pending_message, LinphoneChatMessageStateDisplayed); + linphone_chat_message_send_display_notification(cr->pending_message); + } + cr->unread_count = 0; }