Commit 9ef94561 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Ming Rui Zhang

lrc: avoid excessive copying of conversation info objects

1. Container View api
2. use optional conversation info ref api

Change-Id: I38aa57edc1fbf304ea0ef95d48000e0495c409ee
parent 44ebb170
......@@ -379,17 +379,16 @@ AccountAdapter::connectAccount(const QString& accountId)
= QObject::connect(accInfo.contactModel.get(),
&lrc::api::ContactModel::contactAdded,
[this, accountId](const QString& contactUri) {
auto& accInfo = LRCInstance::accountModel().getAccountInfo(
accountId);
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(
const auto& convInfo = LRCInstance::getConversationFromConvUid(
LRCInstance::getCurrentConvUid());
if (conversation.uid.isEmpty()) {
if (convInfo.uid.isEmpty()) {
return;
}
auto& accInfo = LRCInstance::accountModel().getAccountInfo(
accountId);
if (contactUri
== accInfo.contactModel
->getContact(conversation.participants.at(0))
->getContact(convInfo.participants.at(0))
.profileInfo.uri) {
/*
* Update conversation.
......
......@@ -234,9 +234,8 @@ AvAdapter::stopAudioMeter(bool async)
const QString&
AvAdapter::getCurrentCallId()
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto call = LRCInstance::getCallInfoForConversation(conversation);
const auto& convInfo = LRCInstance::getConversationFromConvUid(LRCInstance::getCurrentConvUid());
auto call = LRCInstance::getCallInfoForConversation(convInfo);
if (!call)
return QString();
return call->id;
......
......@@ -19,6 +19,7 @@
#pragma once
#include "utils.h"
#include "lrcinstance.h"
#include <QImage>
#include <QQuickImageProvider>
......@@ -57,9 +58,8 @@ public:
return Utils::accountPhoto(LRCInstance::accountModel().getAccountInfo(idContent),
requestedSize);
} else if (idType == "conversation") {
auto* convModel = LRCInstance::getCurrentAccountInfo().conversationModel.get();
const auto& conv = convModel->getConversationForUID(idContent);
return Utils::contactPhoto(conv.participants[0], requestedSize);
const auto& convInfo = LRCInstance::getConversationFromConvUid(idContent);
return Utils::contactPhoto(convInfo.participants[0], requestedSize);
} else if (idType == "contact") {
return Utils::contactPhoto(idContent, requestedSize);
} else if (idType == "fallback") {
......
/*
/*!
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
......@@ -37,19 +37,21 @@ CallAdapter::CallAdapter(QObject* parent)
connect(&LRCInstance::behaviorController(),
&BehaviorController::showIncomingCallView,
this,
&CallAdapter::slotShowIncomingCallView);
connect(&LRCInstance::instance(),
&LRCInstance::currentAccountChanged,
this,
&CallAdapter::slotAccountChanged);
&CallAdapter::onShowIncomingCallView);
connect(&LRCInstance::behaviorController(),
&BehaviorController::showCallView,
this,
&CallAdapter::slotShowCallView);
&CallAdapter::onShowCallView);
connect(&LRCInstance::instance(),
&LRCInstance::currentAccountChanged,
this,
&CallAdapter::onAccountChanged);
}
void
CallAdapter::slotAccountChanged()
CallAdapter::onAccountChanged()
{
accountId_ = LRCInstance::getCurrAccId();
connectCallModel(accountId_);
......@@ -76,8 +78,7 @@ CallAdapter::placeCall()
void
CallAdapter::hangUpACall(const QString& accountId, const QString& convUid)
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (!convInfo.uid.isEmpty()) {
LRCInstance::getAccountInfo(accountId).callModel->hangUp(convInfo.callId);
}
......@@ -86,8 +87,7 @@ CallAdapter::hangUpACall(const QString& accountId, const QString& convUid)
void
CallAdapter::refuseACall(const QString& accountId, const QString& convUid)
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (!convInfo.uid.isEmpty()) {
LRCInstance::getAccountInfo(accountId).callModel->refuse(convInfo.callId);
}
......@@ -96,8 +96,7 @@ CallAdapter::refuseACall(const QString& accountId, const QString& convUid)
void
CallAdapter::acceptACall(const QString& accountId, const QString& convUid)
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (!convInfo.uid.isEmpty()) {
LRCInstance::getAccountInfo(accountId).callModel->accept(convInfo.callId);
auto& accInfo = LRCInstance::getAccountInfo(convInfo.accountId);
......@@ -118,11 +117,14 @@ CallAdapter::acceptACall(const QString& accountId, const QString& convUid)
}
void
CallAdapter::slotShowIncomingCallView(const QString& accountId, const conversation::Info& convInfo)
CallAdapter::onShowIncomingCallView(const QString& accountId, const QString& convUid)
{
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (convInfo.uid.isEmpty()) {
return;
}
auto selectedAccountId = LRCInstance::getCurrAccId();
auto* callModel = LRCInstance::getCurrentCallModel();
auto* convModel = LRCInstance::getCurrentConversationModel();
if (!callModel->hasCall(convInfo.callId)) {
if (QApplication::focusObject() == nullptr || accountId != selectedAccountId) {
......@@ -130,8 +132,8 @@ CallAdapter::slotShowIncomingCallView(const QString& accountId, const conversati
return;
}
const auto currentConvUid = LRCInstance::getCurrentConvUid();
const auto currentConvInfo = convModel->getConversationForUID(currentConvUid);
const auto& currentConvInfo = LRCInstance::getConversationFromConvUid(
LRCInstance::getCurrentConvUid());
// Current call
auto currentConvHasCall = callModel->hasCall(currentConvInfo.callId);
......@@ -164,8 +166,8 @@ CallAdapter::slotShowIncomingCallView(const QString& accountId, const conversati
return;
}
const auto currentConvUid = LRCInstance::getCurrentConvUid();
const auto currentConvInfo = convModel->getConversationForUID(currentConvUid);
const auto& currentConvInfo = LRCInstance::getConversationFromConvUid(
LRCInstance::getCurrentConvUid());
// Call in current conversation
auto currentConvHasCall = callModel->hasCall(currentConvInfo.callId);
......@@ -202,8 +204,12 @@ CallAdapter::slotShowIncomingCallView(const QString& accountId, const conversati
}
void
CallAdapter::slotShowCallView(const QString& accountId, const lrc::api::conversation::Info& convInfo)
CallAdapter::onShowCallView(const QString& accountId, const QString& convUid)
{
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (convInfo.uid.isEmpty()) {
return;
}
updateCall(convInfo.uid, accountId);
}
......@@ -213,8 +219,7 @@ CallAdapter::updateCall(const QString& convUid, const QString& accountId, bool f
accountId_ = accountId.isEmpty() ? accountId_ : accountId;
convUid_ = convUid.isEmpty() ? convUid_ : convUid;
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
if (convInfo.uid.isEmpty()) {
return;
}
......@@ -238,8 +243,8 @@ bool
CallAdapter::shouldShowPreview(bool force)
{
bool shouldShowPreview {false};
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
if (convInfo.uid.isEmpty()) {
return shouldShowPreview;
}
......@@ -255,8 +260,7 @@ QVariantList
CallAdapter::getConferencesInfos()
{
QVariantList map;
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
if (convInfo.uid.isEmpty())
return map;
auto callId = convInfo.confId.isEmpty() ? convInfo.callId : convInfo.confId;
......@@ -299,18 +303,20 @@ void
CallAdapter::showNotification(const QString& accountId, const QString& convUid)
{
QString from {};
auto convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (!accountId.isEmpty() && !convInfo.uid.isEmpty()) {
auto& accInfo = LRCInstance::getAccountInfo(accountId);
if (!convInfo.participants.isEmpty())
from = accInfo.contactModel->bestNameForContact(convInfo.participants[0]);
}
auto onClicked = [this, convInfo]() {
emit LRCInstance::instance().notificationClicked();
if (!convInfo.uid.isEmpty()) {
emit callSetupMainViewRequired(convInfo.accountId, convInfo.uid);
auto onClicked = [this, accountId, convUid = convInfo.uid]() {
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (convInfo.uid.isEmpty()) {
return;
}
emit LRCInstance::instance().notificationClicked();
emit callSetupMainViewRequired(convInfo.accountId, convInfo.uid);
};
emit LRCInstance::instance().updateSmartList();
Utils::showNotification(tr("is calling you"), from, accountId, convUid, onClicked);
......@@ -331,7 +337,7 @@ CallAdapter::connectCallModel(const QString& accountId)
auto& accInfo = LRCInstance::accountModel().getAccountInfo(accountId);
auto& callModel = accInfo.callModel;
auto call = callModel->getCall(confId);
const auto convInfo = LRCInstance::getConversationFromCallId(confId);
const auto& convInfo = LRCInstance::getConversationFromCallId(confId);
bool currentMuted = false;
if (!convInfo.uid.isEmpty()) {
// Convert to QML
......@@ -371,8 +377,7 @@ CallAdapter::connectCallModel(const QString& accountId)
}
// Link local mute to conference mute
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
if (!convInfo.uid.isEmpty()) {
auto call = LRCInstance::getCallInfoForConversation(convInfo);
if (call) {
......@@ -397,7 +402,7 @@ CallAdapter::connectCallModel(const QString& accountId)
/*
* Change status label text.
*/
const auto convInfo = LRCInstance::getConversationFromCallId(callId);
const auto& convInfo = LRCInstance::getConversationFromCallId(callId);
if (!convInfo.uid.isEmpty()) {
emit callStatusChanged(static_cast<int>(call.status), accountId, convInfo.uid);
updateCallOverlay(convInfo);
......@@ -439,7 +444,7 @@ CallAdapter::connectCallModel(const QString& accountId)
}
auto currentCall = callModel->getCall(callId);
if (currentCall.status == lrc::api::call::Status::IN_PROGRESS) {
auto otherConv = LRCInstance::getConversationFromCallId(callId);
const auto& otherConv = LRCInstance::getConversationFromCallId(callId);
if (!otherConv.uid.isEmpty() && otherConv.uid != convInfo.uid) {
/*
* Reset the call view corresponding accountId, uid.
......@@ -454,7 +459,7 @@ CallAdapter::connectCallModel(const QString& accountId)
}
case lrc::api::call::Status::CONNECTED:
case lrc::api::call::Status::IN_PROGRESS: {
const auto convInfo = LRCInstance::getConversationFromCallId(callId, accountId);
const auto& convInfo = LRCInstance::getConversationFromCallId(callId, accountId);
if (!convInfo.uid.isEmpty() && convInfo.uid == LRCInstance::getCurrentConvUid()) {
accInfo.conversationModel->selectConversation(convInfo.uid);
}
......@@ -517,7 +522,7 @@ CallAdapter::updateCallOverlay(const lrc::api::conversation::Info& convInfo)
oneSecondTimer_->start(20);
auto& accInfo = LRCInstance::accountModel().getAccountInfo(accountId_);
auto call = LRCInstance::getCallInfoForConversation(convInfo);
auto* call = LRCInstance::getCallInfoForConversation(convInfo);
if (!call) {
return;
}
......@@ -544,7 +549,7 @@ CallAdapter::updateCallOverlay(const lrc::api::conversation::Info& convInfo)
void
CallAdapter::hangupCall(const QString& uri)
{
const auto convInfo = LRCInstance::getConversationFromPeerUri(uri, accountId_);
const auto& convInfo = LRCInstance::getConversationFromPeerUri(uri, accountId_);
if (!convInfo.uid.isEmpty()) {
auto callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
if (callModel->hasCall(convInfo.callId)) {
......@@ -571,11 +576,12 @@ void
CallAdapter::maximizeParticipant(const QString& uri)
{
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto confId = conversation.confId;
const auto& convInfo = LRCInstance::getConversationFromConvUid(LRCInstance::getCurrentConvUid(),
accountId_);
auto confId = convInfo.confId;
if (confId.isEmpty())
confId = conversation.callId;
confId = convInfo.callId;
try {
auto call = callModel->getCall(confId);
if (call.participantsInfos.size() > 0) {
......@@ -603,12 +609,12 @@ void
CallAdapter::minimizeParticipant(const QString& uri)
{
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto confId = conversation.confId;
const auto& convInfo = LRCInstance::getConversationFromConvUid(LRCInstance::getCurrentConvUid(),
accountId_);
auto confId = convInfo.confId;
if (confId.isEmpty())
confId = conversation.callId;
confId = convInfo.callId;
try {
auto call = callModel->getCall(confId);
if (call.participantsInfos.size() > 0) {
......@@ -633,8 +639,7 @@ CallAdapter::minimizeParticipant(const QString& uri)
void
CallAdapter::hangUpThisCall()
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_, accountId_);
if (!convInfo.uid.isEmpty()) {
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
if (!convInfo.confId.isEmpty() && callModel->hasCall(convInfo.confId)) {
......@@ -648,9 +653,8 @@ CallAdapter::hangUpThisCall()
bool
CallAdapter::isRecordingThisCall()
{
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_, accountId_);
auto& accInfo = LRCInstance::accountModel().getAccountInfo(accountId_);
auto& convModel = accInfo.conversationModel;
const auto convInfo = convModel->getConversationForUID(convUid_);
return accInfo.callModel->isRecording(convInfo.confId)
|| accInfo.callModel->isRecording(convInfo.callId);
}
......@@ -658,8 +662,7 @@ CallAdapter::isRecordingThisCall()
bool
CallAdapter::isCurrentHost() const
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_, accountId_);
if (!convInfo.uid.isEmpty()) {
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
try {
......@@ -681,8 +684,7 @@ CallAdapter::isCurrentHost() const
bool
CallAdapter::participantIsHost(const QString& uri) const
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
if (!convInfo.uid.isEmpty()) {
auto& accInfo = LRCInstance::getAccountInfo(accountId_);
auto* callModel = accInfo.callModel.get();
......@@ -704,11 +706,11 @@ bool
CallAdapter::isModerator(const QString& uri) const
{
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto confId = conversation.confId;
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
auto confId = convInfo.confId;
if (confId.isEmpty())
confId = conversation.callId;
confId = convInfo.callId;
try {
return callModel->isModerator(confId, uri);
} catch (...) {
......@@ -719,8 +721,7 @@ CallAdapter::isModerator(const QString& uri) const
bool
CallAdapter::isCurrentModerator() const
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
if (!convInfo.uid.isEmpty()) {
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
try {
......@@ -745,11 +746,10 @@ void
CallAdapter::setModerator(const QString& uri, const bool state)
{
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto confId = conversation.confId;
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
auto confId = convInfo.confId;
if (confId.isEmpty())
confId = conversation.callId;
confId = convInfo.callId;
try {
callModel->setModerator(confId, uri, state);
} catch (...) {
......@@ -760,11 +760,11 @@ void
CallAdapter::muteParticipant(const QString& uri, const bool state)
{
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto confId = conversation.confId;
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
auto confId = convInfo.confId;
if (confId.isEmpty())
confId = conversation.callId;
confId = convInfo.callId;
try {
const auto call = callModel->getCall(confId);
callModel->muteParticipant(confId, uri, state);
......@@ -775,8 +775,7 @@ CallAdapter::muteParticipant(const QString& uri, const bool state)
bool
CallAdapter::isMuted(const QString& uri) const
{
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto convInfo = convModel->getConversationForUID(convUid_);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto confId = convInfo.confId.isEmpty() ? convInfo.callId : convInfo.confId;
try {
......@@ -799,11 +798,11 @@ void
CallAdapter::hangupParticipant(const QString& uri)
{
auto* callModel = LRCInstance::getAccountInfo(accountId_).callModel.get();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
auto confId = conversation.confId;
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid_);
auto confId = convInfo.confId;
if (confId.isEmpty())
confId = conversation.callId;
confId = convInfo.callId;
try {
const auto call = callModel->getCall(confId);
callModel->hangupParticipant(confId, uri);
......
/*
/*!
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
* Author: Sébastien Blin <sebastien.blin@savoirfairelinux.com>
......@@ -99,10 +99,9 @@ signals:
void remoteRecordingChanged(const QStringList& peers, bool state);
public slots:
void slotShowIncomingCallView(const QString& accountId,
const lrc::api::conversation::Info& convInfo);
void slotShowCallView(const QString& accountId, const lrc::api::conversation::Info& convInfo);
void slotAccountChanged();
void onShowIncomingCallView(const QString& accountId, const QString& convUid);
void onShowCallView(const QString& accountId, const QString& convUid);
void onAccountChanged();
private:
bool shouldShowPreview(bool force);
......
......@@ -35,10 +35,7 @@ ContactAdapter::getContactSelectableModel(int type)
* Called from qml every time contact picker refreshes.
*/
listModeltype_ = static_cast<SmartListModel::Type>(type);
smartListModel_.reset(new SmartListModel(this,
LRCInstance::getCurrAccId(),
listModeltype_,
LRCInstance::getCurrentConvUid()));
smartListModel_.reset(new SmartListModel(this, listModeltype_));
selectableProxyModel_->setSourceModel(smartListModel_.get());
/*
......@@ -90,9 +87,7 @@ ContactAdapter::contactSelected(int index)
{
auto contactIndex = selectableProxyModel_->index(index, 0);
auto* callModel = LRCInstance::getCurrentCallModel();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
const auto& convInfo = LRCInstance::getConversationFromConvUid(LRCInstance::getCurrentConvUid());
if (contactIndex.isValid()) {
switch (listModeltype_) {
case SmartListModel::Type::CONFERENCE: {
......@@ -111,16 +106,15 @@ ContactAdapter::contactSelected(int index)
const auto callId = LRCInstance::getCallIdForConversationUid(convUid, accId);
if (!callId.isEmpty()) {
if (conversation.uid.isEmpty()) {
if (convInfo.uid.isEmpty()) {
return;
}
auto thisCallId = conversation.confId.isEmpty() ? conversation.callId
: conversation.confId;
auto thisCallId = convInfo.confId.isEmpty() ? convInfo.callId : convInfo.confId;
callModel->joinCalls(thisCallId, callId);
} else {
const auto contactUri = contactIndex.data(SmartListModel::Role::URI).value<QString>();
auto call = LRCInstance::getCallInfoForConversation(conversation);
auto call = LRCInstance::getCallInfoForConversation(convInfo);
if (!call) {
return;
}
......@@ -133,11 +127,10 @@ ContactAdapter::contactSelected(int index)
*/
const auto contactUri = contactIndex.data(SmartListModel::Role::URI).value<QString>();
if (conversation.uid.isEmpty()) {
if (convInfo.uid.isEmpty()) {
return;
}
const auto callId = conversation.confId.isEmpty() ? conversation.callId
: conversation.confId;
const auto callId = convInfo.confId.isEmpty() ? convInfo.callId : convInfo.confId;
QString destCallId;
......
/*!
* Copyright (C) 2020 by Savoir-faire Linux
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>
* Author: Anthony Lonard <anthony.leonard@savoirfairelinux.com>
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com>
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com>
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
* Author: Isa Nanic <isa.nanic@savoirfairelinux.com>
......@@ -39,14 +39,14 @@ ConversationsAdapter::ConversationsAdapter(QObject* parent)
void
ConversationsAdapter::safeInit()
{
conversationSmartListModel_ = new SmartListModel(this, LRCInstance::getCurrAccId());
conversationSmartListModel_ = new SmartListModel(this);
emit modelChanged(QVariant::fromValue(conversationSmartListModel_));
connect(&LRCInstance::behaviorController(),
&BehaviorController::showChatView,
[this](const QString& accountId, lrc::api::conversation::Info convInfo) {
emit showConversation(accountId, convInfo.uid);
[this](const QString& accountId, const QString& convId) {
emit showConversation(accountId, convId);
});
connect(&LRCInstance::behaviorController(),
......@@ -75,13 +75,16 @@ ConversationsAdapter::backToWelcomePage()
void
ConversationsAdapter::selectConversation(const QString& accountId, const QString& convUid)
{
auto* convModel = LRCInstance::getAccountInfo(accountId).conversationModel.get();
const auto& convInfo = convModel->getConversationForUID(convUid);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (LRCInstance::getCurrentConvUid() != convInfo.uid && convInfo.participants.size() > 0) {
// If the account is not currently selected, do that first, then
// proceed to select the conversation.
auto selectConversation = [this, convInfo] {
auto selectConversation = [this, accountId, convUid = convInfo.uid] {
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (convInfo.uid.isEmpty()) {
return;
}
auto& accInfo = LRCInstance::getAccountInfo(convInfo.accountId);
LRCInstance::setSelectedConvId(convInfo.uid);
accInfo.conversationModel->clearUnreadInteractions(convInfo.uid);
......@@ -143,11 +146,10 @@ ConversationsAdapter::onNewUnreadInteraction(const QString& accountId,
&& (!QApplication::focusWindow() || accountId != LRCInstance::getCurrAccId()
|| convUid != LRCInstance::getCurrentConvUid())) {
auto& accInfo = LRCInstance::getAccountInfo(accountId);
auto& contact = accInfo.contactModel->getContact(interaction.authorUri);
auto from = accInfo.contactModel->bestNameForContact(interaction.authorUri);
auto onClicked = [this, accountId, convUid, uri = interaction.authorUri] {
emit LRCInstance::instance().notificationClicked();
auto convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
const auto& convInfo = LRCInstance::getConversationFromConvUid(convUid, accountId);
if (!convInfo.uid.isEmpty()) {
selectConversation(accountId, convInfo.uid);
emit LRCInstance::instance().updateSmartList();
......@@ -185,24 +187,25 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
auto currentConversationModel = LRCInstance::getCurrentConversationModel();
modelSortedConnection_ = QObject::connect(
currentConversationModel, &lrc::api::ConversationModel::modelSorted, [this]() {
currentConversationModel, &lrc::api::ConversationModel::modelChanged, [this]() {
conversationSmartListModel_->fillConversationsList();
updateConversationsFilterWidget();
emit updateListViewRequested();
auto* convModel = LRCInstance::getCurrentConversationModel();
const auto conversation = convModel->getConversationForUID(
const auto& convInfo = LRCInstance::getConversationFromConvUid(
LRCInstance::getCurrentConvUid());
if (conversation.uid.isEmpty() || conversation.participants.isEmpty()) {
if (convInfo.uid.isEmpty() || convInfo.participants.isEmpty()) {
return;
}
const auto contactURI = conversation.participants[0];
const auto contactURI = convInfo.participants[0];
if (contactURI.isEmpty()
|| convModel->owner.contactModel->getContact(contactURI).profileInfo.type