mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-12 02:35:38 +02:00
conversation model: avoid using database for jami accounts
GitLab: #1794 Change-Id: I48e5e7c42854440f3ee389a7256b8b99a0520eb2
This commit is contained in:
parent
ffb9bb8748
commit
b76570b892
1 changed files with 46 additions and 35 deletions
|
@ -2699,12 +2699,12 @@ ConversationModelPimpl::slotContactAdded(const QString& contactUri)
|
||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||||
auto isSwarm = !convId.isEmpty();
|
auto isSwarm = !convId.isEmpty();
|
||||||
auto conv = !isSwarm ? storage::getConversationsWithPeer(db, contactUri)
|
auto conv = !isSwarm ? (isSip ? storage::getConversationsWithPeer(db, contactUri) : VectorString {})
|
||||||
: VectorString {convId};
|
: VectorString {convId};
|
||||||
if (conv.isEmpty()) {
|
if (conv.isEmpty()) {
|
||||||
if (linked.owner.profileInfo.type == profile::Type::SIP) {
|
if (isSip) {
|
||||||
auto convId = storage::beginConversationWithPeer(db,
|
auto convId = storage::beginConversationWithPeer(db,
|
||||||
contactUri,
|
contactUri,
|
||||||
true,
|
true,
|
||||||
|
@ -2831,7 +2831,8 @@ ConversationModelPimpl::slotPendingContactAccepted(const QString& uri)
|
||||||
}
|
}
|
||||||
profile::Info profileInfo {uri, {}, {}, type};
|
profile::Info profileInfo {uri, {}, {}, type};
|
||||||
storage::vcard::setProfile(linked.owner.id, profileInfo, true);
|
storage::vcard::setProfile(linked.owner.id, profileInfo, true);
|
||||||
auto convs = storage::getConversationsWithPeer(db, uri);
|
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||||
|
auto convs = isSip ? storage::getConversationsWithPeer(db, uri) : VectorString {};
|
||||||
if (!convs.empty()) {
|
if (!convs.empty()) {
|
||||||
try {
|
try {
|
||||||
auto contact = linked.owner.contactModel->getContact(uri);
|
auto contact = linked.owner.contactModel->getContact(uri);
|
||||||
|
@ -3036,32 +3037,35 @@ ConversationModelPimpl::addConversationWith(const QString& convId,
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
conversation.callId = "";
|
conversation.callId = "";
|
||||||
}
|
}
|
||||||
storage::getHistory(db, conversation, linked.owner.profileInfo.uri);
|
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||||
|
if (isSip) {
|
||||||
|
storage::getHistory(db, conversation, linked.owner.profileInfo.uri);
|
||||||
|
|
||||||
QList<std::function<void(void)>> toUpdate;
|
QList<std::function<void(void)>> toUpdate;
|
||||||
conversation.interactions->forEach([&](const QString& id, interaction::Info& interaction) {
|
conversation.interactions->forEach([&](const QString& id, interaction::Info& interaction) {
|
||||||
if (interaction.status != interaction::Status::SENDING) {
|
if (interaction.status != interaction::Status::SENDING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get the message status from daemon, else unknown
|
// Get the message status from daemon, else unknown
|
||||||
auto daemonId = storage::getDaemonIdByInteractionId(db, id);
|
auto daemonId = storage::getDaemonIdByInteractionId(db, id);
|
||||||
int status = 0;
|
int status = 0;
|
||||||
if (daemonId.isEmpty()) {
|
if (daemonId.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
auto msgId = std::stoull(daemonId.toStdString());
|
auto msgId = std::stoull(daemonId.toStdString());
|
||||||
status = ConfigurationManager::instance().getMessageStatus(msgId);
|
status = ConfigurationManager::instance().getMessageStatus(msgId);
|
||||||
toUpdate.emplace_back([this, convId, contactUri, daemonId, status]() {
|
toUpdate.emplace_back([this, convId, contactUri, daemonId, status]() {
|
||||||
auto accId = linked.owner.id;
|
auto accId = linked.owner.id;
|
||||||
updateInteractionStatus(accId, convId, contactUri, daemonId, status);
|
updateInteractionStatus(accId, convId, contactUri, daemonId, status);
|
||||||
});
|
});
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
qWarning() << Q_FUNC_INFO << "Failed: message id was invalid";
|
qWarning() << Q_FUNC_INFO << "Failed: message id was invalid";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Q_FOREACH (const auto& func, toUpdate)
|
Q_FOREACH (const auto& func, toUpdate)
|
||||||
func();
|
func();
|
||||||
|
}
|
||||||
|
|
||||||
conversation.unreadMessages = getNumberOfUnreadMessagesFor(convId);
|
conversation.unreadMessages = getNumberOfUnreadMessagesFor(convId);
|
||||||
|
|
||||||
|
@ -3157,7 +3161,8 @@ ConversationModelPimpl::slotNewCall(const QString& fromId,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toUri == linked.owner.profileInfo.uri) {
|
if (toUri == linked.owner.profileInfo.uri) {
|
||||||
auto convIds = storage::getConversationsWithPeer(db, fromId);
|
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||||
|
auto convIds = isSip ? storage::getConversationsWithPeer(db, fromId) : VectorString {};
|
||||||
if (convIds.empty()) {
|
if (convIds.empty()) {
|
||||||
// in case if we receive call after removing contact add conversation request;
|
// in case if we receive call after removing contact add conversation request;
|
||||||
try {
|
try {
|
||||||
|
@ -3256,6 +3261,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
|
||||||
bool incoming,
|
bool incoming,
|
||||||
const std::time_t& duration)
|
const std::time_t& duration)
|
||||||
{
|
{
|
||||||
|
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||||
// Get conversation
|
// Get conversation
|
||||||
auto conv_it = std::find_if(conversations.begin(),
|
auto conv_it = std::find_if(conversations.begin(),
|
||||||
conversations.end(),
|
conversations.end(),
|
||||||
|
@ -3268,7 +3274,9 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
|
||||||
auto contact = linked.owner.contactModel->getContact(from);
|
auto contact = linked.owner.contactModel->getContact(from);
|
||||||
if (contact.profileInfo.type == profile::Type::PENDING) {
|
if (contact.profileInfo.type == profile::Type::PENDING) {
|
||||||
addContactRequest(from);
|
addContactRequest(from);
|
||||||
storage::beginConversationWithPeer(db, contact.profileInfo.uri);
|
if (isSip) {
|
||||||
|
storage::beginConversationWithPeer(db, contact.profileInfo.uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
return;
|
return;
|
||||||
|
@ -3282,7 +3290,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (conv_it->isSwarm())
|
if (!isSip || conv_it == conversations.end() || conv_it->isSwarm())
|
||||||
return;
|
return;
|
||||||
auto uriString = incoming ? storage::prepareUri(from, linked.owner.profileInfo.type)
|
auto uriString = incoming ? storage::prepareUri(from, linked.owner.profileInfo.type)
|
||||||
: linked.owner.profileInfo.uri;
|
: linked.owner.profileInfo.uri;
|
||||||
|
@ -3722,6 +3730,7 @@ ConversationModelPimpl::usefulDataFromDataTransfer(const QString& fileId,
|
||||||
void
|
void
|
||||||
ConversationModelPimpl::slotTransferStatusCreated(const QString& fileId, datatransfer::Info info)
|
ConversationModelPimpl::slotTransferStatusCreated(const QString& fileId, datatransfer::Info info)
|
||||||
{
|
{
|
||||||
|
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||||
// check if transfer is for the current account
|
// check if transfer is for the current account
|
||||||
if (info.accountId != linked.owner.id)
|
if (info.accountId != linked.owner.id)
|
||||||
return;
|
return;
|
||||||
|
@ -3741,9 +3750,11 @@ ConversationModelPimpl::slotTransferStatusCreated(const QString& fileId, datatra
|
||||||
isRequest = contact.profileInfo.type == profile::Type::PENDING;
|
isRequest = contact.profileInfo.type == profile::Type::PENDING;
|
||||||
if (isRequest && !contact.isBanned && info.peerUri != linked.owner.profileInfo.uri) {
|
if (isRequest && !contact.isBanned && info.peerUri != linked.owner.profileInfo.uri) {
|
||||||
addContactRequest(info.peerUri);
|
addContactRequest(info.peerUri);
|
||||||
convIds.push_back(storage::beginConversationWithPeer(db, contact.profileInfo.uri));
|
if (isSip) {
|
||||||
auto& conv = getConversationForPeerUri(contact.profileInfo.uri).get();
|
convIds.push_back(storage::beginConversationWithPeer(db, contact.profileInfo.uri));
|
||||||
conv.uid = convIds[0];
|
auto& conv = getConversationForPeerUri(contact.profileInfo.uri).get();
|
||||||
|
conv.uid = convIds[0];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue