diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index 244afe477..7d05bdcee 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -364,7 +364,7 @@ LINPHONE_PUBLIC void linphone_chat_room_set_subject (LinphoneChatRoom *cr, const * @param[in] cr A LinphoneChatRoom object * @return \bctbx_list{LinphoneAddress} list of addresses that are in the is_composing state */ -LINPHONE_PUBLIC bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr); +LINPHONE_PUBLIC const bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr); /** * Set the conference address of a group chat room. This function needs to be called from the diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index 5f81c0f7b..d8185943b 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -302,13 +302,8 @@ void linphone_chat_room_set_subject (LinphoneChatRoom *cr, const char *subject) L_GET_CPP_PTR_FROM_C_OBJECT(cr)->setSubject(L_C_TO_STRING(subject)); } -bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr) { - LinphonePrivate::ChatRoomPrivate *room = L_GET_PRIVATE_FROM_C_OBJECT(cr); - bctbx_list_t *result = NULL; - for (const auto &uri : room->remoteIsComposing) { - result = bctbx_list_append(result, linphone_address_new(uri.c_str())); - } - return result; +const bctbx_list_t * linphone_chat_room_get_composing_addresses(LinphoneChatRoom *cr) { + return L_GET_RESOLVED_C_LIST_FROM_CPP_LIST(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getComposingAddresses()); } LinphoneChatMessage *linphone_chat_room_create_file_transfer_message(LinphoneChatRoom *cr, const LinphoneContent *initial_content) { diff --git a/src/chat/chat-room/chat-room-p.h b/src/chat/chat-room/chat-room-p.h index 1a06de91d..9fafcb6f5 100644 --- a/src/chat/chat-room/chat-room-p.h +++ b/src/chat/chat-room/chat-room-p.h @@ -83,7 +83,7 @@ public: LinphoneCall *call = nullptr; ChatRoom::State state = ChatRoom::State::None; bool isComposing = false; - std::unordered_set remoteIsComposing; + std::list
remoteIsComposing; std::list> transientMessages; std::list> weakMessages; diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 0d5bbea64..2135002cb 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -319,7 +319,6 @@ void ChatRoomPrivate::chatMessageReceived (const shared_ptr &msg) { notifyChatMessageReceived(msg); const string fromAddress = msg->getFromAddress().asString(); - remoteIsComposing.erase(fromAddress); isComposingHandler->stopRemoteRefreshTimer(fromAddress); notifyIsComposingReceived(msg->getFromAddress(), false); msg->sendDeliveryNotification(LinphoneReasonNone); @@ -360,6 +359,12 @@ void ChatRoomPrivate::notifyChatMessageReceived (const shared_ptr & void ChatRoomPrivate::notifyIsComposingReceived (const Address &remoteAddr, bool isComposing) { L_Q(); + + if (isComposing) + remoteIsComposing.push_back(remoteAddr); + else + remoteIsComposing.remove(remoteAddr); + LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); LinphoneChatRoomCbsIsComposingReceivedCb cb = linphone_chat_room_cbs_get_is_composing_received(cbs); @@ -399,10 +404,6 @@ void ChatRoomPrivate::onIsComposingStateChanged (bool isComposing) { } void ChatRoomPrivate::onIsRemoteComposingStateChanged (const Address &remoteAddr, bool isComposing) { - if (isComposing) - remoteIsComposing.insert(remoteAddr.asStringUriOnly()); - else - remoteIsComposing.erase(remoteAddr.asStringUriOnly()); notifyIsComposingReceived(remoteAddr, isComposing); } @@ -505,6 +506,11 @@ bool ChatRoom::isRemoteComposing () const { return d->remoteIsComposing.size() > 0; } +std::list
ChatRoom::getComposingAddresses () const { + L_D(); + return d->remoteIsComposing; +} + void ChatRoom::markAsRead () { L_D(); diff --git a/src/chat/chat-room/chat-room.h b/src/chat/chat-room/chat-room.h index e98af035a..f6c671b3f 100644 --- a/src/chat/chat-room/chat-room.h +++ b/src/chat/chat-room/chat-room.h @@ -72,6 +72,7 @@ public: std::list> getHistoryRange (int startm, int endm); int getUnreadChatMessagesCount (); bool isRemoteComposing () const; + std::list
getComposingAddresses () const; virtual void markAsRead (); diff --git a/src/chat/chat-room/real-time-text-chat-room.cpp b/src/chat/chat-room/real-time-text-chat-room.cpp index d4ed5ee45..6242b51b1 100644 --- a/src/chat/chat-room/real-time-text-chat-room.cpp +++ b/src/chat/chat-room/real-time-text-chat-room.cpp @@ -58,7 +58,7 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp cmc->has_been_read = FALSE; receivedRttCharacters.push_back(cmc); - remoteIsComposing.insert(q->getPeerAddress().asString()); + remoteIsComposing.push_back(q->getPeerAddress()); linphone_core_notify_is_composing_received(cCore, L_GET_C_BACK_PTR(q)); if ((character == new_line) || (character == crlf) || (character == lf)) { diff --git a/tester/message_tester.c b/tester/message_tester.c index f9754608a..34909e35f 100644 --- a/tester/message_tester.c +++ b/tester/message_tester.c @@ -942,8 +942,10 @@ static int enable_lime_for_message_test(LinphoneCoreManager *marie, LinphoneCore } static void _is_composing_notification(bool_t lime_enabled) { - LinphoneChatRoom* chat_room; + LinphoneChatRoom* pauline_chat_room; + LinphoneChatRoom* marie_chat_room; int dummy = 0; + const bctbx_list_t *composing_addresses = NULL; LinphoneCoreManager* marie = linphone_core_manager_new("marie_rc"); LinphoneCoreManager* pauline = linphone_core_manager_new( "pauline_tcp_rc"); @@ -952,13 +954,22 @@ static void _is_composing_notification(bool_t lime_enabled) { if (enable_lime_for_message_test(marie, pauline) < 0) goto end; } - chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); + pauline_chat_room = linphone_core_get_chat_room(pauline->lc, marie->identity); + marie_chat_room = linphone_core_get_chat_room(marie->lc, pauline->identity); linphone_core_get_chat_room(marie->lc, pauline->identity); /*make marie create the chatroom with pauline, which is necessary for receiving the is-composing*/ - linphone_chat_room_compose(chat_room); + linphone_chat_room_compose(pauline_chat_room); wait_for_until(pauline->lc, marie->lc, &dummy, 1, 1500); /*just to sleep while iterating*/ - linphone_chat_room_send_message(chat_room, "Composing a msg"); + linphone_chat_room_send_message(pauline_chat_room, "Composing a msg"); BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingActiveReceived, 1)); + composing_addresses = linphone_chat_room_get_composing_addresses(marie_chat_room); + BC_ASSERT_GREATER(bctbx_list_size(composing_addresses), 0, int, "%i"); + if (bctbx_list_size(composing_addresses) > 0) { + LinphoneAddress *addr = (LinphoneAddress *)bctbx_list_get_data(composing_addresses); + BC_ASSERT_STRING_EQUAL(linphone_address_as_string(addr), linphone_address_as_string(pauline->identity)); + } BC_ASSERT_TRUE(wait_for(pauline->lc, marie->lc, &marie->stat.number_of_LinphoneIsComposingIdleReceived, 2)); + composing_addresses = linphone_chat_room_get_composing_addresses(marie_chat_room); + BC_ASSERT_EQUAL(bctbx_list_size(composing_addresses), 0, int, "%i"); end: linphone_core_manager_destroy(marie);