Skip to content

Commit

Permalink
account: add option for loading all conversations
Browse files Browse the repository at this point in the history
For backward compatibility with jami versions that do not yet
send a conversation ID in the request, this patch adds the option
to load all conversations.

Change-Id: I0764d46c635aa3dd05be7adc991918ff53f2c673
  • Loading branch information
katekm committed Feb 26, 2024
1 parent 143df26 commit 4cd76d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/client/configurationmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ setAccountActive(const std::string& accountId, bool enable, bool shutdownConnect
}

void
loadAccountAndConversation(const std::string& accountID, const std::string& convID)
loadAccountAndConversation(const std::string& accountId, bool loadAll, const std::string& convId)
{
jami::Manager::instance().loadAccountAndConversation(accountID, convID);
jami::Manager::instance().loadAccountAndConversation(accountId, loadAll, convId);
}

void
Expand Down
5 changes: 3 additions & 2 deletions src/jami/configurationmanager_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ LIBJAMI_PUBLIC void setAccountDetails(const std::string& accountId,
LIBJAMI_PUBLIC void setAccountActive(const std::string& accountId,
bool active,
bool shutdownConnections = false);
LIBJAMI_PUBLIC void loadAccountAndConversation(const std::string& accountID,
const std::string& convID);
LIBJAMI_PUBLIC void loadAccountAndConversation(const std::string& accountId,
bool loadAll,
const std::string& convId);
LIBJAMI_PUBLIC std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
LIBJAMI_PUBLIC std::string addAccount(const std::map<std::string, std::string>& details,
const std::string& accountId = {});
Expand Down
19 changes: 13 additions & 6 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3056,9 +3056,11 @@ Manager::setAccountActive(const std::string& accountID, bool active, bool shutdo
}

void
Manager::loadAccountAndConversation(const std::string& accountID, const std::string& convID)
Manager::loadAccountAndConversation(const std::string& accountId,
bool loadAll,
const std::string& convId)
{
auto account = getAccount(accountID);
auto account = getAccount(accountId);
if (!account && !autoLoad) {
/*
With the LIBJAMI_FLAG_NO_AUTOLOAD flag active, accounts are not
Expand All @@ -3068,9 +3070,9 @@ Manager::loadAccountAndConversation(const std::string& accountID, const std::str
account creation now occurs here in response to a received notification.
*/
auto accountBaseDir = fileutils::get_data_dir();
auto configFile = accountBaseDir / accountID / "config.yml";
auto configFile = accountBaseDir / accountId / "config.yml";
try {
if (account = accountFactory.createAccount(JamiAccount::ACCOUNT_TYPE, accountID)) {
if (account = accountFactory.createAccount(JamiAccount::ACCOUNT_TYPE, accountId)) {
account->enableAutoLoadConversations(false);
auto configNode = YAML::LoadFile(configFile.string());
auto config = account->buildConfig();
Expand All @@ -3082,8 +3084,9 @@ Manager::loadAccountAndConversation(const std::string& accountID, const std::str
return;
}
}

if (!account) {
JAMI_WARN("Could not load account %s", accountID.c_str());
JAMI_WARN("Could not load account %s", accountId.c_str());
return;
}
if (auto jamiAcc = std::dynamic_pointer_cast<JamiAccount>(account)) {
Expand All @@ -3092,8 +3095,12 @@ Manager::loadAccountAndConversation(const std::string& accountID, const std::str
jamiAcc->doRegister();
if (auto convModule = jamiAcc->convModule()) {
convModule->reloadRequests();
if (loadAll) {
convModule->loadConversations();
} else {
jamiAcc->loadConversation(convId);
}
}
jamiAcc->loadConversation(convID);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ class LIBJAMI_TESTABLE Manager
const std::map<std::string, ::std::string>& details);

void setAccountActive(const std::string& accountID, bool active, bool shutdownConnections);
void loadAccountAndConversation(const std::string& accountID, const std::string& convID);
void loadAccountAndConversation(const std::string& accountId,
bool loadAll,
const std::string& convId);

std::mt19937_64 getSeededRandomEngine();

Expand Down

0 comments on commit 4cd76d1

Please sign in to comment.