switch default account if clicking on a notification leading to a chat room from another account
This commit is contained in:
parent
da2ea7d114
commit
e0cb654746
3 changed files with 27 additions and 1 deletions
|
|
@ -108,6 +108,7 @@ ChatCore::ChatCore(const std::shared_ptr<linphone::ChatRoom> &chatRoom) : QObjec
|
||||||
mChatRoomState = LinphoneEnums::fromLinphone(chatRoom->getState());
|
mChatRoomState = LinphoneEnums::fromLinphone(chatRoom->getState());
|
||||||
mIsEncrypted = chatRoom->hasCapability((int)linphone::ChatRoom::Capabilities::Encrypted);
|
mIsEncrypted = chatRoom->hasCapability((int)linphone::ChatRoom::Capabilities::Encrypted);
|
||||||
auto localAccount = ToolModel::findAccount(chatRoom->getLocalAddress());
|
auto localAccount = ToolModel::findAccount(chatRoom->getLocalAddress());
|
||||||
|
if (localAccount) mLocalAccount = AccountCore::create(localAccount);
|
||||||
bool associatedAccountHasIMEncryptionMandatory =
|
bool associatedAccountHasIMEncryptionMandatory =
|
||||||
localAccount && localAccount->getParams() &&
|
localAccount && localAccount->getParams() &&
|
||||||
localAccount->getParams()->getInstantMessagingEncryptionMandatory();
|
localAccount->getParams()->getInstantMessagingEncryptionMandatory();
|
||||||
|
|
@ -693,6 +694,10 @@ QList<QSharedPointer<ParticipantCore>> ChatCore::getParticipants() const {
|
||||||
return mParticipants;
|
return mParticipants;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSharedPointer<AccountCore> ChatCore::getLocalAccount() const {
|
||||||
|
return mLocalAccount;
|
||||||
|
}
|
||||||
|
|
||||||
void ChatCore::updateInfo(const std::shared_ptr<linphone::Friend> &updatedFriend, bool isRemoval) {
|
void ChatCore::updateInfo(const std::shared_ptr<linphone::Friend> &updatedFriend, bool isRemoval) {
|
||||||
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
|
mustBeInLinphoneThread(log().arg(Q_FUNC_INFO));
|
||||||
auto fAddress = ToolModel::interpretUrl(mPeerAddress);
|
auto fAddress = ToolModel::interpretUrl(mPeerAddress);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
class EventLogCore;
|
class EventLogCore;
|
||||||
class FriendModel;
|
class FriendModel;
|
||||||
|
class AccountCore;
|
||||||
|
|
||||||
class ChatCore : public QObject, public AbstractObject {
|
class ChatCore : public QObject, public AbstractObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -148,6 +149,8 @@ public:
|
||||||
QVariantList getParticipantsGui() const;
|
QVariantList getParticipantsGui() const;
|
||||||
QStringList getParticipantsAddresses() const;
|
QStringList getParticipantsAddresses() const;
|
||||||
|
|
||||||
|
QSharedPointer<AccountCore> getLocalAccount() const;
|
||||||
|
|
||||||
void updateInfo(const std::shared_ptr<linphone::Friend> &updatedFriend, bool isRemoval = false);
|
void updateInfo(const std::shared_ptr<linphone::Friend> &updatedFriend, bool isRemoval = false);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
@ -222,6 +225,7 @@ private:
|
||||||
std::shared_ptr<ChatModel> mChatModel;
|
std::shared_ptr<ChatModel> mChatModel;
|
||||||
QSharedPointer<ChatMessageCore> mLastMessage;
|
QSharedPointer<ChatMessageCore> mLastMessage;
|
||||||
QList<QSharedPointer<EventLogCore>> mEventLogList;
|
QList<QSharedPointer<EventLogCore>> mEventLogList;
|
||||||
|
QSharedPointer<AccountCore> mLocalAccount;
|
||||||
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;
|
||||||
|
|
|
||||||
|
|
@ -1657,7 +1657,24 @@ void Utils::openChat(ChatGui *chat) {
|
||||||
smartShowWindow(mainWindow);
|
smartShowWindow(mainWindow);
|
||||||
if (mainWindow && chat) {
|
if (mainWindow && chat) {
|
||||||
emit chat->mCore->messageOpen();
|
emit chat->mCore->messageOpen();
|
||||||
QMetaObject::invokeMethod(mainWindow, "openChat", Q_ARG(QVariant, QVariant::fromValue(chat)));
|
auto localChatAccount = chat->mCore->getLocalAccount();
|
||||||
|
auto accountList = App::getInstance()->getAccountList();
|
||||||
|
auto defaultAccount = accountList->getDefaultAccountCore();
|
||||||
|
// If multiple accounts, we must switch to the correct account before opening the chatroom, otherwise,
|
||||||
|
// a chat room corresponding to the wrong account could be added in the chat list
|
||||||
|
if (localChatAccount && localChatAccount->getIdentityAddress() != defaultAccount->getIdentityAddress()) {
|
||||||
|
connect(accountList.get(), &AccountList::defaultAccountChanged, accountList.get(),
|
||||||
|
[localChatAccount, accountList, chat] {
|
||||||
|
auto defaultAccount = accountList->getDefaultAccountCore();
|
||||||
|
if (defaultAccount->getIdentityAddress() == localChatAccount->getIdentityAddress()) {
|
||||||
|
disconnect(accountList.get(), &AccountList::defaultAccountChanged, accountList.get(),
|
||||||
|
nullptr);
|
||||||
|
QMetaObject::invokeMethod(getMainWindow(), "openChat",
|
||||||
|
Q_ARG(QVariant, QVariant::fromValue(chat)));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
localChatAccount->lSetDefaultAccount();
|
||||||
|
} else QMetaObject::invokeMethod(mainWindow, "openChat", Q_ARG(QVariant, QVariant::fromValue(chat)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue