fix #LINQT-1860 refresh unread count on chatroom marked as read

This commit is contained in:
Gaelle Braud 2025-07-29 14:36:46 +02:00
parent e90869c781
commit 521240cfd6
3 changed files with 16 additions and 16 deletions

View file

@ -139,7 +139,6 @@ ChatCore::ChatCore(const std::shared_ptr<linphone::ChatRoom> &chatRoom) : QObjec
ChatCore::~ChatCore() { ChatCore::~ChatCore() {
lDebug() << "[ChatCore] delete" << this; lDebug() << "[ChatCore] delete" << this;
mustBeInMainThread("~" + getClassName()); mustBeInMainThread("~" + getClassName());
mChatModelConnection->disconnect();
emit mChatModel->removeListener(); emit mChatModel->removeListener();
} }
@ -670,7 +669,6 @@ void ChatCore::updateInfo(const std::shared_ptr<linphone::Friend> &updatedFriend
if (isThisFriend) { if (isThisFriend) {
if (isRemoval) { if (isRemoval) {
mFriendModel = nullptr; mFriendModel = nullptr;
mFriendModelConnection = nullptr;
} }
int capabilities = mChatModel->getCapabilities(); int capabilities = mChatModel->getCapabilities();
auto chatroom = mChatModel->getMonitor(); auto chatroom = mChatModel->getMonitor();

View file

@ -214,7 +214,6 @@ private:
std::shared_ptr<FriendModel> mFriendModel; std::shared_ptr<FriendModel> mFriendModel;
QSharedPointer<SafeConnection<ChatCore, ChatModel>> mChatModelConnection; QSharedPointer<SafeConnection<ChatCore, ChatModel>> mChatModelConnection;
QSharedPointer<SafeConnection<ChatCore, CoreModel>> mCoreModelConnection; QSharedPointer<SafeConnection<ChatCore, CoreModel>> mCoreModelConnection;
QSharedPointer<SafeConnection<ChatCore, FriendModel>> mFriendModelConnection;
DECLARE_ABSTRACT_OBJECT DECLARE_ABSTRACT_OBJECT
}; };

View file

@ -69,14 +69,17 @@ void ChatList::connectItem(QSharedPointer<ChatCore> chat) {
emit dataChanged(modelIndex, modelIndex); emit dataChanged(modelIndex, modelIndex);
} }
}; };
connect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, dataChange); connect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, [this, dataChange] {
dataChange();
auto defaultAccount = App::getInstance()->getAccountList()->getDefaultAccountCore();
if (defaultAccount) emit defaultAccount->lRefreshNotifications();
});
connect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, dataChange); connect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, dataChange);
connect(chat.get(), &ChatCore::lastMessageChanged, this, dataChange); connect(chat.get(), &ChatCore::lastMessageChanged, this, dataChange);
} }
void ChatList::setSelf(QSharedPointer<ChatList> me) { void ChatList::setSelf(QSharedPointer<ChatList> me) {
mModelConnection = SafeConnection<ChatList, CoreModel>::create(me, CoreModel::getInstance()); mModelConnection = SafeConnection<ChatList, CoreModel>::create(me, CoreModel::getInstance());
mModelConnection->makeConnectToCore(&ChatList::lUpdate, [this]() { mModelConnection->makeConnectToCore(&ChatList::lUpdate, [this]() {
mModelConnection->invokeToModel([this]() { mModelConnection->invokeToModel([this]() {
mustBeInLinphoneThread(getClassName()); mustBeInLinphoneThread(getClassName());
@ -102,11 +105,11 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
connectItem(chat); connectItem(chat);
} }
mustBeInMainThread(getClassName()); mustBeInMainThread(getClassName());
clearData(); clearData();
for(auto chat: *chats) { for (auto chat : *chats) {
add(chat); add(chat);
} }
delete chats; delete chats;
}); });
}); });
}); });
@ -118,21 +121,21 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
const std::shared_ptr<linphone::ChatRoom> &room, const std::shared_ptr<linphone::ChatRoom> &room,
const std::shared_ptr<linphone::ChatMessage> &message) { const std::shared_ptr<linphone::ChatMessage> &message) {
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
auto receiverAccount = ToolModel::findAccount(message->getToAddress()); auto receiverAddress = message->getToAddress();
if (!receiverAccount) {
qWarning() << log().arg("Receiver account not found in account list, return");
return;
}
auto receiverAddress = receiverAccount->getContactAddress();
if (!receiverAddress) { if (!receiverAddress) {
qWarning() << log().arg("Receiver account has no address, return"); qWarning() << log().arg("Receiver account has no address, return");
return; return;
} }
auto senderAddress = message->getFromAddress();
auto defaultAddress = core->getDefaultAccount()->getContactAddress(); auto defaultAddress = core->getDefaultAccount()->getContactAddress();
if (!defaultAddress->weakEqual(receiverAddress)) { if (!defaultAddress->weakEqual(receiverAddress)) {
qDebug() << log().arg("Receiver account is not the default one, do not add chat to list"); qDebug() << log().arg("Receiver account is not the default one, do not add chat to list");
return; return;
} }
if (defaultAddress->weakEqual(senderAddress)) {
qDebug() << log().arg("Sender account is the default one, do not add chat to list");
return;
}
auto chatCore = ChatCore::create(room); auto chatCore = ChatCore::create(room);
mModelConnection->invokeToCore([this, chatCore] { mModelConnection->invokeToCore([this, chatCore] {