diff --git a/src/c-wrapper/api/c-chat-message.cpp b/src/c-wrapper/api/c-chat-message.cpp index b60967110..7e28a33ef 100644 --- a/src/c-wrapper/api/c-chat-message.cpp +++ b/src/c-wrapper/api/c-chat-message.cpp @@ -265,11 +265,11 @@ void linphone_chat_message_cancel_file_transfer(LinphoneChatMessage *msg) { } void linphone_chat_message_resend(LinphoneChatMessage *msg) { - L_GET_CPP_PTR_FROM_C_OBJECT(msg)->reSend(); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send(); } void linphone_chat_message_resend_2(LinphoneChatMessage *msg) { - L_GET_CPP_PTR_FROM_C_OBJECT(msg)->reSend(); + L_GET_CPP_PTR_FROM_C_OBJECT(msg)->send(); } void linphone_chat_message_update_state(LinphoneChatMessage *msg, LinphoneChatMessageState new_state) { diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index e56d447c0..f447e0fd2 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -74,7 +74,7 @@ void linphone_chat_room_remove_transient_message (LinphoneChatRoom *cr, Linphone } void linphone_chat_room_send_message (LinphoneChatRoom *cr, const char *msg) { - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg)); + L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->createMessage(msg)); } bool_t linphone_chat_room_is_remote_composing (const LinphoneChatRoom *cr) { @@ -136,16 +136,16 @@ void linphone_chat_room_send_message2 ( ) { linphone_chat_message_set_message_state_changed_cb(msg, status_cb); linphone_chat_message_set_message_state_changed_cb_user_data(msg, ud); - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); + L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); } void linphone_chat_room_send_chat_message_2 (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { linphone_chat_message_ref(msg); - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); + L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); } void linphone_chat_room_send_chat_message (LinphoneChatRoom *cr, LinphoneChatMessage *msg) { - L_GET_CPP_PTR_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); + L_GET_PRIVATE_FROM_C_OBJECT(cr)->sendMessage(L_GET_CPP_PTR_FROM_C_OBJECT(msg)); } uint32_t linphone_chat_room_get_char (const LinphoneChatRoom *cr) { diff --git a/src/chat/chat-message.cpp b/src/chat/chat-message.cpp index aff6d1048..50822b168 100644 --- a/src/chat/chat-message.cpp +++ b/src/chat/chat-message.cpp @@ -1420,7 +1420,7 @@ void ChatMessage::updateState(State state) { d->chatRoom->getPrivate()->moveTransientMessageToWeakMessages(getSharedFromThis()); } -void ChatMessage::reSend() { +void ChatMessage::send () { L_D(); if (d->state != State::NotDelivered) { @@ -1428,7 +1428,7 @@ void ChatMessage::reSend() { return; } - d->chatRoom->sendMessage(getSharedFromThis()); + d->chatRoom->getPrivate()->sendMessage(getSharedFromThis()); } void ChatMessage::sendDeliveryNotification(LinphoneReason reason) { diff --git a/src/chat/chat-message.h b/src/chat/chat-message.h index 9900b4dbd..7a5504860 100644 --- a/src/chat/chat-message.h +++ b/src/chat/chat-message.h @@ -61,18 +61,18 @@ public: void cancelFileTransfer (); int putCharacter (uint32_t character); void updateState (State state); - void reSend (); void sendDeliveryNotification (LinphoneReason reason); void sendDisplayNotification (); void setImdnMessageId (const std::string &imdnMessageId); void setIsSecured (bool isSecured); void setFromAddress (Address from); void setToAddress (Address to); + void store (); // ----- TODO: Remove me. std::shared_ptr getChatRoom () const; - void store (); + void send (); time_t getTime () const; diff --git a/src/chat/chat-room-p.h b/src/chat/chat-room-p.h index 592e5f5fd..fe8710a6a 100644 --- a/src/chat/chat-room-p.h +++ b/src/chat/chat-room-p.h @@ -45,13 +45,13 @@ private: static int createChatMessageFromDb (void *data, int argc, char **argv, char **colName); public: - void addTransientMessage (std::shared_ptr msg); - void addWeakMessage (std::shared_ptr msg); + void addTransientMessage (const std::shared_ptr &msg); + void addWeakMessage (const std::shared_ptr &msg); std::list > getTransientMessages () const { return transientMessages; } - void moveTransientMessageToWeakMessages (std::shared_ptr msg); - void removeTransientMessage (std::shared_ptr msg); + void moveTransientMessageToWeakMessages (const std::shared_ptr &msg); + void removeTransientMessage (const std::shared_ptr &msg); void release (); void sendImdn (const std::string &content, LinphoneReason reason); @@ -59,6 +59,8 @@ public: int getMessagesCount (bool unreadOnly); void setState (ChatRoom::State newState); + virtual void sendMessage (const std::shared_ptr &msg); + protected: void sendIsComposingNotification (); @@ -68,21 +70,21 @@ protected: int sqlRequest (sqlite3 *db, const std::string &stmt); void sqlRequestMessage (sqlite3 *db, const std::string &stmt); std::list > findMessages (const std::string &messageId); - void storeOrUpdateMessage (std::shared_ptr msg); + void storeOrUpdateMessage (const std::shared_ptr &msg); public: LinphoneReason messageReceived (SalOp *op, const SalMessage *msg); void realtimeTextReceived (uint32_t character, LinphoneCall *call); protected: - void chatMessageReceived (std::shared_ptr msg); + void chatMessageReceived (const std::shared_ptr &msg); void imdnReceived (const std::string &text); void isComposingReceived (const std::string &text); private: - void notifyChatMessageReceived (std::shared_ptr msg); + void notifyChatMessageReceived (const std::shared_ptr &msg); void notifyStateChanged (); - void notifyUndecryptableMessageReceived (std::shared_ptr msg); + void notifyUndecryptableMessageReceived (const std::shared_ptr &msg); private: /* IsComposingListener */ diff --git a/src/chat/chat-room.cpp b/src/chat/chat-room.cpp index c8dabef24..d044fb4fd 100644 --- a/src/chat/chat-room.cpp +++ b/src/chat/chat-room.cpp @@ -51,18 +51,18 @@ int ChatRoomPrivate::createChatMessageFromDb (void *data, int argc, char **argv, // ----------------------------------------------------------------------------- -void ChatRoomPrivate::addTransientMessage (shared_ptr msg) { +void ChatRoomPrivate::addTransientMessage (const shared_ptr &msg) { auto iter = find(transientMessages.begin(), transientMessages.end(), msg); if (iter == transientMessages.end()) transientMessages.push_back(msg); } -void ChatRoomPrivate::addWeakMessage (shared_ptr msg) { +void ChatRoomPrivate::addWeakMessage (const shared_ptr &msg) { weak_ptr weakptr(msg); weakMessages.push_back(weakptr); } -void ChatRoomPrivate::moveTransientMessageToWeakMessages (shared_ptr msg) { +void ChatRoomPrivate::moveTransientMessageToWeakMessages (const shared_ptr &msg) { auto iter = find(transientMessages.begin(), transientMessages.end(), msg); if (iter != transientMessages.end()) { /* msg is not transient anymore, we can remove it from our transient list and unref it */ @@ -73,7 +73,7 @@ void ChatRoomPrivate::moveTransientMessageToWeakMessages (shared_ptr msg) { +void ChatRoomPrivate::removeTransientMessage (const shared_ptr &msg) { auto iter = find(transientMessages.begin(), transientMessages.end(), msg); if (iter != transientMessages.end()) { transientMessages.erase(iter); @@ -378,10 +378,27 @@ list > ChatRoomPrivate::findMessages (const string &mess return result; } -void ChatRoomPrivate::storeOrUpdateMessage (shared_ptr msg) { +void ChatRoomPrivate::storeOrUpdateMessage (const shared_ptr &msg) { msg->store(); } +void ChatRoomPrivate::sendMessage (const shared_ptr &msg) { + msg->getPrivate()->setDirection(ChatMessage::Direction::Outgoing); + + /* Add to transient list */ + addTransientMessage(msg); + + msg->getPrivate()->setTime(ms_time(0)); + msg->getPrivate()->send(); + + storeOrUpdateMessage(msg); + + if (isComposing) + isComposing = false; + isComposingHandler.stopIdleTimer(); + isComposingHandler.stopRefreshTimer(); +} + // ----------------------------------------------------------------------------- LinphoneReason ChatRoomPrivate::messageReceived (SalOp *op, const SalMessage *salMsg) { @@ -460,7 +477,7 @@ end: // ----------------------------------------------------------------------------- -void ChatRoomPrivate::chatMessageReceived (shared_ptr msg) { +void ChatRoomPrivate::chatMessageReceived (const shared_ptr &msg) { L_Q(); if ((msg->getPrivate()->getContentType() != ContentType::Imdn) && (msg->getPrivate()->getContentType() != ContentType::ImIsComposing)) { notifyChatMessageReceived(msg); @@ -481,7 +498,7 @@ void ChatRoomPrivate::isComposingReceived (const string &text) { // ----------------------------------------------------------------------------- -void ChatRoomPrivate::notifyChatMessageReceived (shared_ptr msg) { +void ChatRoomPrivate::notifyChatMessageReceived (const shared_ptr &msg) { L_Q(); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); if (!msg->getPrivate()->getText().empty()) { @@ -504,7 +521,7 @@ void ChatRoomPrivate::notifyStateChanged () { cb(cr, (LinphoneChatRoomState)state); } -void ChatRoomPrivate::notifyUndecryptableMessageReceived (shared_ptr msg) { +void ChatRoomPrivate::notifyUndecryptableMessageReceived (const shared_ptr &msg) { L_Q(); LinphoneChatRoom *cr = L_GET_C_BACK_PTR(q); LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); @@ -598,7 +615,7 @@ void ChatRoom::deleteHistory () { if (d->unreadCount > 0) d->unreadCount = 0; } -void ChatRoom::deleteMessage (shared_ptr msg) { +void ChatRoom::deleteMessage (const shared_ptr &msg) { L_D(); if (!d->core->db) return; char *buf = sqlite3_mprintf("DELETE FROM history WHERE id = %u;", msg->getPrivate()->getStorageId()); @@ -734,25 +751,6 @@ void ChatRoom::markAsRead () { d->unreadCount = 0; } -void ChatRoom::sendMessage (shared_ptr msg) { - L_D(); - - msg->getPrivate()->setDirection(ChatMessage::Direction::Outgoing); - - /* Add to transient list */ - d->addTransientMessage(msg); - - msg->getPrivate()->setTime(ms_time(0)); - msg->getPrivate()->send(); - - d->storeOrUpdateMessage(msg); - - if (d->isComposing) - d->isComposing = false; - d->isComposingHandler.stopIdleTimer(); - d->isComposingHandler.stopRefreshTimer(); -} - // ----------------------------------------------------------------------------- LinphoneCore *ChatRoom::getCore () const { diff --git a/src/chat/chat-room.h b/src/chat/chat-room.h index 09061e789..50b087edb 100644 --- a/src/chat/chat-room.h +++ b/src/chat/chat-room.h @@ -55,7 +55,7 @@ public: std::shared_ptr createMessage (const std::string &msg); std::shared_ptr createMessage (); void deleteHistory (); - void deleteMessage (std::shared_ptr msg); + void deleteMessage (const std::shared_ptr &msg); std::shared_ptr findMessage (const std::string& messageId); std::shared_ptr findMessageWithDirection (const std::string &messageId, ChatMessage::Direction direction); std::list > getHistory (int nbMessages); @@ -64,7 +64,6 @@ public: int getUnreadMessagesCount (); bool isRemoteComposing () const; void markAsRead (); - virtual void sendMessage (std::shared_ptr msg); LinphoneCore *getCore () const; diff --git a/src/chat/real-time-text-chat-room-p.h b/src/chat/real-time-text-chat-room-p.h index 78440181d..8c02770a2 100644 --- a/src/chat/real-time-text-chat-room-p.h +++ b/src/chat/real-time-text-chat-room-p.h @@ -37,10 +37,10 @@ public: public: void setCall (LinphoneCall *call) { this->call = call; } - -public: void realtimeTextReceived (uint32_t character, LinphoneCall *call); + void sendMessage (const std::shared_ptr &msg) override; + public: LinphoneCall *call = nullptr; std::list receivedRttCharacters; diff --git a/src/chat/real-time-text-chat-room.cpp b/src/chat/real-time-text-chat-room.cpp index fbff72412..d62eb31de 100644 --- a/src/chat/real-time-text-chat-room.cpp +++ b/src/chat/real-time-text-chat-room.cpp @@ -100,20 +100,17 @@ void RealTimeTextChatRoomPrivate::realtimeTextReceived (uint32_t character, Linp } } -// ============================================================================= - -RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {} - -// ----------------------------------------------------------------------------- - -void RealTimeTextChatRoom::sendMessage (std::shared_ptr msg) { - L_D(); - if (d->call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(d->call))) { +void RealTimeTextChatRoomPrivate::sendMessage (const std::shared_ptr &msg) { + if (call && linphone_call_params_realtime_text_enabled(linphone_call_get_current_params(call))) { uint32_t new_line = 0x2028; msg->putCharacter(new_line); } } +// ============================================================================= + +RealTimeTextChatRoom::RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress) : ChatRoom(*new RealTimeTextChatRoomPrivate(core, peerAddress)) {} + // ----------------------------------------------------------------------------- uint32_t RealTimeTextChatRoom::getChar () const { diff --git a/src/chat/real-time-text-chat-room.h b/src/chat/real-time-text-chat-room.h index ad2f12d37..52c0993ef 100644 --- a/src/chat/real-time-text-chat-room.h +++ b/src/chat/real-time-text-chat-room.h @@ -38,8 +38,6 @@ public: RealTimeTextChatRoom (LinphoneCore *core, const Address &peerAddress); virtual ~RealTimeTextChatRoom () = default; - void sendMessage (std::shared_ptr msg) override; - uint32_t getChar () const; LinphoneCall *getCall () const; diff --git a/tester/cpim-tester.cpp b/tester/cpim-tester.cpp index 191792e57..35af930bc 100644 --- a/tester/cpim-tester.cpp +++ b/tester/cpim-tester.cpp @@ -257,7 +257,7 @@ static void parse_rfc_example () { const string str2 = message->asString(); BC_ASSERT_STRING_EQUAL(str2.c_str(), str.c_str()); - + string content = message->getContent(); BC_ASSERT_STRING_EQUAL(content.c_str(), body.c_str()); } @@ -283,7 +283,7 @@ static void parse_message_with_generic_header_parameters () { const string str2 = message->asString(); BC_ASSERT_STRING_EQUAL(str2.c_str(), str.c_str()); - + string content = message->getContent(); BC_ASSERT_STRING_EQUAL(content.c_str(), body.c_str()); } @@ -346,7 +346,7 @@ static void build_message () { if (!BC_ASSERT_TRUE(contentTypeHeader.setName("Content-Type"))) return; if (!BC_ASSERT_TRUE( contentTypeHeader.setValue("text/xml; charset=utf-8"))) return; if (!BC_ASSERT_TRUE(message.addContentHeader(contentTypeHeader))) return; - + Cpim::GenericHeader contentIdHeader; if (!BC_ASSERT_TRUE(contentIdHeader.setName("Content-ID"))) return; if (!BC_ASSERT_TRUE( contentIdHeader.setValue("<1234567890@foo.com>"))) return; @@ -398,11 +398,11 @@ static void cpim_chat_message_modifier_base(bool_t use_multipart) { content.setBody("Hello Part 2"); marieMessage->addContent(content); } - marieRoom->sendMessage(marieMessage); + marieMessage->send(); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1)); BC_ASSERT_TRUE(marieMessage->getInternalContent().getContentType() == ContentType::Cpim); - + BC_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_chat_message); if (pauline->stat.last_received_chat_message != NULL) { BC_ASSERT_STRING_EQUAL(linphone_chat_message_get_text(pauline->stat.last_received_chat_message), "Hello CPIM"); diff --git a/tester/multipart-tester.cpp b/tester/multipart-tester.cpp index 470b05bd7..b02ea3f4f 100644 --- a/tester/multipart-tester.cpp +++ b/tester/multipart-tester.cpp @@ -51,11 +51,11 @@ static void chat_message_multipart_modifier_base(bool first_file_transfer, bool content.setBody("Hello Part 2"); marieMessage->addContent(content); } - marieRoom->sendMessage(marieMessage); + marieMessage->send(); BC_ASSERT_TRUE(wait_for(pauline->lc,marie->lc,&pauline->stat.number_of_LinphoneMessageReceived,1)); BC_ASSERT_STRING_EQUAL(marieMessage->getInternalContent().getContentType().asString().c_str(), "multipart/mixed"); - + BC_ASSERT_PTR_NOT_NULL(pauline->stat.last_received_chat_message); //TODO