Do not automatically select chat when it is added in list because of its Created state, only force selection when user is manually creating it

This commit is contained in:
Gaelle Braud 2026-01-22 17:08:25 +01:00
parent 41b2086b66
commit 770ed045e5
6 changed files with 18 additions and 7 deletions

View file

@ -150,7 +150,7 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
return; return;
} }
auto chatCore = ChatCore::create(room); auto chatCore = ChatCore::create(room);
mModelConnection->invokeToCore([this, chatCore] { addChatInList(chatCore); }); mModelConnection->invokeToCore([this, chatCore] { addChatInList(chatCore, false); });
}; };
mModelConnection->makeConnectToModel(&CoreModel::messageReceived, mModelConnection->makeConnectToModel(&CoreModel::messageReceived,
[this, addChatToList](const std::shared_ptr<linphone::Core> &core, [this, addChatToList](const std::shared_ptr<linphone::Core> &core,
@ -178,6 +178,11 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
[this, addChatToList](const std::shared_ptr<linphone::Core> &core, [this, addChatToList](const std::shared_ptr<linphone::Core> &core,
const std::shared_ptr<linphone::ChatRoom> &chatRoom, linphone::ChatRoom::State state) { const std::shared_ptr<linphone::ChatRoom> &chatRoom, linphone::ChatRoom::State state) {
if (state == linphone::ChatRoom::State::Created) { if (state == linphone::ChatRoom::State::Created) {
bool sendAddSignal = false;
if (chatRoom == CoreModel::getInstance()->mChatRoomBeingCreated) {
sendAddSignal = true;
}
CoreModel::getInstance()->mChatRoomBeingCreated = nullptr;
if (chatRoom->getConferenceInfo()) { if (chatRoom->getConferenceInfo()) {
qWarning() << log().arg("Chatroom created during a conference, return"); qWarning() << log().arg("Chatroom created during a conference, return");
return; return;
@ -191,7 +196,8 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
return; return;
} }
auto chatCore = ChatCore::create(chatRoom); auto chatCore = ChatCore::create(chatRoom);
mModelConnection->invokeToCore([this, chatCore] { addChatInList(chatCore); }); mModelConnection->invokeToCore(
[this, chatCore, sendAddSignal] { addChatInList(chatCore, sendAddSignal); });
} }
}); });
@ -212,7 +218,7 @@ int ChatList::findChatIndex(ChatGui *chatGui) {
return it == chatList.end() ? -1 : std::distance(chatList.begin(), it); return it == chatList.end() ? -1 : std::distance(chatList.begin(), it);
} }
bool ChatList::addChatInList(QSharedPointer<ChatCore> chatCore) { bool ChatList::addChatInList(QSharedPointer<ChatCore> chatCore, bool emitAddSignal) {
mustBeInMainThread(log().arg(Q_FUNC_INFO)); mustBeInMainThread(log().arg(Q_FUNC_INFO));
if (chatCore->getIdentifier().isEmpty()) { if (chatCore->getIdentifier().isEmpty()) {
qWarning() << "ChatRoom with invalid identifier cannot be added to the list, return"; qWarning() << "ChatRoom with invalid identifier cannot be added to the list, return";
@ -225,7 +231,7 @@ bool ChatList::addChatInList(QSharedPointer<ChatCore> chatCore) {
if (it == chatList.end()) { if (it == chatList.end()) {
connectItem(chatCore); connectItem(chatCore);
add(chatCore); add(chatCore);
emit chatAdded(chatCore); if (emitAddSignal) emit chatAdded(chatCore);
return true; return true;
} }
return false; return false;

View file

@ -42,7 +42,7 @@ public:
void connectItem(QSharedPointer<ChatCore> chat); void connectItem(QSharedPointer<ChatCore> chat);
int findChatIndex(ChatGui *chat); int findChatIndex(ChatGui *chat);
bool addChatInList(QSharedPointer<ChatCore> chatCore); bool addChatInList(QSharedPointer<ChatCore> chatCore, bool emitAddSignal);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
signals: signals:

View file

@ -72,7 +72,7 @@ int ChatProxy::findChatIndex(ChatGui *chatGui) {
bool ChatProxy::addChatInList(ChatGui *chatGui) { bool ChatProxy::addChatInList(ChatGui *chatGui) {
auto chatList = dynamic_cast<ChatList *>(sourceModel()); auto chatList = dynamic_cast<ChatList *>(sourceModel());
if (chatList && chatGui) { if (chatList && chatGui) {
return chatList->addChatInList(chatGui->mCore); return chatList->addChatInList(chatGui->mCore, true);
} }
return false; return false;
} }

View file

@ -79,6 +79,9 @@ public:
bool mEnd = false; bool mEnd = false;
linphone::ConfiguringState mConfigStatus; linphone::ConfiguringState mConfigStatus;
QString mConfigMessage; QString mConfigMessage;
// Used to get a chatroom created by user when trying to add
// one to the chat room list, so we can automatically select it
std::shared_ptr<linphone::ChatRoom> mChatRoomBeingCreated;
std::shared_ptr<linphone::Core> mCore; std::shared_ptr<linphone::Core> mCore;
std::shared_ptr<LoggerModel> mLogger; std::shared_ptr<LoggerModel> mLogger;

View file

@ -757,6 +757,7 @@ std::shared_ptr<linphone::ChatRoom> ToolModel::createChatForAddress(std::shared_
return nullptr; return nullptr;
} }
auto chatRoom = core->createChatRoom(params, participants); auto chatRoom = core->createChatRoom(params, participants);
CoreModel::getInstance()->mChatRoomBeingCreated = chatRoom;
return chatRoom; return chatRoom;
} }
@ -784,6 +785,7 @@ ToolModel::createGroupChatRoom(QString subject, std::list<std::shared_ptr<linpho
auto chatRoom = core->createChatRoom(params, participantsAddresses); auto chatRoom = core->createChatRoom(params, participantsAddresses);
if (!chatRoom) lWarning() << ("[ToolModel] Failed to create group chat"); if (!chatRoom) lWarning() << ("[ToolModel] Failed to create group chat");
CoreModel::getInstance()->mChatRoomBeingCreated = chatRoom;
return chatRoom; return chatRoom;
} }

View file

@ -60,7 +60,7 @@ ListView {
} }
} }
onChatAdded: (chat) => { onChatAdded: (chat) => {
// mainItem.chatToSelect = chat mainItem.chatToSelect = chat
} }
onRowsRemoved: { onRowsRemoved: {
var index = mainItem.currentIndex var index = mainItem.currentIndex