Commit d957f9f2 authored by Sébastien Blin's avatar Sébastien Blin

mainwindow: show call notification if not same account

Gitlab: #1194
Change-Id: I18a6a8f75b1819d5ddd23abf5b33b9eeb6dfe70d
parent 7dbaab90
......@@ -358,7 +358,6 @@ public:
QMetaObject::Connection showChatViewConnection_;
QMetaObject::Connection showLeaveMessageViewConnection_;
QMetaObject::Connection showCallViewConnection_;
QMetaObject::Connection showIncomingViewConnection_;
QMetaObject::Connection newTrustRequestNotification_;
QMetaObject::Connection closeTrustRequestNotification_;
QMetaObject::Connection slotNewInteraction_;
......@@ -401,7 +400,7 @@ private:
void slotAccountStatusChanged(const std::string& id);
void slotConversationCleared(const std::string& uid);
void slotModelSorted();
void slotNewIncomingCall(const std::string& callId);
void slotNewIncomingCall(const std::string& accountId, lrc::api::conversation::Info origin);
void slotCallStatusChanged(const std::string& callId);
void slotCallStarted(const std::string& callId);
void slotCallEnded(const std::string& callId);
......@@ -411,7 +410,6 @@ private:
void slotShowChatView(const std::string& id, lrc::api::conversation::Info origin);
void slotShowLeaveMessageView(lrc::api::conversation::Info conv);
void slotShowCallView(const std::string& id, lrc::api::conversation::Info origin);
void slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin);
void slotNewTrustRequest(const std::string& id, const std::string& contactUri);
void slotCloseTrustRequest(const std::string& id, const std::string& contactUri);
void slotNewInteraction(const std::string& accountId, const std::string& conversation,
......@@ -1062,6 +1060,11 @@ on_notification_accept_call(GtkWidget*, gchar *title, MainWindow* self)
priv->cpp->leaveSettingsView();
}
if (priv->cpp->accountInfo_->id.toStdString() != id) {
priv->cpp->updateLrc(id);
priv->cpp->refreshAccountSelectorWidget(-1, id);
}
try {
auto& accountInfo = priv->cpp->lrc_->getAccountModel().getAccountInfo(id.c_str());
accountInfo.callModel->accept(information.c_str());
......@@ -1477,7 +1480,6 @@ CppImpl::~CppImpl()
{
QObject::disconnect(showLeaveMessageViewConnection_);
QObject::disconnect(showChatViewConnection_);
QObject::disconnect(showIncomingViewConnection_);
QObject::disconnect(historyClearedConnection_);
QObject::disconnect(modelSortedConnection_);
QObject::disconnect(callChangedConnection_);
......@@ -1920,7 +1922,7 @@ CppImpl::forCurrentConversation(const std::function<void(const lrc::api::convers
if (conversation.participants.empty()) return;
func(conversation);
} catch (...) {
g_warning("Can't retrieve conversation %d", current);
g_warning("Can't retrieve conversation %s", current.c_str());
}
}
......@@ -1948,7 +1950,6 @@ CppImpl::updateLrc(const std::string& id, const std::string& accountIdToFlagFree
// Disconnect old signals.
QObject::disconnect(showLeaveMessageViewConnection_);
QObject::disconnect(showChatViewConnection_);
QObject::disconnect(showIncomingViewConnection_);
QObject::disconnect(showCallViewConnection_);
QObject::disconnect(newTrustRequestNotification_);
QObject::disconnect(closeTrustRequestNotification_);
......@@ -2022,9 +2023,10 @@ CppImpl::updateLrc(const std::string& id, const std::string& accountIdToFlagFree
&lrc::api::NewCallModel::callEnded,
[this] (const QString& callId) { slotCallEnded(callId.toStdString()); });
newIncomingCallConnection_ = QObject::connect(&*accountInfo_->callModel,
&lrc::api::NewCallModel::newIncomingCall,
[this] (const QString&, const QString& callId) { slotNewIncomingCall(callId.toStdString()); });
newIncomingCallConnection_ = QObject::connect(&lrc_->getBehaviorController(),
&lrc::api::BehaviorController::showIncomingCallView,
[this] (const QString& accountId, lrc::api::conversation::Info origin) {
slotNewIncomingCall(accountId.toStdString(), origin); });
filterChangedConnection_ = QObject::connect(&*accountInfo_->conversationModel,
&lrc::api::ConversationModel::filterChanged,
......@@ -2058,11 +2060,6 @@ CppImpl::updateLrc(const std::string& id, const std::string& accountIdToFlagFree
&lrc::api::BehaviorController::trustRequestTreated,
[this] (const QString& id, const QString& contactUri) { slotCloseTrustRequest(id.toStdString(), contactUri.toStdString()); });
showIncomingViewConnection_ = QObject::connect(&lrc_->getBehaviorController(),
&lrc::api::BehaviorController::showIncomingCallView,
[this] (const QString& id, lrc::api::conversation::Info origin)
{ slotShowIncomingCallView(id.toStdString(), origin); });
slotNewInteraction_ = QObject::connect(&lrc_->getBehaviorController(),
&lrc::api::BehaviorController::newUnreadInteraction,
[this] (const QString& accountId, const QString& conversation,
......@@ -2297,18 +2294,17 @@ CppImpl::slotCallEnded(const std::string& /*callId*/)
}
void
CppImpl::slotNewIncomingCall(const std::string& callId)
CppImpl::slotNewIncomingCall(const std::string& accountId, lrc::api::conversation::Info origin)
{
if (!accountInfo_) {
return;
}
if (g_settings_get_boolean(widgets->window_settings, "bring-window-to-front")) {
g_settings_set_boolean(widgets->window_settings, "show-main-window", TRUE);
}
auto callId = origin.callId;
try {
auto call = accountInfo_->callModel->getCall(callId.c_str());
auto& accountInfo = lrc_->getAccountModel().getAccountInfo(accountId.c_str());
auto call = accountInfo.callModel->getCall(callId);
auto peer = call.peerUri.remove("ring:");
auto& contactModel = accountInfo_->contactModel;
auto& contactModel = accountInfo.contactModel;
QString avatar = "", name = "", uri = "";
std::string notifId = "";
try {
......@@ -2322,9 +2318,9 @@ CppImpl::slotNewIncomingCall(const std::string& callId)
name = contactInfo.profileInfo.uri;
}
}
notifId = accountInfo_->id.toStdString() + ":call:" + callId;
notifId = accountInfo.id.toStdString() + ":call:" + callId.toStdString();
} catch (...) {
g_warning("Can't get contact for account %s. Don't show notification", qUtf8Printable(accountInfo_->id));
g_warning("Can't get contact for account %s. Don't show notification", qUtf8Printable(accountInfo.id));
return;
}
......@@ -2336,8 +2332,16 @@ CppImpl::slotNewIncomingCall(const std::string& callId)
notifId, _("Incoming call"), body, NotificationType::CALL);
}
} catch (const std::exception& e) {
g_warning("Can't get call %s for this account.", callId.c_str());
g_warning("Can't get call %s for this account.", callId.toStdString().c_str());
}
if (not accountInfo_ or accountInfo_->id.toStdString() != accountId)
return;
// call changeView even if we are already in an incoming call view, since
// the incoming call view holds a copy of the conversation info which has
// the be updated
changeView(INCOMING_CALL_VIEW_TYPE, origin);
}
void
......@@ -2494,7 +2498,6 @@ void
CppImpl::slotCloseTrustRequest(const std::string& id, const std::string& contactUri)
{
try {
auto& accountInfo = lrc_->getAccountModel().getAccountInfo(id.c_str());
auto notifId = id + ":request:" + contactUri;
hide_notification(NOTIFIER(widgets->notifier), notifId);
} catch (...) {
......@@ -2571,18 +2574,6 @@ CppImpl::slotCloseInteraction(const std::string& accountId, const std::string& c
}
}
void
CppImpl::slotShowIncomingCallView(const std::string& id, lrc::api::conversation::Info origin)
{
if (accountInfo_->id.toStdString() != id)
return;
/* call changeView even if we are already in an incoming call view, since
the incoming call view holds a copy of the conversation info which has
the be updated */
changeView(INCOMING_CALL_VIEW_TYPE, origin);
}
void
CppImpl::slotProfileUpdated(const std::string& id)
{
......@@ -2784,7 +2775,7 @@ main_window_accept_call(MainWindow *win)
// Accept call
priv->cpp->accountInfo_->callModel->accept(conversation.callId);
} catch (...) {
g_warning("Can't retrieve conversation %d", current);
g_warning("Can't retrieve conversation %s", current.c_str());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment