Reworked iscomposing addresses cache

This commit is contained in:
Sylvain Berfini 2017-11-22 14:02:35 +01:00
parent fa861d553d
commit bb9cf6a74f
7 changed files with 32 additions and 19 deletions

View file

@ -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

View file

@ -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) {

View file

@ -83,7 +83,7 @@ public:
LinphoneCall *call = nullptr;
ChatRoom::State state = ChatRoom::State::None;
bool isComposing = false;
std::unordered_set<std::string> remoteIsComposing;
std::list<Address> remoteIsComposing;
std::list<std::shared_ptr<ChatMessage>> transientMessages;
std::list<std::weak_ptr<ChatMessage>> weakMessages;

View file

@ -319,7 +319,6 @@ void ChatRoomPrivate::chatMessageReceived (const shared_ptr<ChatMessage> &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<ChatMessage> &
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<Address> ChatRoom::getComposingAddresses () const {
L_D();
return d->remoteIsComposing;
}
void ChatRoom::markAsRead () {
L_D();

View file

@ -72,6 +72,7 @@ public:
std::list<std::shared_ptr<ChatMessage>> getHistoryRange (int startm, int endm);
int getUnreadChatMessagesCount ();
bool isRemoteComposing () const;
std::list<Address> getComposingAddresses () const;
virtual void markAsRead ();

View file

@ -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)) {

View file

@ -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);