fix crash

fix add chat to list if first message received
This commit is contained in:
Gaelle Braud 2025-06-24 15:54:36 +02:00
parent 61fecd8c93
commit a7e39ab276
6 changed files with 82 additions and 19 deletions

View file

@ -206,7 +206,7 @@ set(ENABLE_CSHARP_WRAPPER OFF CACHE BOOL "Build the CSharp wrapper for Liblinpho
set(ENABLE_THEORA OFF) set(ENABLE_THEORA OFF)
set(ENABLE_QT_GL ${ENABLE_VIDEO}) set(ENABLE_QT_GL ${ENABLE_VIDEO})
find_package(Qt6 REQUIRED COMPONENTS Core Widgets Core5Compat) find_package(Qt6 REQUIRED COMPONENTS Core Quick Widgets Core5Compat)
if(NOT Qt6_FOUND) if(NOT Qt6_FOUND)
message(FATAL_ERROR "Minimum supported Qt6!") message(FATAL_ERROR "Minimum supported Qt6!")

View file

@ -69,6 +69,7 @@ void ChatList::connectItem(QSharedPointer<ChatCore> chat) {
}; };
connect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, dataChange); connect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, dataChange);
connect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, dataChange); connect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, dataChange);
connect(chat.get(), &ChatCore::lastMessageChanged, this, dataChange);
} }
void ChatList::setSelf(QSharedPointer<ChatList> me) { void ChatList::setSelf(QSharedPointer<ChatList> me) {
@ -80,6 +81,7 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
// Avoid copy to lambdas // Avoid copy to lambdas
QList<QSharedPointer<ChatCore>> *chats = new QList<QSharedPointer<ChatCore>>(); QList<QSharedPointer<ChatCore>> *chats = new QList<QSharedPointer<ChatCore>>();
auto currentAccount = CoreModel::getInstance()->getCore()->getDefaultAccount(); auto currentAccount = CoreModel::getInstance()->getCore()->getDefaultAccount();
if (!currentAccount) return;
auto linphoneChatRooms = currentAccount->filterChatRooms(Utils::appStringToCoreString(mFilter)); auto linphoneChatRooms = currentAccount->filterChatRooms(Utils::appStringToCoreString(mFilter));
for (auto it : linphoneChatRooms) { for (auto it : linphoneChatRooms) {
auto model = createChatCore(it); auto model = createChatCore(it);
@ -91,6 +93,7 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
disconnect(chat.get(), &ChatCore::deleted, this, nullptr); disconnect(chat.get(), &ChatCore::deleted, this, nullptr);
disconnect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, nullptr); disconnect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, nullptr); disconnect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::lastMessageChanged, this, nullptr);
} }
} }
for (auto &chat : *chats) { for (auto &chat : *chats) {
@ -106,6 +109,64 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
mModelConnection->makeConnectToModel( mModelConnection->makeConnectToModel(
&CoreModel::defaultAccountChanged, &CoreModel::defaultAccountChanged,
[this](std::shared_ptr<linphone::Core> core, std::shared_ptr<linphone::Account> account) { lUpdate(); }); [this](std::shared_ptr<linphone::Core> core, std::shared_ptr<linphone::Account> account) { lUpdate(); });
mModelConnection->makeConnectToModel(
&CoreModel::messageReceived,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::ChatRoom> &room,
const std::shared_ptr<linphone::ChatMessage> &message) {
auto chatCore = ChatCore::create(room);
mModelConnection->invokeToCore([this, chatCore] {
auto chatList = getSharedList<ChatCore>();
auto it =
std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer<ChatCore> item) {
return item && chatCore && item->getModel() && chatCore->getModel() &&
item->getModel()->getMonitor() == chatCore->getModel()->getMonitor();
});
if (it == chatList.end()) {
connectItem(chatCore);
add(chatCore);
emit chatAdded();
}
});
});
mModelConnection->makeConnectToModel(
&CoreModel::messagesReceived,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::ChatRoom> &room,
const std::list<std::shared_ptr<linphone::ChatMessage>> &messages) {
auto chatCore = ChatCore::create(room);
mModelConnection->invokeToCore([this, chatCore] {
auto chatList = getSharedList<ChatCore>();
auto it =
std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer<ChatCore> item) {
return item && chatCore && item->getModel() && chatCore->getModel() &&
item->getModel()->getMonitor() == chatCore->getModel()->getMonitor();
});
if (it == chatList.end()) {
connectItem(chatCore);
add(chatCore);
emit chatAdded();
}
});
});
mModelConnection->makeConnectToModel(
&CoreModel::newMessageReaction,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::ChatRoom> &room,
const std::shared_ptr<linphone::ChatMessage> &message,
const std::shared_ptr<const linphone::ChatMessageReaction> &reaction) {
auto chatCore = ChatCore::create(room);
mModelConnection->invokeToCore([this, chatCore] {
auto chatList = getSharedList<ChatCore>();
auto it =
std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer<ChatCore> item) {
return item && chatCore && item->getModel() && chatCore->getModel() &&
item->getModel()->getMonitor() == chatCore->getModel()->getMonitor();
});
if (it == chatList.end()) {
connectItem(chatCore);
add(chatCore);
emit chatAdded();
}
});
});
connect(this, &ChatList::filterChanged, [this](QString filter) { connect(this, &ChatList::filterChanged, [this](QString filter) {
mFilter = filter; mFilter = filter;
@ -128,7 +189,8 @@ void ChatList::addChatInList(ChatGui *chatGui) {
auto chatCore = chatGui->mCore; auto chatCore = chatGui->mCore;
auto chatList = getSharedList<ChatCore>(); auto chatList = getSharedList<ChatCore>();
auto it = std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer<ChatCore> item) { auto it = std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer<ChatCore> item) {
return item->getIdentifier() == chatCore->getIdentifier(); return item && chatCore && item->getModel() && chatCore->getModel() &&
item->getModel()->getMonitor() == chatCore->getModel()->getMonitor();
}); });
if (it == chatList.end()) { if (it == chatList.end()) {
connectItem(chatCore); connectItem(chatCore);

View file

@ -164,7 +164,6 @@ bool Notifier::createNotification(Notifier::NotificationType type, QVariantMap d
engine->deleteLater(); engine->deleteLater();
exit(-1); exit(-1);
} else { } else {
lDebug() << engine->rootObjects()[0];
auto window = qobject_cast<QQuickWindow *>(obj); auto window = qobject_cast<QQuickWindow *>(obj);
if (window) { if (window) {
window->setProperty(NotificationPropertyData, data); window->setProperty(NotificationPropertyData, data);

View file

@ -150,6 +150,8 @@ QString LinphoneEnums::toString(const LinphoneEnums::ChatMessageState &data) {
case LinphoneEnums::ChatMessageState::StateFileTransferCancelling: case LinphoneEnums::ChatMessageState::StateFileTransferCancelling:
//: file transfer canceled //: file transfer canceled
return QObject::tr("message_state_file_transfer_cancelling"); return QObject::tr("message_state_file_transfer_cancelling");
default:
return QString();
} }
} }

View file

@ -17,12 +17,12 @@ Notification {
property var chat: notificationData ? notificationData.chat : null property var chat: notificationData ? notificationData.chat : null
property string avatarUri: notificationData ? notificationData.avatarUri : "" property string avatarUri: notificationData?.avatarUri? notificationData.avatarUri : ""
property string chatRoomName: notificationData ? notificationData.chatRoomName : "" property string chatRoomName: notificationData?.chatRoomName ? notificationData.chatRoomName : ""
property string remoteAddress: notificationData ? notificationData.remoteAddress : "" property string remoteAddress: notificationData?.remoteAddress ? notificationData.remoteAddress : ""
property string chatRoomAddress: notificationData ? notificationData.chatRoomAddress : "" property string chatRoomAddress: notificationData?.chatRoomAddress ? notificationData.chatRoomAddress : ""
property bool isGroupChat: notificationData ? notificationData.isGroupChat : false property bool isGroupChat: notificationData?.isGroupChat ? notificationData.isGroupChat : false
property string message: notificationData ? notificationData.message : "" property string message: notificationData?.message ? notificationData.message : ""
Connections { Connections {
enabled: chat enabled: chat
target: chat ? chat.core : null target: chat ? chat.core : null