diff --git a/Linphone/core/chat/ChatCore.cpp b/Linphone/core/chat/ChatCore.cpp index 03abe3593..722726dd0 100644 --- a/Linphone/core/chat/ChatCore.cpp +++ b/Linphone/core/chat/ChatCore.cpp @@ -47,6 +47,7 @@ ChatCore::ChatCore(const std::shared_ptr &chatRoom) : QObjec mLastUpdatedTime = QDateTime::fromSecsSinceEpoch(chatRoom->getLastUpdateTime()); auto chatRoomAddress = chatRoom->getPeerAddress()->clone(); chatRoomAddress->clean(); + // TODO FIXME Ne pas stocker les Address sous forme de string et avoir à les re-parser en Address après, autant garder directement le shared_ptr en mémoire mChatRoomAddress = Utils::coreStringToAppString(chatRoomAddress->asStringUriOnly()); if (chatRoom->hasCapability((int)linphone::ChatRoom::Capabilities::Basic)) { mTitle = ToolModel::getDisplayName(chatRoomAddress); @@ -90,15 +91,26 @@ ChatCore::ChatCore(const std::shared_ptr &chatRoom) : QObjec static_cast(linphone::ChatRoom::HistoryFilter::InfoNoDevice) : static_cast(linphone::ChatRoom::HistoryFilter::ChatMessage); - auto history = chatRoom->getHistory(0, filter); + // TODO FIXME Tu récupère l'historique entier de chaque chat room qui est mise dans la liste, du coup ça prend du temps + // et potentiellement ça sert a rien si l'utilisateur va jamais dedans. + // Peut-être il faudrait un ChatListCore/ChatListModel pour juste la partie liste ? + + // TODO FIXME Aussi il ne faut pas tout charger mais uniquement mettons les 30 derniers messages + // et les charger à la volée quand l'utilisateur scrolle vers le haut + + // Dernière question : pourquoi bouger les eventLog depuis history dans lHistory et pas faire directement + // lHistory = chatRoom->getHistory(0, filter); ? + auto history = chatRoom->getHistory(30, filter); std::list> lHistory; for (auto &eventLog : history) { lHistory.push_back(eventLog); } + QList> eventList; for (auto &event : lHistory) { auto eventLogCore = EventLogCore::create(event); eventList.append(eventLogCore); + // TODO faudra que tu m'expliques pourquoi tu as besoin de cette liste des fichiers de chaque message de la chat room if (auto isMessage = eventLogCore->getChatMessageCore()) { for (auto content : isMessage->getChatMessageContentList()) { if (content->isFile() && !content->isVoiceRecording()) { @@ -258,6 +270,7 @@ void ChatCore::setSelf(QSharedPointer me) { auto event = EventLogCore::create(e); list.push_back(event); } + // TODO FIXME On devrait déjà être dans le thread du Core ici, du coup je pense que c'est pas nécessaire mChatModelConnection->invokeToCore([this, list]() { appendEventLogsToEventLogList(list); emit lUpdateUnreadCount(); @@ -723,6 +736,7 @@ QSharedPointer ChatCore::getLocalAccount() const { void ChatCore::updateInfo(const std::shared_ptr &updatedFriend, bool isRemoval) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); + // TODO FIXME Je sais pas quand UpdateInfo() est appelé ni pourquoi mais le check sur la peerAddress ne marchera que pour les Basic auto fAddress = ToolModel::interpretUrl(mPeerAddress); bool isThisFriend = mFriendModel && updatedFriend == mFriendModel->getFriend(); if (!isThisFriend) diff --git a/Linphone/core/chat/ChatList.cpp b/Linphone/core/chat/ChatList.cpp index e34294eab..a7e86ca81 100644 --- a/Linphone/core/chat/ChatList.cpp +++ b/Linphone/core/chat/ChatList.cpp @@ -89,11 +89,14 @@ void ChatList::setSelf(QSharedPointer me) { QList> *chats = new QList>(); auto currentAccount = CoreModel::getInstance()->getCore()->getDefaultAccount(); if (!currentAccount) return; + // TODO FIXME J'ai pas réussi à trouver si c'était le cas mais il ne faut pas re-trier la liste des chat rooms renvoyée par filterChatRooms() + // Tu ne dois le faire uniquement que dans les callback onMessageSent() et onMessagesReceived() auto linphoneChatRooms = currentAccount->filterChatRooms(Utils::appStringToCoreString(mFilter)); for (auto it : linphoneChatRooms) { auto model = createChatCore(it); chats->push_back(model); } + // TODO FIXME t'es pas déjà dans le thread du core ici ? mModelConnection->invokeToCore([this, chats]() { for (auto &chat : getSharedList()) { if (chat) { @@ -139,6 +142,7 @@ void ChatList::setSelf(QSharedPointer me) { } auto chatCore = ChatCore::create(room); + // TODO FIXME t'es pas déjà dans le thread du core ici ? mModelConnection->invokeToCore([this, chatCore] { auto chatList = getSharedList(); auto it = std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer item) { @@ -163,6 +167,7 @@ void ChatList::setSelf(QSharedPointer me) { [this, addChatToList](const std::shared_ptr &core, const std::shared_ptr &room, const std::list> &messages) { + // TODO FIXME c'est normal que seul le premier des messages soit ajouté à la liste et pas tous ? addChatToList(core, room, messages.front()); }); mModelConnection->makeConnectToModel( diff --git a/Linphone/core/event-count-notifier/AbstractEventCountNotifier.cpp b/Linphone/core/event-count-notifier/AbstractEventCountNotifier.cpp index 4e49ec036..b1143ed49 100644 --- a/Linphone/core/event-count-notifier/AbstractEventCountNotifier.cpp +++ b/Linphone/core/event-count-notifier/AbstractEventCountNotifier.cpp @@ -55,10 +55,7 @@ int AbstractEventCountNotifier::getCurrentEventCount() const { else { auto currentAccount = CoreModel::getInstance()->getCore()->getDefaultAccount(); if (currentAccount) { - auto linphoneChatRooms = currentAccount->filterChatRooms(""); - for (const auto &chatRoom : linphoneChatRooms) { - count += chatRoom->getUnreadMessagesCount(); - } + count += currentAccount->getUnreadChatMessageCount(); } return count; } diff --git a/Linphone/core/notifier/Notifier.cpp b/Linphone/core/notifier/Notifier.cpp index afb573143..2c0680629 100644 --- a/Linphone/core/notifier/Notifier.cpp +++ b/Linphone/core/notifier/Notifier.cpp @@ -395,6 +395,7 @@ void Notifier::notifyReceivedMessages(const std::shared_ptr }); auto settings = SettingsModel::getInstance(); if (settings && !settings->dndEnabled()) { + // TODO FIXME on serait pas sur le mauvais thread ici ? CoreModel::getInstance()->getCore()->playLocal( Utils::appStringToCoreString(settings->getChatNotificationSoundPath())); } diff --git a/Linphone/model/account/AccountModel.cpp b/Linphone/model/account/AccountModel.cpp index 5bb044948..010835849 100644 --- a/Linphone/model/account/AccountModel.cpp +++ b/Linphone/model/account/AccountModel.cpp @@ -44,9 +44,10 @@ AccountModel::AccountModel(const std::shared_ptr &account, QO Utils::coreStringToAppString(mMonitor->getParams()->getIdentityAddress()->getDisplayName())); }); - connect(CoreModel::getInstance().get(), &CoreModel::unreadNotificationsChanged, this, [this]() { + // TODO FIXME infinite loop + /*connect(CoreModel::getInstance().get(), &CoreModel::unreadNotificationsChanged, this, [this]() { emit unreadNotificationsChanged(mMonitor->getUnreadChatMessageCount(), mMonitor->getMissedCallsCount()); - }); + });*/ connect(CoreModel::getInstance().get(), &CoreModel::accountRemoved, this, [this](const std::shared_ptr &core, const std::shared_ptr &account) { if (account == mMonitor) { diff --git a/Linphone/model/chat/ChatModel.cpp b/Linphone/model/chat/ChatModel.cpp index 8187c8e00..fc18d3420 100644 --- a/Linphone/model/chat/ChatModel.cpp +++ b/Linphone/model/chat/ChatModel.cpp @@ -52,27 +52,20 @@ QDateTime ChatModel::getLastUpdateTime() { return QDateTime::fromSecsSinceEpoch(mMonitor->getLastUpdateTime()); } -std::list> ChatModel::getHistory() const { - auto history = mMonitor->getHistory(0, (int)linphone::ChatRoom::HistoryFilter::ChatMessage); - std::list> res; - for (auto &eventLog : history) { - if (!eventLog->getChatMessage()) res.push_back(eventLog->getChatMessage()); - } - return res; -} - QString ChatModel::getIdentifier() const { return Utils::coreStringToAppString(mMonitor->getIdentifier()); } QString ChatModel::getTitle() { if (mMonitor->hasCapability((int)linphone::ChatRoom::Capabilities::Basic)) { + // TODO FIXME Ne pas cloner les addresses si possible, ça prend beaucoup de ressources ! return ToolModel::getDisplayName(mMonitor->getPeerAddress()->clone()); } else { if (mMonitor->hasCapability((int)linphone::ChatRoom::Capabilities::OneToOne)) { auto participants = mMonitor->getParticipants(); if (participants.size() > 0) { auto peer = participants.front(); + // TODO FIXME Ne pas cloner les addresses si possible, ça prend beaucoup de ressources ! return peer ? ToolModel::getDisplayName(peer->getAddress()->clone()) : ""; } else { return ""; @@ -106,9 +99,6 @@ int ChatModel::getUnreadMessagesCount() const { void ChatModel::markAsRead() { mMonitor->markAsRead(); - for (auto &message : getHistory()) { - message->markAsRead(); - } emit messagesRead(); } diff --git a/Linphone/model/chat/ChatModel.hpp b/Linphone/model/chat/ChatModel.hpp index 96bacf187..8dc0c0e1f 100644 --- a/Linphone/model/chat/ChatModel.hpp +++ b/Linphone/model/chat/ChatModel.hpp @@ -46,7 +46,6 @@ public: bool hasCapability(int capability) const; int getUnreadMessagesCount() const; void markAsRead(); - std::list> getHistory() const; QString getIdentifier() const; void deleteHistory(); void deleteMessage(std::shared_ptr message); diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index 06a4ea34f..bd6e31ad4 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -70,15 +70,6 @@ std::shared_ptr CoreModel::create(const QString &configPath, QThread } void CoreModel::start() { - mIterateTimer = new QTimer(this); - mIterateTimer->setInterval(30); - connect(mIterateTimer, &QTimer::timeout, [this]() { - static int iterateCount = 0; - if (iterateCount != 0) lCritical() << log().arg("Multi Iterate ! "); - ++iterateCount; - mCore->iterate(); - --iterateCount; - }); setPathBeforeCreation(); mCore = linphone::Factory::get()->createCore(Utils::appStringToCoreString(Paths::getConfigFilePath(mConfigPath)), @@ -122,6 +113,12 @@ void CoreModel::start() { mCore->enableFriendListSubscription(true); if (mCore->getLogCollectionUploadServerUrl().empty()) mCore->setLogCollectionUploadServerUrl(Constants::DefaultUploadLogsServer); + + mIterateTimer = new QTimer(this); + mIterateTimer->setInterval(20); + connect(mIterateTimer, &QTimer::timeout, [this]() { + mCore->iterate(); + }); mIterateTimer->start(); auto linphoneSearch = mCore->createMagicSearch(); diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index 8df490ca8..87439da2c 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -196,8 +196,8 @@ QString ToolModel::encodeTextToQmlRichFormat(const QString &text, auto foundParticipant = *it; // participants.at(std::distance(participants.begin(), it)); auto address = foundParticipant->getAddress()->clone(); - auto isFriend = findFriendByAddress(address); address->clean(); + auto isFriend = findFriendByAddress(address); auto addressString = Utils::coreStringToAppString(address->asStringUriOnly()); if (isFriend) part = "@" + Utils::coreStringToAppString(isFriend->getAddress()->getDisplayName()); @@ -221,8 +221,6 @@ QString ToolModel::encodeTextToQmlRichFormat(const QString &text, } std::shared_ptr ToolModel::findFriendByAddress(const QString &address) { - auto defaultFriendList = CoreModel::getInstance()->getCore()->getDefaultFriendList(); - if (!defaultFriendList) return nullptr; auto linphoneAddr = ToolModel::interpretUrl(address); if (linphoneAddr) return ToolModel::findFriendByAddress(linphoneAddr); else return nullptr; diff --git a/external/linphone-sdk b/external/linphone-sdk index 0802fb170..1ddbb4e93 160000 --- a/external/linphone-sdk +++ b/external/linphone-sdk @@ -1 +1 @@ -Subproject commit 0802fb170fd2458d83bfd16623ececf97d0ba7db +Subproject commit 1ddbb4e933a06fcdd9b1c968065017c36bae3da6