Sync contacts doesn't work for JAMS
Scenario
- Remove or re-add a contact on a JAMS account (Note: Just adding the contact is not enough to trigger the error).
Current result
[1695241407.656|13426|server_account_manager.cpp:395 ] [Auth] Got contact sync request callback with status code=500
[1695241407.657|13426] [http:request:55] end with error: stream truncated
[1695241407.657|13426] [http:request:55] can't parse response to json
JAMS is not updated
Code:
sendDeviceRequest(std::make_shared<Request>(
*Manager::instance().ioContext(),
urlContacts,
jsonContacts,
[w=weak_from_this()](Json::Value json, const dht::http::Response& response) {
JAMI_DBG("[Auth] Got contact sync request callback with status code=%u",
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 {
JAMI_WARN("[Auth] Got server response: %s", response.body.c_str());
if (not json.isArray()) {
JAMI_ERR("[Auth] Can't parse server response: not an array");
} else {
for (unsigned i = 0, n = json.size(); i < n; i++) {
const auto& e = json[i];
Contact contact(e);
this_->info_->contacts
->updateContact(dht::InfoHash {e["uri"].asString()}, contact);
}
this_->info_->contacts->saveContacts();
}
} catch (const std::exception& e) {
JAMI_ERR("Error when iterating contact list: %s", e.what());
}
} else if (response.status_code == 401)
this_->authError(TokenScope::Device);
this_->clearRequest(response.request);
},
logger_));
Edited by Sébastien Blin