Skip to content
Snippets Groups Projects
Commit 6f450ea4 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

jams: synchronize the blueprint config changes on Jami launch

Change-Id: I102d66970aaa90764d88e194fa2d3a1b8794bfb2
parent 9899ae3f
No related branches found
No related tags found
No related merge requests found
......@@ -1206,6 +1206,17 @@ JamiAccount::loadAccount(const std::string& archive_password,
setRegistrationState(RegistrationState::UNREGISTERED);
}
convModule()->loadConversations();
if (!conf.managerUri.empty()) {
if (accountManager_ == nullptr) {
return;
}
dynamic_cast<ServerAccountManager*>(accountManager_.get())
->syncBlueprintConfig([this](const std::map<std::string, std::string>& config) {
editConfig([&](JamiAccountConfig& conf) { conf.fromMap(config); });
emitSignal<libjami::ConfigurationSignal::AccountDetailsChanged>(getAccountID(),
getAccountDetails());
});
}
} else if (isEnabled()) {
JAMI_WARNING("[Account {}] useIdentity failed!", getAccountID());
if (not conf.managerUri.empty() and archive_password.empty()) {
......
......@@ -207,6 +207,7 @@ JamiAccountConfig::fromMap(const std::map<std::string, std::string>& details)
parseString(details, libjami::Account::ConfProperties::DHT_PROXY_LIST_URL, proxyListUrl);
parseBool(details, libjami::Account::ConfProperties::PROXY_ENABLED, proxyEnabled);
parseString(details, libjami::Account::ConfProperties::PROXY_SERVER, proxyServer);
parseString(details, libjami::Account::ConfProperties::UI_CUSTOMIZATION, uiCustomization);
if (not managerUri.empty() and managerUri.rfind("http", 0) != 0) {
managerUri = "https://" + managerUri;
}
......
......@@ -41,6 +41,7 @@ constexpr std::string_view PATH_DEVICE = JAMI_PATH_AUTH "/device";
constexpr std::string_view PATH_DEVICES = JAMI_PATH_AUTH "/devices";
constexpr std::string_view PATH_SEARCH = JAMI_PATH_AUTH "/directory/search";
constexpr std::string_view PATH_CONTACTS = JAMI_PATH_AUTH "/contacts";
constexpr std::string_view PATH_BLUEPRINT = JAMI_PATH_AUTH "/policyData";
ServerAccountManager::ServerAccountManager(const std::string& path,
const std::string& managerHostname,
......@@ -454,6 +455,37 @@ ServerAccountManager::syncDevices()
logger_));
}
void
ServerAccountManager::syncBlueprintConfig(SyncBlueprintCallback onSuccess)
{
auto syncBlueprintCallback = std::make_shared<SyncBlueprintCallback>(onSuccess);
const std::string urlBlueprints = managerHostname_ + PATH_BLUEPRINT;
JAMI_DEBUG("[Auth] synchronize blueprint configuration {}", urlBlueprints);
sendDeviceRequest(std::make_shared<Request>(
*Manager::instance().ioContext(),
urlBlueprints,
[syncBlueprintCallback, w=weak_from_this()](Json::Value json, const dht::http::Response& response) {
JAMI_DEBUG("[Auth] Got sync request callback with status code={}", response.status_code);
auto this_ = std::static_pointer_cast<ServerAccountManager>(w.lock());
if (!this_) return;
if (response.status_code >= 200 && response.status_code < 300) {
try {
std::map<std::string, std::string> config;
for (auto itr = json.begin(); itr != json.end(); ++itr) {
const auto& name = itr.name();
config.emplace(name, itr->asString());
}
(*syncBlueprintCallback)(config);
} catch (const std::exception& e) {
JAMI_ERROR("Error when iterating blueprint config json: {}", e.what());
}
} else if (response.status_code == 401)
this_->authError(TokenScope::Device);
this_->clearRequest(response.request);
},
logger_));
}
bool
ServerAccountManager::revokeDevice(const std::string& password,
const std::string& device,
......@@ -503,7 +535,6 @@ ServerAccountManager::registerName(const std::string&, const std::string&, Regis
bool
ServerAccountManager::searchUser(const std::string& query, SearchCallback cb)
{
// TODO escape url query
const std::string url = managerHostname_ + PATH_SEARCH + "?queryString=" + query;
JAMI_WARN("[Search] Searching user %s at %s", query.c_str(), url.c_str());
sendDeviceRequest(std::make_shared<Request>(
......
......@@ -55,6 +55,10 @@ public:
void syncDevices() override;
using SyncBlueprintCallback = std::function<void(const std::map<std::string, std::string>& config)>;
void syncBlueprintConfig(SyncBlueprintCallback onSuccess);
bool revokeDevice(const std::string& password,
const std::string& device,
RevokeDeviceCallback cb) override;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment