diff --git a/Linphone/core/chat/ChatCore.cpp b/Linphone/core/chat/ChatCore.cpp index 5970a95c3..a5a838629 100644 --- a/Linphone/core/chat/ChatCore.cpp +++ b/Linphone/core/chat/ChatCore.cpp @@ -249,6 +249,25 @@ void ChatCore::setSelf(const QSharedPointer &me) { emit lUpdateLastUpdatedTime(); }); }); + mChatModelConnection->makeConnectToModel( + &ChatModel::chatMessageSent, [this](const std::shared_ptr &chatRoom, + const std::shared_ptr &eventLog) { + if (!mChatModel) { + lWarning() << log().arg("Chat model is null !"); + return; + } else if (!mChatModelConnection) { + lWarning() << log().arg("Connection between Core and Model is null !"); + return; + } + if (mChatModel->getMonitor() != chatRoom) return; + lInfo() << log().arg("Chat message sent in chatroom") << this << mChatModel->getTitle(); + QList> list; + if (eventLog) { + emit CoreModel::getInstance()->messageSent(CoreModel::getInstance()->getCore(), chatRoom, eventLog); + } else { + lWarning() << log().arg("message sent : event log is null"); + } + }); mChatModelConnection->makeConnectToCore(&ChatCore::lMarkAsRead, [this]() { auto lastActiveWindow = Utils::getLastActiveWindow(); diff --git a/Linphone/core/chat/ChatList.cpp b/Linphone/core/chat/ChatList.cpp index 1d7d02cde..6e8c78944 100644 --- a/Linphone/core/chat/ChatList.cpp +++ b/Linphone/core/chat/ChatList.cpp @@ -154,10 +154,8 @@ void ChatList::setSelf(QSharedPointer me) { [this](std::shared_ptr core, std::shared_ptr account) { lUpdate(); }); auto addChatToList = [this](const std::shared_ptr &core, - const std::shared_ptr &room, - const std::shared_ptr &message, bool sendAddSignal = false) { + const std::shared_ptr &room, bool sendAddSignal = false) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); - // if (!message) return; if (!core->getDefaultAccount()) return; if (room->getAccount() != core->getDefaultAccount()) { qInfo() << log().arg("Chat room to add does not refer to current account, return"); @@ -182,27 +180,28 @@ void ChatList::setSelf(QSharedPointer me) { auto chatCore = ChatCore::create(room); mModelConnection->invokeToCore([this, chatCore, sendAddSignal] { addChatInList(chatCore, sendAddSignal); }); }; - mModelConnection->makeConnectToModel(&CoreModel::messageReceived, - [this, addChatToList](const std::shared_ptr &core, - const std::shared_ptr &room, - const std::shared_ptr &message) { - addChatToList(core, room, message); - }); mModelConnection->makeConnectToModel( - &CoreModel::messagesReceived, + &CoreModel::messageReceived, [this, addChatToList](const std::shared_ptr &core, const std::shared_ptr &room, - const std::list> &messages) { - addChatToList(core, room, messages.front()); + const std::shared_ptr &message) { addChatToList(core, room); }); + mModelConnection->makeConnectToModel( + &CoreModel::messagesReceived, + [this, addChatToList]( + const std::shared_ptr &core, const std::shared_ptr &room, + const std::list> &messages) { addChatToList(core, room); }); + mModelConnection->makeConnectToModel( + &CoreModel::messageSent, [this, addChatToList](const std::shared_ptr &core, + const std::shared_ptr &room, + const std::shared_ptr &eventLog) { + addChatToList(core, room, true); }); mModelConnection->makeConnectToModel( &CoreModel::newMessageReaction, - [this, addChatToList](const std::shared_ptr &core, - const std::shared_ptr &room, - const std::shared_ptr &message, - const std::shared_ptr &reaction) { - addChatToList(core, room, message); - }); + [this, addChatToList]( + const std::shared_ptr &core, const std::shared_ptr &room, + const std::shared_ptr &message, + const std::shared_ptr &reaction) { addChatToList(core, room); }); mModelConnection->makeConnectToModel(&CoreModel::chatRoomStateChanged, [this, addChatToList](const std::shared_ptr &core, const std::shared_ptr &chatRoom, @@ -212,8 +211,7 @@ void ChatList::setSelf(QSharedPointer me) { if (chatRoom == CoreModel::getInstance()->mChatRoomBeingCreated) { sendAddSignal = true; } - CoreModel::getInstance()->mChatRoomBeingCreated = nullptr; - addChatToList(core, chatRoom, nullptr, sendAddSignal); + addChatToList(core, chatRoom, sendAddSignal); } }); @@ -248,7 +246,10 @@ bool ChatList::addChatInList(QSharedPointer chatCore, bool emitAddSign connectItem(chatCore); lInfo() << "Add ChatRoom" << chatCore->getTitle(); add(chatCore); - if (emitAddSignal) emit chatAdded(chatCore); + if (emitAddSignal) { + CoreModel::getInstance()->mChatRoomBeingCreated = nullptr; + emit chatAdded(chatCore); + } return true; } return false; diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index bf04f043c..e83b61d40 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -274,6 +274,9 @@ signals: void messageReceived(const std::shared_ptr &core, const std::shared_ptr &room, const std::shared_ptr &message); + void messageSent(const std::shared_ptr &core, + const std::shared_ptr &room, + const std::shared_ptr &message); void messagesReceived(const std::shared_ptr &core, const std::shared_ptr &room, const std::list> &messages); diff --git a/Linphone/view/Control/Display/Chat/ChatListView.qml b/Linphone/view/Control/Display/Chat/ChatListView.qml index 9dded30a7..2ed45e2c5 100644 --- a/Linphone/view/Control/Display/Chat/ChatListView.qml +++ b/Linphone/view/Control/Display/Chat/ChatListView.qml @@ -99,6 +99,8 @@ ListView { if (index === -1 && force === true && chatGui) { if (chatProxy.addChatInList(chatGui)) { var index = chatProxy.findChatIndex(chatGui) + } else { + console.log("could not add chat in list !") } } mainItem.currentIndex = index diff --git a/Linphone/view/Page/Main/Chat/ChatPage.qml b/Linphone/view/Page/Main/Chat/ChatPage.qml index ebcfd9181..7de3f7dc9 100644 --- a/Linphone/view/Page/Main/Chat/ChatPage.qml +++ b/Linphone/view/Page/Main/Chat/ChatPage.qml @@ -52,6 +52,9 @@ AbstractMainPage { UtilsCpp.showInformationPopup(qsTr("info_popup_error_title"), //: Chat room creation failed ! qsTr("info_popup_chatroom_creation_failed"), false) + } else if (remoteChat.core.state === LinphoneEnums.ChatRoomState.Created) { + console.log("chat room state Created, open chat in right panel") + mainItem.selectedChatGui = remoteChat } } }