mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-06 07:45:51 +02:00
conversation model: split logic for SIP and Jami
GitLab: #1794 Change-Id: Ief688df6778fe2758882ff1538371def8ba75d64
This commit is contained in:
parent
69400bee2a
commit
89354a07e1
1 changed files with 63 additions and 48 deletions
|
@ -200,7 +200,7 @@ public:
|
||||||
QString& conversationId);
|
QString& conversationId);
|
||||||
void awaitingHost(const QString& fileId, datatransfer::Info info);
|
void awaitingHost(const QString& fileId, datatransfer::Info info);
|
||||||
|
|
||||||
bool hasOneOneSwarmWith(const QString& participant);
|
bool hasOneOneSwarmWith(const contact::Info& participant);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* accept a file transfer
|
* accept a file transfer
|
||||||
|
@ -2009,57 +2009,70 @@ ConversationModelPimpl::initConversations()
|
||||||
if (accountDetails.empty())
|
if (accountDetails.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Fill swarm conversations
|
auto isJami = linked.owner.profileInfo.type == profile::Type::JAMI;
|
||||||
QStringList swarms = ConfigurationManager::instance().getConversations(linked.owner.id);
|
|
||||||
for (auto& swarmConv : swarms) {
|
|
||||||
addSwarmConversation(swarmConv);
|
|
||||||
}
|
|
||||||
|
|
||||||
VectorMapStringString conversationsRequests = ConfigurationManager::instance()
|
if (isJami) {
|
||||||
.getConversationRequests(linked.owner.id);
|
// Fill swarm conversations
|
||||||
for (auto& request : conversationsRequests) {
|
QStringList swarms = ConfigurationManager::instance().getConversations(linked.owner.id);
|
||||||
addConversationRequest(request);
|
for (auto& swarmConv : swarms) {
|
||||||
}
|
addSwarmConversation(swarmConv);
|
||||||
|
}
|
||||||
|
|
||||||
// Fill conversations
|
VectorMapStringString conversationsRequests = ConfigurationManager::instance()
|
||||||
for (auto const& c : linked.owner.contactModel->getAllContacts().toStdMap()) {
|
.getConversationRequests(linked.owner.id);
|
||||||
auto conv = storage::getConversationsWithPeer(db, c.second.profileInfo.uri);
|
for (auto& request : conversationsRequests) {
|
||||||
if (hasOneOneSwarmWith(c.second.profileInfo.uri))
|
addConversationRequest(request);
|
||||||
continue;
|
}
|
||||||
bool isRequest = c.second.profileInfo.type == profile::Type::PENDING;
|
|
||||||
if (conv.empty()) {
|
for (auto const& c : linked.owner.contactModel->getAllContacts()) {
|
||||||
|
if (hasOneOneSwarmWith(c))
|
||||||
|
continue;
|
||||||
|
bool isRequest = c.profileInfo.type == profile::Type::PENDING;
|
||||||
// Can't find a conversation with this contact
|
// Can't find a conversation with this contact
|
||||||
// add pending not swarm conversation
|
// add pending not swarm conversation
|
||||||
if (isRequest) {
|
if (isRequest) {
|
||||||
addContactRequest(c.second.profileInfo.uri);
|
addContactRequest(c.profileInfo.uri);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
conv.push_back(storage::beginConversationWithPeer(db,
|
|
||||||
c.second.profileInfo.uri,
|
|
||||||
true,
|
|
||||||
linked.owner.contactModel->getAddedTs(
|
|
||||||
c.second.profileInfo.uri)));
|
|
||||||
}
|
}
|
||||||
addConversationWith(conv[0], c.first, isRequest);
|
} else {
|
||||||
|
// Fill conversations
|
||||||
auto convIdx = indexOf(conv[0]);
|
for (auto const& c : linked.owner.contactModel->getAllContacts().toStdMap()) {
|
||||||
|
auto conv = storage::getConversationsWithPeer(db, c.second.profileInfo.uri);
|
||||||
// Resolve any file transfer interactions were left in an incorrect state
|
bool isRequest = c.second.profileInfo.type == profile::Type::PENDING;
|
||||||
auto& interactions = conversations[convIdx].interactions;
|
if (conv.empty()) {
|
||||||
interactions->forEach([&](const QString& id, interaction::Info& interaction) {
|
// Can't find a conversation with this contact
|
||||||
if (interaction.transferStatus == interaction::TransferStatus::TRANSFER_CREATED
|
// add pending not swarm conversation
|
||||||
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_AWAITING_HOST
|
if (isRequest) {
|
||||||
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_AWAITING_PEER
|
addContactRequest(c.second.profileInfo.uri);
|
||||||
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_ONGOING
|
continue;
|
||||||
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_ACCEPTED) {
|
}
|
||||||
// If a datatransfer was left in a non-terminal status in DB, we switch this status
|
conv.push_back(storage::beginConversationWithPeer(db,
|
||||||
// to ERROR
|
c.second.profileInfo.uri,
|
||||||
// TODO : Improve for DBus clients as daemon and transfer may still be ongoing
|
true,
|
||||||
storage::updateInteractionTransferStatus(db, id, interaction::TransferStatus::TRANSFER_ERROR);
|
linked.owner.contactModel->getAddedTs(
|
||||||
|
c.second.profileInfo.uri)));
|
||||||
interaction.transferStatus = interaction::TransferStatus::TRANSFER_ERROR;
|
|
||||||
}
|
}
|
||||||
});
|
addConversationWith(conv[0], c.first, isRequest);
|
||||||
|
|
||||||
|
auto convIdx = indexOf(conv[0]);
|
||||||
|
|
||||||
|
// Resolve any file transfer interactions were left in an incorrect state
|
||||||
|
auto& interactions = conversations[convIdx].interactions;
|
||||||
|
interactions->forEach([&](const QString& id, interaction::Info& interaction) {
|
||||||
|
if (interaction.transferStatus == interaction::TransferStatus::TRANSFER_CREATED
|
||||||
|
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_AWAITING_HOST
|
||||||
|
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_AWAITING_PEER
|
||||||
|
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_ONGOING
|
||||||
|
|| interaction.transferStatus == interaction::TransferStatus::TRANSFER_ACCEPTED) {
|
||||||
|
// If a datatransfer was left in a non-terminal status in DB, we switch this status
|
||||||
|
// to ERROR
|
||||||
|
// TODO : Improve for DBus clients as daemon and transfer may still be ongoing
|
||||||
|
storage::updateInteractionTransferStatus(db, id, interaction::TransferStatus::TRANSFER_ERROR);
|
||||||
|
|
||||||
|
interaction.transferStatus = interaction::TransferStatus::TRANSFER_ERROR;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
invalidateModel();
|
invalidateModel();
|
||||||
|
|
||||||
|
@ -3848,14 +3861,16 @@ ConversationModelPimpl::slotTransferStatusAwaitingHost(const QString& fileId,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ConversationModelPimpl::hasOneOneSwarmWith(const QString& participant)
|
ConversationModelPimpl::hasOneOneSwarmWith(const contact::Info& participant)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
auto& conversation = getConversationForPeerUri(participant).get();
|
if (!participant.conversationId.isEmpty()) {
|
||||||
return conversation.mode == conversation::Mode::ONE_TO_ONE;
|
auto& conversation = getConversationForUid(participant.conversationId).get();
|
||||||
|
return conversation.mode == conversation::Mode::ONE_TO_ONE;
|
||||||
|
}
|
||||||
} catch (std::out_of_range&) {
|
} catch (std::out_of_range&) {
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Reference in a new issue