1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-08 19:13:28 +02:00

conversationlist: save linked account

This avoid some "contact not found" messages if a delegate is
checked while changing the account.

Change-Id: I05c4affa93a972ac95578507bd8263706e90298b
This commit is contained in:
Sébastien Blin 2023-03-13 10:31:13 -04:00
parent a5de0d4196
commit 9207dfcd5b
2 changed files with 18 additions and 13 deletions

View file

@ -23,7 +23,12 @@ ConversationListModelBase::ConversationListModelBase(LRCInstance* instance, QObj
: AbstractListModelBase(parent)
{
lrcInstance_ = instance;
model_ = lrcInstance_->getCurrentConversationModel();
try {
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
accountId_ = accInfo.id;
model_ = accInfo.conversationModel.get();
} catch (...) {
}
}
int
@ -47,12 +52,12 @@ ConversationListModelBase::roleNames() const
QVariant
ConversationListModelBase::dataForItem(item_t item, int role) const
{
auto& accInfo = lrcInstance_->getAccountInfo(accountId_);
switch (role) {
case Role::InCall: {
const auto& convInfo = lrcInstance_->getConversationFromConvUid(item.uid);
if (!convInfo.uid.isEmpty()) {
auto* callModel = lrcInstance_->getCurrentCallModel();
return QVariant(callModel->hasCall(convInfo.callId));
return QVariant(accInfo.callModel->hasCall(convInfo.callId));
}
return QVariant(false);
}
@ -69,9 +74,8 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
case Role::CallStackViewShouldShow: {
const auto& convInfo = lrcInstance_->getConversationFromConvUid(item.uid);
if (!convInfo.uid.isEmpty() && !convInfo.callId.isEmpty()) {
auto* callModel = lrcInstance_->getCurrentCallModel();
const auto& call = callModel->getCall(convInfo.callId);
return QVariant(callModel->hasCall(convInfo.callId)
const auto& call = accInfo.callModel->getCall(convInfo.callId);
return QVariant(accInfo.callModel->hasCall(convInfo.callId)
&& ((!call.isOutgoing
&& (call.status == call::Status::IN_PROGRESS
|| call.status == call::Status::PAUSED
@ -141,7 +145,7 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
QStringList ret;
Q_FOREACH (const auto& peerUri, model_->peersForConversation(item.uid))
try {
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
auto& accInfo = lrcInstance_->getAccountInfo(accountId_);
auto contact = accInfo.contactModel->getContact(peerUri);
ret << contact.profileInfo.alias << contact.registeredName;
} catch (const std::exception&) {
@ -152,7 +156,7 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
// The conversation can show a green dot if at least one peer is present
Q_FOREACH (const auto& peerUri, model_->peersForConversation(item.uid))
try {
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
auto& accInfo = lrcInstance_->getAccountInfo(accountId_);
if (peerUri == accInfo.profileInfo.uri)
return true; // Self account
auto contact = accInfo.contactModel->getContact(peerUri);
@ -171,7 +175,7 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
if (peerUriList.isEmpty())
return {};
auto peerUri = peerUriList.at(0);
auto& accInfo = lrcInstance_->getCurrentAccountInfo();
auto& accInfo = lrcInstance_->getAccountInfo(accountId_);
if (peerUri == accInfo.profileInfo.uri) {
// Conversation alone with self
switch (role) {
@ -186,8 +190,7 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
case Role::IsBanned:
return QVariant(false);
case Role::ContactType:
return QVariant(
static_cast<int>(accInfo.profileInfo.type));
return QVariant(static_cast<int>(accInfo.profileInfo.type));
}
}
ContactModel* contactModel;
@ -196,8 +199,9 @@ ConversationListModelBase::dataForItem(item_t item, int role) const
try {
contact = contactModel->getContact(peerUri);
} catch (const std::exception&) {
qWarning() << Q_FUNC_INFO << "Can't find contact" << peerUri
<< " this is a bug, please report";
qWarning() << Q_FUNC_INFO << "Can't find contact" << peerUri << " for account "
<< lrcInstance_->accountModel().bestNameForAccount(accInfo.id)
<< " - Conv: " << item.uid;
}
switch (role) {

View file

@ -81,4 +81,5 @@ protected:
// Convenience pointer to be pulled from lrcinstance
ConversationModel* model_;
QString accountId_;
};