conversation: fix getConversationMembers for one to one with self

Change-Id: I77b12b6b6ee8ae06930e776ca0637d43cd9b2586
GitLab: https://git.jami.net/savoirfairelinux/ring-project/-/issues/1282
This commit is contained in:
Sébastien Blin
2021-08-16 15:32:45 -04:00
parent 5f7970baa2
commit f7a5fe26f7
2 changed files with 35 additions and 5 deletions

View File

@ -1815,14 +1815,14 @@ ConversationRepository::Impl::initMembers()
std::lock_guard<std::mutex> lk(membersMtx_);
members_.clear();
std::string repoPath = git_repository_workdir(repo.get());
std::vector<std::string> paths = {repoPath + "/" + "invited",
repoPath + "/" + "admins",
std::vector<std::string> paths = {repoPath + "/" + "admins",
repoPath + "/" + "members",
repoPath + "/" + "invited",
repoPath + "/" + "banned" + "/" + "members"};
std::vector<MemberRole> roles = {
MemberRole::INVITED,
MemberRole::ADMIN,
MemberRole::MEMBER,
MemberRole::INVITED,
MemberRole::BANNED,
};
@ -1831,8 +1831,11 @@ ConversationRepository::Impl::initMembers()
for (const auto& f : fileutils::readDirectory(p)) {
auto pos = f.find(".crt");
auto uri = f.substr(0, pos);
uris.emplace_back(uri);
members_.emplace_back(ConversationMember {uri, roles[i]});
auto it = std::find(uris.begin(), uris.end(), uri);
if (it == uris.end()) {
members_.emplace_back(ConversationMember {uri, roles[i]});
uris.emplace_back(uri);
}
}
++i;
}

View File

@ -159,6 +159,7 @@ private:
void testGetConversationsMembersWhileSyncing();
void testRemoveContactRemoveSyncing();
void testCountInteractions();
void testGetConversationMembersWithSelfOneOne();
CPPUNIT_TEST_SUITE(ConversationTest);
CPPUNIT_TEST(testCreateConversation);
@ -219,6 +220,7 @@ private:
CPPUNIT_TEST(testGetConversationsMembersWhileSyncing);
CPPUNIT_TEST(testRemoveContactRemoveSyncing);
CPPUNIT_TEST(testCountInteractions);
CPPUNIT_TEST(testGetConversationMembersWithSelfOneOne);
CPPUNIT_TEST_SUITE_END();
};
@ -4673,6 +4675,31 @@ ConversationTest::testCountInteractions()
CPPUNIT_ASSERT(DRing::countInteractions(aliceId, convId, msgId2, "") == 1);
}
void
ConversationTest::testGetConversationMembersWithSelfOneOne()
{
auto aliceAccount = Manager::instance().getAccount<JamiAccount>(aliceId);
auto aliceUri = aliceAccount->getUsername();
std::mutex mtx;
std::unique_lock<std::mutex> lk {mtx};
std::condition_variable cv;
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> confHandlers;
std::string convId = "";
confHandlers.insert(DRing::exportable_callback<DRing::ConversationSignal::ConversationReady>(
[&](const std::string& accountId, const std::string& conversationId) {
if (accountId == aliceId)
convId = conversationId;
cv.notify_one();
}));
DRing::registerSignalHandlers(confHandlers);
aliceAccount->addContact(aliceUri);
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(5), [&]() { return !convId.empty(); }));
auto members = aliceAccount->getConversationMembers(convId);
CPPUNIT_ASSERT(members.size() == 1);
CPPUNIT_ASSERT(members[0]["uri"] == aliceUri);
}
} // namespace test
} // namespace jami