Skip to content
Snippets Groups Projects
Commit 04bfde0d authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

conference: check if conversation exists.

This patch excludes pending conversations from the conference
hosting search.

Change-Id: I3f414ef7a8e6e90d537acbac5c235dca7cd38f3e
parent a44c2fc1
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,8 @@ struct PendingConversationFetch ...@@ -51,7 +51,8 @@ struct PendingConversationFetch
std::shared_ptr<dhtnet::ChannelSocket> socket {}; std::shared_ptr<dhtnet::ChannelSocket> socket {};
}; };
struct SyncedConversation { struct SyncedConversation
{
std::mutex mtx; std::mutex mtx;
ConvInfo info; ConvInfo info;
std::unique_ptr<PendingConversationFetch> pending; std::unique_ptr<PendingConversationFetch> pending;
...@@ -94,8 +95,7 @@ struct SyncedConversation { ...@@ -94,8 +95,7 @@ struct SyncedConversation {
pending.reset(); pending.reset();
} }
std::vector<std::map<std::string, std::string>> std::vector<std::map<std::string, std::string>> getMembers(bool includeBanned = false) const
getMembers(bool includeBanned = false) const
{ {
// conversation mtx must be locked // conversation mtx must be locked
if (conversation) if (conversation)
...@@ -108,7 +108,6 @@ struct SyncedConversation { ...@@ -108,7 +108,6 @@ struct SyncedConversation {
} }
return result; return result;
} }
}; };
class ConversationModule::Impl : public std::enable_shared_from_this<Impl> class ConversationModule::Impl : public std::enable_shared_from_this<Impl>
...@@ -269,24 +268,28 @@ public: ...@@ -269,24 +268,28 @@ public:
std::string getOneToOneConversation(const std::string& uri) const noexcept; std::string getOneToOneConversation(const std::string& uri) const noexcept;
std::shared_ptr<SyncedConversation> getConversation(std::string_view convId) const { std::shared_ptr<SyncedConversation> getConversation(std::string_view convId) const
{
std::lock_guard<std::mutex> lk(conversationsMtx_); std::lock_guard<std::mutex> lk(conversationsMtx_);
auto c = conversations_.find(convId); auto c = conversations_.find(convId);
return c != conversations_.end() ? c->second : nullptr; return c != conversations_.end() ? c->second : nullptr;
} }
std::shared_ptr<SyncedConversation> getConversation(std::string_view convId) { std::shared_ptr<SyncedConversation> getConversation(std::string_view convId)
{
std::lock_guard<std::mutex> lk(conversationsMtx_); std::lock_guard<std::mutex> lk(conversationsMtx_);
auto c = conversations_.find(convId); auto c = conversations_.find(convId);
return c != conversations_.end() ? c->second : nullptr; return c != conversations_.end() ? c->second : nullptr;
} }
std::shared_ptr<SyncedConversation> startConversation(const std::string& convId) { std::shared_ptr<SyncedConversation> startConversation(const std::string& convId)
{
std::lock_guard<std::mutex> lk(conversationsMtx_); std::lock_guard<std::mutex> lk(conversationsMtx_);
auto& c = conversations_[convId]; auto& c = conversations_[convId];
if (!c) if (!c)
c = std::make_shared<SyncedConversation>(convId); c = std::make_shared<SyncedConversation>(convId);
return c; return c;
} }
std::shared_ptr<SyncedConversation> startConversation(const ConvInfo& info) { std::shared_ptr<SyncedConversation> startConversation(const ConvInfo& info)
{
std::lock_guard<std::mutex> lk(conversationsMtx_); std::lock_guard<std::mutex> lk(conversationsMtx_);
auto& c = conversations_[info.id]; auto& c = conversations_[info.id];
if (!c) if (!c)
...@@ -470,8 +473,9 @@ ConversationModule::Impl::cloneConversation(const std::string& deviceId, ...@@ -470,8 +473,9 @@ ConversationModule::Impl::cloneConversation(const std::string& deviceId,
conv->pending->socket = channel; conv->pending->socket = channel;
if (!conv->pending->cloning) { if (!conv->pending->cloning) {
conv->pending->cloning = true; conv->pending->cloning = true;
dht::ThreadPool::io().run( dht::ThreadPool::io().run([w = weak(),
[w = weak(), convId=conv->info.id, deviceId = conv->pending->deviceId]() { convId = conv->info.id,
deviceId = conv->pending->deviceId]() {
if (auto sthis = w.lock()) if (auto sthis = w.lock())
sthis->handlePendingConversation(convId, deviceId); sthis->handlePendingConversation(convId, deviceId);
}); });
...@@ -501,21 +505,16 @@ ConversationModule::Impl::cloneConversation(const std::string& deviceId, ...@@ -501,21 +505,16 @@ ConversationModule::Impl::cloneConversation(const std::string& deviceId,
} }
} }
void void
ConversationModule::Impl::fetchNewCommits(const std::string& peer, ConversationModule::Impl::fetchNewCommits(const std::string& peer,
const std::string& deviceId, const std::string& deviceId,
const std::string& conversationId, const std::string& conversationId,
const std::string& commitId) const std::string& commitId)
{ {
JAMI_LOG("[Account {}] fetch commits for peer {} on device {}", JAMI_LOG("[Account {}] fetch commits for peer {} on device {}", accountId_, peer, deviceId);
accountId_,
peer,
deviceId);
auto conv = getConversation(conversationId); auto conv = getConversation(conversationId);
if (!conv) { if (!conv) {
JAMI_WARNING("[Account {}] Could not find conversation {}, ask for an invite", JAMI_WARNING("[Account {}] Could not find conversation {}, ask for an invite",
accountId_, accountId_,
conversationId); conversationId);
...@@ -533,10 +532,7 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer, ...@@ -533,10 +532,7 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
return; return;
} }
if (!conv->conversation->isMember(peer, true)) { if (!conv->conversation->isMember(peer, true)) {
JAMI_WARNING("[Account {}] {} is not a member of {}", JAMI_WARNING("[Account {}] {} is not a member of {}", accountId_, peer, conversationId);
accountId_,
peer,
conversationId);
return; return;
} }
if (conv->conversation->isBanned(deviceId)) { if (conv->conversation->isBanned(deviceId)) {
...@@ -608,7 +604,10 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer, ...@@ -608,7 +604,10 @@ ConversationModule::Impl::fetchNewCommits(const std::string& peer,
conv->pending.reset(); conv->pending.reset();
// Notify peers that a new commit is there (DRT) // Notify peers that a new commit is there (DRT)
if (not commitId.empty()) { if (not commitId.empty()) {
shared->sendMessageNotification(*conv->conversation, false, commitId, deviceId); shared->sendMessageNotification(*conv->conversation,
false,
commitId,
deviceId);
} }
} }
if (shared->syncCnt.fetch_sub(1) == 1) { if (shared->syncCnt.fetch_sub(1) == 1) {
...@@ -669,10 +668,12 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat ...@@ -669,10 +668,12 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat
}; };
try { try {
auto conversation = std::make_shared<Conversation>(acc, deviceId, conversationId); auto conversation = std::make_shared<Conversation>(acc, deviceId, conversationId);
conversation->onLastDisplayedUpdated( conversation->onLastDisplayedUpdated([&](const auto& convId, const auto& lastId) {
[&](const auto& convId, const auto& lastId) { onLastDisplayedUpdated(convId, lastId); }); onLastDisplayedUpdated(convId, lastId);
conversation->onMembersChanged( });
[this, conversationId](const auto& members) { setConversationMembers(conversationId, members); }); conversation->onMembersChanged([this, conversationId](const auto& members) {
setConversationMembers(conversationId, members);
});
conversation->onNeedSocket(onNeedSwarmSocket_); conversation->onNeedSocket(onNeedSwarmSocket_);
if (!conversation->isMember(username_, true)) { if (!conversation->isMember(username_, true)) {
JAMI_ERR("Conversation cloned but doesn't seems to be a valid member"); JAMI_ERR("Conversation cloned but doesn't seems to be a valid member");
...@@ -725,8 +726,10 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat ...@@ -725,8 +726,10 @@ ConversationModule::Impl::handlePendingConversation(const std::string& conversat
#ifdef LIBJAMI_TESTABLE #ifdef LIBJAMI_TESTABLE
conversation->onBootstrapStatus(bootstrapCbTest_); conversation->onBootstrapStatus(bootstrapCbTest_);
#endif // LIBJAMI_TESTABLE #endif // LIBJAMI_TESTABLE
conversation->bootstrap( conversation->bootstrap(std::bind(&ConversationModule::Impl::bootstrapCb,
std::bind(&ConversationModule::Impl::bootstrapCb, this, conversation->id()), kd); this,
conversation->id()),
kd);
if (!lastDisplayedInfo.empty()) if (!lastDisplayedInfo.empty())
conversation->updateLastDisplayed(lastDisplayedInfo); conversation->updateLastDisplayed(lastDisplayedInfo);
...@@ -816,8 +819,7 @@ ConversationModule::Impl::declineOtherConversationWith(const std::string& uri) n ...@@ -816,8 +819,7 @@ ConversationModule::Impl::declineOtherConversationWith(const std::string& uri) n
if (request.isOneToOne() && request.from == uri) { if (request.isOneToOne() && request.from == uri) {
JAMI_WARNING("Decline conversation request ({}) from {}", id, uri); JAMI_WARNING("Decline conversation request ({}) from {}", id, uri);
request.declined = std::time(nullptr); request.declined = std::time(nullptr);
emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>(accountId_, emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>(accountId_, id);
id);
} }
} }
} }
...@@ -826,7 +828,8 @@ std::vector<std::map<std::string, std::string>> ...@@ -826,7 +828,8 @@ std::vector<std::map<std::string, std::string>>
ConversationModule::Impl::getConversationMembers(const std::string& conversationId, ConversationModule::Impl::getConversationMembers(const std::string& conversationId,
bool includeBanned) const bool includeBanned) const
{ {
return withConv(conversationId, [&](const auto& conv) { return conv.getMembers(includeBanned); }); return withConv(conversationId,
[&](const auto& conv) { return conv.getMembers(includeBanned); });
} }
void void
...@@ -875,9 +878,7 @@ ConversationModule::Impl::removeRepositoryImpl(SyncedConversation& conv, bool sy ...@@ -875,9 +878,7 @@ ConversationModule::Impl::removeRepositoryImpl(SyncedConversation& conv, bool sy
bool bool
ConversationModule::Impl::removeConversation(const std::string& conversationId) ConversationModule::Impl::removeConversation(const std::string& conversationId)
{ {
return withConv(conversationId, [this](auto& conv) { return withConv(conversationId, [this](auto& conv) { return removeConversationImpl(conv); });
return removeConversationImpl(conv);
});
} }
bool bool
...@@ -1058,12 +1059,14 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId, ...@@ -1058,12 +1059,14 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId,
if (auto conv = getConversation(conversationId)) { if (auto conv = getConversation(conversationId)) {
std::lock_guard<std::mutex> lk(conv->mtx); std::lock_guard<std::mutex> lk(conv->mtx);
if (conv->conversation) if (conv->conversation)
conv->conversation->sendMessage( conv->conversation
std::move(value), ->sendMessage(std::move(value),
replyTo, replyTo,
std::move(onCommit), std::move(onCommit),
[this, conversationId, announce, cb = std::move(cb)](bool ok, [this,
const std::string& commitId) { conversationId,
announce,
cb = std::move(cb)](bool ok, const std::string& commitId) {
if (cb) if (cb)
cb(ok, commitId); cb(ok, commitId);
if (!announce) if (!announce)
...@@ -1071,7 +1074,8 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId, ...@@ -1071,7 +1074,8 @@ ConversationModule::Impl::sendMessage(const std::string& conversationId,
if (ok) if (ok)
sendMessageNotification(conversationId, true, commitId); sendMessageNotification(conversationId, true, commitId);
else else
JAMI_ERR("Failed to send message to conversation %s", conversationId.c_str()); JAMI_ERR("Failed to send message to conversation %s",
conversationId.c_str());
}); });
} }
} }
...@@ -1214,13 +1218,13 @@ ConversationModule::loadConversations() ...@@ -1214,13 +1218,13 @@ ConversationModule::loadConversations()
auto sconv = std::make_shared<SyncedConversation>(repository); auto sconv = std::make_shared<SyncedConversation>(repository);
auto conv = std::make_shared<Conversation>(acc, repository); auto conv = std::make_shared<Conversation>(acc, repository);
conv->onLastDisplayedUpdated( conv->onLastDisplayedUpdated([w = pimpl_->weak_from_this()](auto convId, auto lastId) {
[w=pimpl_->weak_from_this()](auto convId, auto lastId) { if (auto p = w.lock())
if (auto p=w.lock()) p->onLastDisplayedUpdated(convId, lastId); p->onLastDisplayedUpdated(convId, lastId);
}); });
conv->onMembersChanged( conv->onMembersChanged([w = pimpl_->weak_from_this(), repository](const auto& members) {
[w=pimpl_->weak_from_this(), repository](const auto& members) { if (auto p = w.lock())
if (auto p=w.lock()) p->setConversationMembers(repository, members); p->setConversationMembers(repository, members);
}); });
conv->onNeedSocket(pimpl_->onNeedSwarmSocket_); conv->onNeedSocket(pimpl_->onNeedSwarmSocket_);
auto members = conv->memberUris(uri, {}); auto members = conv->memberUris(uri, {});
...@@ -1296,9 +1300,12 @@ ConversationModule::loadConversations() ...@@ -1296,9 +1300,12 @@ ConversationModule::loadConversations()
if (itConv == pimpl_->conversations_.end()) { if (itConv == pimpl_->conversations_.end()) {
// convInfos_ can contain a conversation that is not yet cloned // convInfos_ can contain a conversation that is not yet cloned
// so we need to add it there. // so we need to add it there.
itConv = pimpl_->conversations_.emplace(info.id, std::make_shared<SyncedConversation>(info)).first; itConv = pimpl_->conversations_
.emplace(info.id, std::make_shared<SyncedConversation>(info))
.first;
} }
if (itConv != pimpl_->conversations_.end() && itConv->second && itConv->second->conversation && info.removed) if (itConv != pimpl_->conversations_.end() && itConv->second && itConv->second->conversation
&& info.removed)
itConv->second->conversation->setRemovingFlag(); itConv->second->conversation->setRemovingFlag();
if (!info.removed && itConv == pimpl_->conversations_.end()) { if (!info.removed && itConv == pimpl_->conversations_.end()) {
// In this case, the conversation is not synced and we only know ourself // In this case, the conversation is not synced and we only know ourself
...@@ -1378,8 +1385,10 @@ ConversationModule::bootstrap(const std::string& convId) ...@@ -1378,8 +1385,10 @@ ConversationModule::bootstrap(const std::string& convId)
#ifdef LIBJAMI_TESTABLE #ifdef LIBJAMI_TESTABLE
conv->onBootstrapStatus(pimpl_->bootstrapCbTest_); conv->onBootstrapStatus(pimpl_->bootstrapCbTest_);
#endif // LIBJAMI_TESTABLE #endif // LIBJAMI_TESTABLE
conv->bootstrap( conv->bootstrap(std::bind(&ConversationModule::Impl::bootstrapCb,
std::bind(&ConversationModule::Impl::bootstrapCb, pimpl_.get(), conv->id()), kd); pimpl_.get(),
conv->id()),
kd);
} }
}; };
std::vector<std::string> toClone; std::vector<std::string> toClone;
...@@ -1633,13 +1642,17 @@ ConversationModule::startConversation(ConversationMode mode, const std::string& ...@@ -1633,13 +1642,17 @@ ConversationModule::startConversation(ConversationMode mode, const std::string&
conversation->onLastDisplayedUpdated( conversation->onLastDisplayedUpdated(
[&](auto convId, auto lastId) { pimpl_->onLastDisplayedUpdated(convId, lastId); }); [&](auto convId, auto lastId) { pimpl_->onLastDisplayedUpdated(convId, lastId); });
conversation->onMembersChanged( conversation->onMembersChanged(
[this, conversationId=conversation->id()](const auto& members) { pimpl_->setConversationMembers(conversationId, members); }); [this, conversationId = conversation->id()](const auto& members) {
pimpl_->setConversationMembers(conversationId, members);
});
conversation->onNeedSocket(pimpl_->onNeedSwarmSocket_); conversation->onNeedSocket(pimpl_->onNeedSwarmSocket_);
#ifdef LIBJAMI_TESTABLE #ifdef LIBJAMI_TESTABLE
conversation->onBootstrapStatus(pimpl_->bootstrapCbTest_); conversation->onBootstrapStatus(pimpl_->bootstrapCbTest_);
#endif // LIBJAMI_TESTABLE #endif // LIBJAMI_TESTABLE
conversation->bootstrap( conversation->bootstrap(std::bind(&ConversationModule::Impl::bootstrapCb,
std::bind(&ConversationModule::Impl::bootstrapCb, pimpl_.get(), conversation->id()), kd); pimpl_.get(),
conversation->id()),
kd);
} catch (const std::exception& e) { } catch (const std::exception& e) {
JAMI_ERR("[Account %s] Error while generating a conversation %s", JAMI_ERR("[Account %s] Error while generating a conversation %s",
pimpl_->accountId_.c_str(), pimpl_->accountId_.c_str(),
...@@ -1681,7 +1694,8 @@ ConversationModule::cloneConversationFrom(const std::string& conversationId, ...@@ -1681,7 +1694,8 @@ ConversationModule::cloneConversationFrom(const std::string& conversationId,
std::lock_guard<std::mutex> lk(conv->mtx); std::lock_guard<std::mutex> lk(conv->mtx);
acc->forEachDevice(memberHash, acc->forEachDevice(
memberHash,
[w = pimpl_->weak(), conv, conversationId, oldConvId]( [w = pimpl_->weak(), conv, conversationId, oldConvId](
const std::shared_ptr<dht::crypto::PublicKey>& pk) { const std::shared_ptr<dht::crypto::PublicKey>& pk) {
auto sthis = w.lock(); auto sthis = w.lock();
...@@ -1689,7 +1703,6 @@ ConversationModule::cloneConversationFrom(const std::string& conversationId, ...@@ -1689,7 +1703,6 @@ ConversationModule::cloneConversationFrom(const std::string& conversationId,
if (!sthis or deviceId == sthis->deviceId_) if (!sthis or deviceId == sthis->deviceId_)
return; return;
std::lock_guard<std::mutex> lk(conv->mtx); std::lock_guard<std::mutex> lk(conv->mtx);
if (!conv->startFetch(deviceId, true)) { if (!conv->startFetch(deviceId, true)) {
JAMI_WARNING("[Account {}] Already fetching {}", sthis->accountId_, conversationId); JAMI_WARNING("[Account {}] Already fetching {}", sthis->accountId_, conversationId);
...@@ -1711,8 +1724,9 @@ ConversationModule::cloneConversationFrom(const std::string& conversationId, ...@@ -1711,8 +1724,9 @@ ConversationModule::cloneConversationFrom(const std::string& conversationId,
conv->pending->socket = channel; conv->pending->socket = channel;
if (!conv->pending->cloning) { if (!conv->pending->cloning) {
conv->pending->cloning = true; conv->pending->cloning = true;
dht::ThreadPool::io().run( dht::ThreadPool::io().run([w = sthis->weak(),
[w = sthis->weak(), conversationId, deviceId = conv->pending->deviceId]() { conversationId,
deviceId = conv->pending->deviceId]() {
if (auto sthis = w.lock()) if (auto sthis = w.lock())
sthis->handlePendingConversation(conversationId, deviceId); sthis->handlePendingConversation(conversationId, deviceId);
}); });
...@@ -1811,9 +1825,7 @@ ConversationModule::onMessageDisplayed(const std::string& peer, ...@@ -1811,9 +1825,7 @@ ConversationModule::onMessageDisplayed(const std::string& peer,
lk.unlock(); lk.unlock();
if (conversation->setMessageDisplayed(peer, interactionId)) { if (conversation->setMessageDisplayed(peer, interactionId)) {
auto msg = std::make_shared<SyncMsg>(); auto msg = std::make_shared<SyncMsg>();
msg->ld = { msg->ld = {{conversationId, conversation->displayed()}};
{conversationId, conversation->displayed()}
};
pimpl_->needsSyncingCb_(std::move(msg)); pimpl_->needsSyncingCb_(std::move(msg));
return true; return true;
} }
...@@ -1895,9 +1907,8 @@ ConversationModule::loadConversationUntil(const std::string& conversationId, ...@@ -1895,9 +1907,8 @@ ConversationModule::loadConversationUntil(const std::string& conversationId,
std::shared_ptr<TransferManager> std::shared_ptr<TransferManager>
ConversationModule::dataTransfer(const std::string& conversationId) const ConversationModule::dataTransfer(const std::string& conversationId) const
{ {
return pimpl_->withConversation(conversationId, [](auto& conversation) { return pimpl_->withConversation(conversationId,
return conversation.dataTransfer(); [](auto& conversation) { return conversation.dataTransfer(); });
});
} }
bool bool
...@@ -1995,7 +2006,8 @@ ConversationModule::onSyncData(const SyncMsg& msg, ...@@ -1995,7 +2006,8 @@ ConversationModule::onSyncData(const SyncMsg& msg,
pimpl_->cloneConversation(deviceId, peerId, conv, convInfo.lastDisplayed); pimpl_->cloneConversation(deviceId, peerId, conv, convInfo.lastDisplayed);
} else { } else {
if (conv->conversation && !conv->conversation->isRemoving()) { if (conv->conversation && !conv->conversation->isRemoving()) {
emitSignal<libjami::ConversationSignal::ConversationRemoved>(pimpl_->accountId_, convId); emitSignal<libjami::ConversationSignal::ConversationRemoved>(pimpl_->accountId_,
convId);
conv->conversation->setRemovingFlag(); conv->conversation->setRemovingFlag();
} }
auto update = false; auto update = false;
...@@ -2127,8 +2139,7 @@ ConversationModule::onNewCommit(const std::string& peer, ...@@ -2127,8 +2139,7 @@ ConversationModule::onNewCommit(const std::string& peer,
conversationId); conversationId);
pimpl_->sendMsgCb_(peer, pimpl_->sendMsgCb_(peer,
{}, {},
std::map<std::string, std::string> { std::map<std::string, std::string> {{MIME_TYPE_INVITE, conversationId}},
{MIME_TYPE_INVITE, conversationId}},
0); 0);
return; return;
} }
...@@ -2163,10 +2174,9 @@ ConversationModule::addConversationMember(const std::string& conversationId, ...@@ -2163,10 +2174,9 @@ ConversationModule::addConversationMember(const std::string& conversationId,
return; return;
} }
conv->conversation conv->conversation->addMember(
->addMember(contactUri, contactUri,
[this, conv, conversationId, sendRequest, contactUri](bool ok, [this, conv, conversationId, sendRequest, contactUri](bool ok, const std::string& commitId) {
const std::string& commitId) {
if (ok) { if (ok) {
std::unique_lock<std::mutex> lk(conv->mtx); std::unique_lock<std::mutex> lk(conv->mtx);
pimpl_->sendMessageNotification(*conv->conversation, pimpl_->sendMessageNotification(*conv->conversation,
...@@ -2189,12 +2199,10 @@ ConversationModule::removeConversationMember(const std::string& conversationId, ...@@ -2189,12 +2199,10 @@ ConversationModule::removeConversationMember(const std::string& conversationId,
if (auto conv = pimpl_->getConversation(conversationId)) { if (auto conv = pimpl_->getConversation(conversationId)) {
std::lock_guard<std::mutex> lk(conv->mtx); std::lock_guard<std::mutex> lk(conv->mtx);
if (conv->conversation) if (conv->conversation)
return conv->conversation->removeMember(contactUri, isDevice, return conv->conversation->removeMember(
[this, conversationId](bool ok, const std::string& commitId) { contactUri, isDevice, [this, conversationId](bool ok, const std::string& commitId) {
if (ok) { if (ok) {
pimpl_->sendMessageNotification(conversationId, pimpl_->sendMessageNotification(conversationId, true, commitId);
true,
commitId);
} }
}); });
} }
...@@ -2259,8 +2267,8 @@ ConversationModule::updateConversationInfos(const std::string& conversationId, ...@@ -2259,8 +2267,8 @@ ConversationModule::updateConversationInfos(const std::string& conversationId,
return; return;
} }
std::lock_guard<std::mutex> lk(conv->mtx); std::lock_guard<std::mutex> lk(conv->mtx);
conv->conversation->updateInfos(infos, conv->conversation
[this, conversationId, sync](bool ok, const std::string& commitId) { ->updateInfos(infos, [this, conversationId, sync](bool ok, const std::string& commitId) {
if (ok && sync) { if (ok && sync) {
pimpl_->sendMessageNotification(conversationId, true, commitId); pimpl_->sendMessageNotification(conversationId, true, commitId);
} else if (sync) } else if (sync)
...@@ -2302,9 +2310,7 @@ ConversationModule::setConversationPreferences(const std::string& conversationId ...@@ -2302,9 +2310,7 @@ ConversationModule::setConversationPreferences(const std::string& conversationId
lk.unlock(); lk.unlock();
conversation->updatePreferences(prefs); conversation->updatePreferences(prefs);
auto msg = std::make_shared<SyncMsg>(); auto msg = std::make_shared<SyncMsg>();
msg->p = { msg->p = {{conversationId, conversation->preferences(true)}};
{conversationId, conversation->preferences(true)}
};
pimpl_->needsSyncingCb_(std::move(msg)); pimpl_->needsSyncingCb_(std::move(msg));
} }
} }
...@@ -2360,7 +2366,8 @@ ConversationModule::isBanned(const std::string& convId, const std::string& uri) ...@@ -2360,7 +2366,8 @@ ConversationModule::isBanned(const std::string& convId, const std::string& uri)
} }
// If 1:1 we check the certificate status // If 1:1 we check the certificate status
if (auto acc = pimpl_->account_.lock()) { if (auto acc = pimpl_->account_.lock()) {
return acc->accountManager()->getCertificateStatus(uri) == dhtnet::tls::TrustStore::PermissionStatus::BANNED; return acc->accountManager()->getCertificateStatus(uri)
== dhtnet::tls::TrustStore::PermissionStatus::BANNED;
} }
return true; return true;
} }
...@@ -2372,7 +2379,9 @@ ConversationModule::removeContact(const std::string& uri, bool banned) ...@@ -2372,7 +2379,9 @@ ConversationModule::removeContact(const std::string& uri, bool banned)
{ {
std::lock_guard<std::mutex> lk(pimpl_->conversationsRequestsMtx_); std::lock_guard<std::mutex> lk(pimpl_->conversationsRequestsMtx_);
auto update = false; auto update = false;
for (auto it = pimpl_->conversationsRequests_.begin(); it != pimpl_->conversationsRequests_.end(); ++it) { for (auto it = pimpl_->conversationsRequests_.begin();
it != pimpl_->conversationsRequests_.end();
++it) {
if (it->second.from == uri && !it->second.declined) { if (it->second.from == uri && !it->second.declined) {
JAMI_DEBUG("Declining conversation request {:s} from {:s}", it->first, uri); JAMI_DEBUG("Declining conversation request {:s} from {:s}", it->first, uri);
emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>( emitSignal<libjami::ConversationSignal::ConversationRequestDeclined>(
...@@ -2471,7 +2480,10 @@ ConversationModule::isHosting(const std::string& conversationId, const std::stri ...@@ -2471,7 +2480,10 @@ ConversationModule::isHosting(const std::string& conversationId, const std::stri
std::lock_guard<std::mutex> lk(pimpl_->conversationsMtx_); std::lock_guard<std::mutex> lk(pimpl_->conversationsMtx_);
return std::find_if(pimpl_->conversations_.cbegin(), return std::find_if(pimpl_->conversations_.cbegin(),
pimpl_->conversations_.cend(), pimpl_->conversations_.cend(),
[&](const auto& conv) { return conv.second->conversation->isHosting(confId); }) [&](const auto& conv) {
return conv.second->conversation
&& conv.second->conversation->isHosting(confId);
})
!= pimpl_->conversations_.cend(); != pimpl_->conversations_.cend();
} else if (auto conv = pimpl_->getConversation(conversationId)) { } else if (auto conv = pimpl_->getConversation(conversationId)) {
if (conv->conversation) { if (conv->conversation) {
...@@ -2533,7 +2545,8 @@ ConversationModule::call(const std::string& url, ...@@ -2533,7 +2545,8 @@ ConversationModule::call(const std::string& url,
}; };
auto conv = pimpl_->getConversation(conversationId); auto conv = pimpl_->getConversation(conversationId);
if (!conv) return; if (!conv)
return;
std::unique_lock<std::mutex> lk(conv->mtx); std::unique_lock<std::mutex> lk(conv->mtx);
if (!conv->conversation) { if (!conv->conversation) {
JAMI_ERROR("Conversation {:s} not found", conversationId); JAMI_ERROR("Conversation {:s} not found", conversationId);
...@@ -2632,7 +2645,8 @@ ConversationModule::hostConference(const std::string& conversationId, ...@@ -2632,7 +2645,8 @@ ConversationModule::hostConference(const std::string& conversationId,
} }
auto conv = pimpl_->getConversation(conversationId); auto conv = pimpl_->getConversation(conversationId);
if (!conv) return; if (!conv)
return;
std::unique_lock<std::mutex> lk(conv->mtx); std::unique_lock<std::mutex> lk(conv->mtx);
if (!conv->conversation) { if (!conv->conversation) {
JAMI_ERROR("Conversation {} not found", conversationId); JAMI_ERROR("Conversation {} not found", conversationId);
...@@ -2645,10 +2659,13 @@ ConversationModule::hostConference(const std::string& conversationId, ...@@ -2645,10 +2659,13 @@ ConversationModule::hostConference(const std::string& conversationId,
value["confId"] = confId; value["confId"] = confId;
value["type"] = "application/call-history+json"; value["type"] = "application/call-history+json";
conv->conversation->hostConference(std::move(value), conv->conversation->hostConference(std::move(value),
[w = pimpl_->weak(), conversationId](bool ok, const std::string& commitId) { [w = pimpl_->weak(),
conversationId](bool ok, const std::string& commitId) {
if (ok) { if (ok) {
if (auto shared = w.lock()) if (auto shared = w.lock())
shared->sendMessageNotification(conversationId, true, commitId); shared->sendMessageNotification(conversationId,
true,
commitId);
} else { } else {
JAMI_ERR("Failed to send message to conversation %s", JAMI_ERR("Failed to send message to conversation %s",
conversationId.c_str()); conversationId.c_str());
...@@ -2794,9 +2811,7 @@ ConversationModule::addGitSocket(std::string_view deviceId, ...@@ -2794,9 +2811,7 @@ ConversationModule::addGitSocket(std::string_view deviceId,
void void
ConversationModule::removeGitSocket(std::string_view deviceId, std::string_view convId) ConversationModule::removeGitSocket(std::string_view deviceId, std::string_view convId)
{ {
pimpl_->withConversation(convId, [&](auto& conv) { pimpl_->withConversation(convId, [&](auto& conv) { conv.removeGitSocket(DeviceId(deviceId)); });
conv.removeGitSocket(DeviceId(deviceId));
});
} }
void void
...@@ -2814,9 +2829,8 @@ void ...@@ -2814,9 +2829,8 @@ void
ConversationModule::addSwarmChannel(const std::string& conversationId, ConversationModule::addSwarmChannel(const std::string& conversationId,
std::shared_ptr<dhtnet::ChannelSocket> channel) std::shared_ptr<dhtnet::ChannelSocket> channel)
{ {
pimpl_->withConversation(conversationId, [&](auto& conv) { pimpl_->withConversation(conversationId,
conv.addSwarmChannel(std::move(channel)); [&](auto& conv) { conv.addSwarmChannel(std::move(channel)); });
});
} }
void void
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment