mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-07-20 15:35:25 +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) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||
auto isSwarm = !convId.isEmpty();
|
||||
auto conv = !isSwarm ? storage::getConversationsWithPeer(db, contactUri)
|
||||
auto conv = !isSwarm ? (isSip ? storage::getConversationsWithPeer(db, contactUri) : VectorString {})
|
||||
: VectorString {convId};
|
||||
if (conv.isEmpty()) {
|
||||
if (linked.owner.profileInfo.type == profile::Type::SIP) {
|
||||
if (isSip) {
|
||||
auto convId = storage::beginConversationWithPeer(db,
|
||||
contactUri,
|
||||
true,
|
||||
|
@ -2831,7 +2831,8 @@ ConversationModelPimpl::slotPendingContactAccepted(const QString& uri)
|
|||
}
|
||||
profile::Info profileInfo {uri, {}, {}, type};
|
||||
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()) {
|
||||
try {
|
||||
auto contact = linked.owner.contactModel->getContact(uri);
|
||||
|
@ -3036,32 +3037,35 @@ ConversationModelPimpl::addConversationWith(const QString& convId,
|
|||
} catch (...) {
|
||||
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;
|
||||
conversation.interactions->forEach([&](const QString& id, interaction::Info& interaction) {
|
||||
if (interaction.status != interaction::Status::SENDING) {
|
||||
return;
|
||||
}
|
||||
// Get the message status from daemon, else unknown
|
||||
auto daemonId = storage::getDaemonIdByInteractionId(db, id);
|
||||
int status = 0;
|
||||
if (daemonId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
auto msgId = std::stoull(daemonId.toStdString());
|
||||
status = ConfigurationManager::instance().getMessageStatus(msgId);
|
||||
toUpdate.emplace_back([this, convId, contactUri, daemonId, status]() {
|
||||
auto accId = linked.owner.id;
|
||||
updateInteractionStatus(accId, convId, contactUri, daemonId, status);
|
||||
});
|
||||
} catch (const std::exception& e) {
|
||||
qWarning() << Q_FUNC_INFO << "Failed: message id was invalid";
|
||||
}
|
||||
});
|
||||
Q_FOREACH (const auto& func, toUpdate)
|
||||
func();
|
||||
QList<std::function<void(void)>> toUpdate;
|
||||
conversation.interactions->forEach([&](const QString& id, interaction::Info& interaction) {
|
||||
if (interaction.status != interaction::Status::SENDING) {
|
||||
return;
|
||||
}
|
||||
// Get the message status from daemon, else unknown
|
||||
auto daemonId = storage::getDaemonIdByInteractionId(db, id);
|
||||
int status = 0;
|
||||
if (daemonId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
auto msgId = std::stoull(daemonId.toStdString());
|
||||
status = ConfigurationManager::instance().getMessageStatus(msgId);
|
||||
toUpdate.emplace_back([this, convId, contactUri, daemonId, status]() {
|
||||
auto accId = linked.owner.id;
|
||||
updateInteractionStatus(accId, convId, contactUri, daemonId, status);
|
||||
});
|
||||
} catch (const std::exception& e) {
|
||||
qWarning() << Q_FUNC_INFO << "Failed: message id was invalid";
|
||||
}
|
||||
});
|
||||
Q_FOREACH (const auto& func, toUpdate)
|
||||
func();
|
||||
}
|
||||
|
||||
conversation.unreadMessages = getNumberOfUnreadMessagesFor(convId);
|
||||
|
||||
|
@ -3157,7 +3161,8 @@ ConversationModelPimpl::slotNewCall(const QString& fromId,
|
|||
}
|
||||
|
||||
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()) {
|
||||
// in case if we receive call after removing contact add conversation request;
|
||||
try {
|
||||
|
@ -3256,6 +3261,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
|
|||
bool incoming,
|
||||
const std::time_t& duration)
|
||||
{
|
||||
auto isSip = linked.owner.profileInfo.type == profile::Type::SIP;
|
||||
// Get conversation
|
||||
auto conv_it = std::find_if(conversations.begin(),
|
||||
conversations.end(),
|
||||
|
@ -3268,7 +3274,9 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
|
|||
auto contact = linked.owner.contactModel->getContact(from);
|
||||
if (contact.profileInfo.type == profile::Type::PENDING) {
|
||||
addContactRequest(from);
|
||||
storage::beginConversationWithPeer(db, contact.profileInfo.uri);
|
||||
if (isSip) {
|
||||
storage::beginConversationWithPeer(db, contact.profileInfo.uri);
|
||||
}
|
||||
}
|
||||
} catch (const std::exception&) {
|
||||
return;
|
||||
|
@ -3282,7 +3290,7 @@ ConversationModelPimpl::addOrUpdateCallMessage(const QString& callId,
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (conv_it->isSwarm())
|
||||
if (!isSip || conv_it == conversations.end() || conv_it->isSwarm())
|
||||
return;
|
||||
auto uriString = incoming ? storage::prepareUri(from, linked.owner.profileInfo.type)
|
||||
: linked.owner.profileInfo.uri;
|
||||
|
@ -3722,6 +3730,7 @@ ConversationModelPimpl::usefulDataFromDataTransfer(const QString& fileId,
|
|||
void
|
||||
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
|
||||
if (info.accountId != linked.owner.id)
|
||||
return;
|
||||
|
@ -3741,9 +3750,11 @@ ConversationModelPimpl::slotTransferStatusCreated(const QString& fileId, datatra
|
|||
isRequest = contact.profileInfo.type == profile::Type::PENDING;
|
||||
if (isRequest && !contact.isBanned && info.peerUri != linked.owner.profileInfo.uri) {
|
||||
addContactRequest(info.peerUri);
|
||||
convIds.push_back(storage::beginConversationWithPeer(db, contact.profileInfo.uri));
|
||||
auto& conv = getConversationForPeerUri(contact.profileInfo.uri).get();
|
||||
conv.uid = convIds[0];
|
||||
if (isSip) {
|
||||
convIds.push_back(storage::beginConversationWithPeer(db, contact.profileInfo.uri));
|
||||
auto& conv = getConversationForPeerUri(contact.profileInfo.uri).get();
|
||||
conv.uid = convIds[0];
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue