Create a secure chat room when calling someone with standard chat deactivated.

This commit is contained in:
Julien Wadel 2022-07-28 20:05:31 +02:00
parent 3f6ae60cde
commit 5d7894e400
4 changed files with 40 additions and 15 deletions

View file

@ -27,6 +27,7 @@
#include "app/App.hpp" #include "app/App.hpp"
#include "CallListener.hpp" #include "CallListener.hpp"
#include "components/calls/CallsListModel.hpp" #include "components/calls/CallsListModel.hpp"
#include "components/chat-room/ChatRoomListener.hpp"
#include "components/chat-room/ChatRoomModel.hpp" #include "components/chat-room/ChatRoomModel.hpp"
#include "components/conference/ConferenceModel.hpp" #include "components/conference/ConferenceModel.hpp"
#include "components/conferenceInfo/ConferenceInfoModel.hpp" #include "components/conferenceInfo/ConferenceInfoModel.hpp"
@ -54,6 +55,10 @@ void CallModel::connectTo(CallListener * listener){
connect(listener, &CallListener::remoteRecording, this, &CallModel::onRemoteRecording); connect(listener, &CallListener::remoteRecording, this, &CallModel::onRemoteRecording);
} }
void CallModel::connectTo(ChatRoomListener * listener){
connect(listener, &ChatRoomListener::stateChanged, this, &CallModel::onChatRoomStateChanged);
}
CallModel::CallModel (shared_ptr<linphone::Call> call){ CallModel::CallModel (shared_ptr<linphone::Call> call){
CoreManager *coreManager = CoreManager::getInstance(); CoreManager *coreManager = CoreManager::getInstance();
SettingsModel *settings = coreManager->getSettingsModel(); SettingsModel *settings = coreManager->getSettingsModel();
@ -76,7 +81,8 @@ CallModel::CallModel (shared_ptr<linphone::Call> call){
}else }else
settings->setCameraMode(settings->getCallCameraMode()); settings->setCameraMode(settings->getCallCameraMode());
} }
mDelayedCreationChatRoom.first = std::make_shared<ChatRoomListener>();
connectTo(mDelayedCreationChatRoom.first.get());
// Deal with auto-answer. // Deal with auto-answer.
if (!isOutgoing()) { if (!isOutgoing()) {
@ -164,15 +170,20 @@ ContactModel *CallModel::getContactModel() const{
return CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(cleanedAddress).get(); return CoreManager::getInstance()->getContactsListModel()->findContactModelFromSipAddress(cleanedAddress).get();
} }
ChatRoomModel * CallModel::getChatRoomModel() const{ ChatRoomModel * CallModel::getChatRoomModel(){
if(mCall && mCall->getCallLog()->getCallId() != "" && !mCall->getConference()) {// Conference has no chat room yet. if(mCall && mCall->getCallLog()->getCallId() != "" && !mCall->getConference()) {// Conference has no chat room yet.
auto currentParams = mCall->getCurrentParams(); auto currentParams = mCall->getCurrentParams();
bool isEncrypted = currentParams->getMediaEncryption() != linphone::MediaEncryption::None; bool isEncrypted = currentParams->getMediaEncryption() != linphone::MediaEncryption::None;
SettingsModel * settingsModel = CoreManager::getInstance()->getSettingsModel(); SettingsModel * settingsModel = CoreManager::getInstance()->getSettingsModel();
if(mDelayedCreationChatRoom.second){// We already created a chat room.
if( mDelayedCreationChatRoom.second->getState() == linphone::ChatRoom::State::Created)
return CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(mDelayedCreationChatRoom.second, true).get();
else// Chat room is not yet created.
return nullptr;
}
if( mCall->getChatRoom() && (settingsModel->getSecureChatEnabled() && if( mCall->getChatRoom() && (settingsModel->getSecureChatEnabled() &&
(!settingsModel->getStandardChatEnabled() || (settingsModel->getStandardChatEnabled() && isEncrypted)) (!settingsModel->getStandardChatEnabled() || (settingsModel->getStandardChatEnabled() && isEncrypted))
)){ )){// Make a secure chat
std::shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); std::shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
std::shared_ptr<const linphone::ChatRoomParams> dbParams = mCall->getChatRoom()->getCurrentParams(); std::shared_ptr<const linphone::ChatRoomParams> dbParams = mCall->getChatRoom()->getCurrentParams();
std::shared_ptr<linphone::ChatRoomParams> params = core->createDefaultChatRoomParams(); std::shared_ptr<linphone::ChatRoomParams> params = core->createDefaultChatRoomParams();
@ -181,13 +192,13 @@ ChatRoomModel * CallModel::getChatRoomModel() const{
std::list<std::shared_ptr<linphone::Address>> participants; std::list<std::shared_ptr<linphone::Address>> participants;
std::shared_ptr<linphone::ChatRoom> chatRoom; std::shared_ptr<linphone::ChatRoom> chatRoom;
// Copy parameters // Copy parameters
params->setBackend(dbParams->getBackend()); params->enableEncryption(true);
params->setEncryptionBackend(dbParams->getEncryptionBackend());
params->enableEncryption(dbParams->encryptionEnabled());
params->enableGroup(dbParams->groupEnabled()); params->enableGroup(dbParams->groupEnabled());
params->enableRtt(dbParams->rttEnabled()); params->enableRtt(dbParams->rttEnabled());
params->setSubject(dbParams->getSubject()); if( dbParams->getSubject() == "") // A linphone::ChatRoomBackend::FlexisipChat need a subject.
params->enableEncryption(true); params->setSubject("Dummy Subject");
else
params->setSubject(dbParams->getSubject());
std::list<std::shared_ptr<linphone::Participant>> chatRoomParticipants = mCall->getChatRoom()->getParticipants(); std::list<std::shared_ptr<linphone::Participant>> chatRoomParticipants = mCall->getChatRoom()->getParticipants();
for(auto p : chatRoomParticipants){ for(auto p : chatRoomParticipants){
participants.push_back(p->getAddress()->clone()); participants.push_back(p->getAddress()->clone());
@ -197,8 +208,13 @@ ChatRoomModel * CallModel::getChatRoomModel() const{
, participants); , participants);
if(chatRoom) if(chatRoom)
return CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(chatRoom, true).get(); return CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(chatRoom, true).get();
} else{// Wait for creation. Secure chat rooms cannot be used before being created.
return CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(mCall->getChatRoom(), true).get(); mDelayedCreationChatRoom.second = CoreManager::getInstance()->getCore()->createChatRoom(params, callLocalAddress, participants);// The result cannot be used.
mDelayedCreationChatRoom.second->addListener(mDelayedCreationChatRoom.first);
return nullptr;
}
}else
return CoreManager::getInstance()->getTimelineListModel()->getChatRoomModel(mCall->getChatRoom(), true).get();
}else }else
return nullptr; return nullptr;
} }
@ -921,6 +937,11 @@ void CallModel::onRemoteRecording(const std::shared_ptr<linphone::Call> & call,
emit remoteRecordingChanged(recording); emit remoteRecordingChanged(recording);
} }
void CallModel::onChatRoomStateChanged(const std::shared_ptr<linphone::ChatRoom> & chatRoom, linphone::ChatRoom::State newState){
if(newState == linphone::ChatRoom::State::Created)// A chat room has been created for the call. Warn listeners that the model changed.
emit chatRoomModelChanged();
}
void CallModel::setRemoteDisplayName(const std::string& name){ void CallModel::setRemoteDisplayName(const std::string& name){
mRemoteAddress->setDisplayName(name); mRemoteAddress->setDisplayName(name);
if(mCall) { if(mCall) {

View file

@ -33,6 +33,7 @@ class CallListener;
class ConferenceInfoModel; class ConferenceInfoModel;
class ConferenceModel; class ConferenceModel;
class ContactModel; class ContactModel;
class ChatRoomListener;
class ChatRoomModel; class ChatRoomModel;
class CallModel : public QObject { class CallModel : public QObject {
@ -126,7 +127,7 @@ public:
std::shared_ptr<linphone::Address> getConferenceAddress () const; std::shared_ptr<linphone::Address> getConferenceAddress () const;
ContactModel *getContactModel() const; ContactModel *getContactModel() const;
ChatRoomModel * getChatRoomModel() const; ChatRoomModel * getChatRoomModel();
ConferenceModel* getConferenceModel(); ConferenceModel* getConferenceModel();
ConferenceInfoModel* getConferenceInfoModel(); ConferenceInfoModel* getConferenceInfoModel();
QSharedPointer<ConferenceModel> getConferenceSharedModel(); QSharedPointer<ConferenceModel> getConferenceSharedModel();
@ -185,6 +186,7 @@ public:
std::shared_ptr<linphone::Call> mCall; std::shared_ptr<linphone::Call> mCall;
std::shared_ptr<CallListener> mCallListener; // This is passed to linpĥone object and must be in shared_ptr std::shared_ptr<CallListener> mCallListener; // This is passed to linpĥone object and must be in shared_ptr
QPair<std::shared_ptr<ChatRoomListener>, std::shared_ptr<linphone::ChatRoom>> mDelayedCreationChatRoom; // For secure chat rooms, we need to wait till it is created by keeping a ref and by using alistener.
std::shared_ptr<linphone::Address> mRemoteAddress; std::shared_ptr<linphone::Address> mRemoteAddress;
std::shared_ptr<linphone::MagicSearch> mMagicSearch; std::shared_ptr<linphone::MagicSearch> mMagicSearch;
@ -193,6 +195,7 @@ public slots:
void searchReceived(std::list<std::shared_ptr<linphone::SearchResult>> results); void searchReceived(std::list<std::shared_ptr<linphone::SearchResult>> results);
void endCall(); void endCall();
void onRemoteRecording(const std::shared_ptr<linphone::Call> & call, bool recording); void onRemoteRecording(const std::shared_ptr<linphone::Call> & call, bool recording);
void onChatRoomStateChanged(const std::shared_ptr<linphone::ChatRoom> & chatRoom, linphone::ChatRoom::State newState);
signals: signals:
void callErrorChanged (const QString &callError); void callErrorChanged (const QString &callError);
@ -297,6 +300,7 @@ public:
private: private:
void connectTo(CallListener * listener); void connectTo(CallListener * listener);
void connectTo(ChatRoomListener * listener);
bool mIsInConference = false; bool mIsInConference = false;

View file

@ -236,7 +236,7 @@ ChatRoomModel* CallsListModel::createChat (const QString &participantAddress) co
return nullptr; return nullptr;
} }
ChatRoomModel* CallsListModel::createChat (const CallModel * model) const{ ChatRoomModel* CallsListModel::createChat (CallModel * model){
if(model){ if(model){
return model->getChatRoomModel(); return model->getChatRoomModel();
} }

View file

@ -49,7 +49,7 @@ public:
Q_INVOKABLE void launchVideoCall (const QString &sipAddress, const QString& prepareTransfertAddress = "", const bool& autoSelectAfterCreation = true, QVariantMap options = QVariantMap()) const; Q_INVOKABLE void launchVideoCall (const QString &sipAddress, const QString& prepareTransfertAddress = "", const bool& autoSelectAfterCreation = true, QVariantMap options = QVariantMap()) const;
Q_INVOKABLE QVariantMap launchChat(const QString &sipAddress, const int& securityLevel) const; Q_INVOKABLE QVariantMap launchChat(const QString &sipAddress, const int& securityLevel) const;
Q_INVOKABLE ChatRoomModel* createChat (const QString &participantAddress) const; Q_INVOKABLE ChatRoomModel* createChat (const QString &participantAddress) const;
Q_INVOKABLE ChatRoomModel* createChat (const CallModel * ) const; Q_INVOKABLE ChatRoomModel* createChat (CallModel * );
Q_INVOKABLE bool createSecureChat (const QString& subject, const QString &participantAddress) const; Q_INVOKABLE bool createSecureChat (const QString& subject, const QString &participantAddress) const;
QVariantMap createChatRoom(const QString& subject, const int& securityLevel, std::shared_ptr<linphone::Address> localAddress, const QVariantList& participants, const bool& selectAfterCreation) const; QVariantMap createChatRoom(const QString& subject, const int& securityLevel, std::shared_ptr<linphone::Address> localAddress, const QVariantList& participants, const bool& selectAfterCreation) const;