Commit 615117d2 authored by Sébastien Blin's avatar Sébastien Blin Committed by Andreas Traczyk

newaccountmodel: link to namedirectory

Change-Id: I62c9fa51b8e9d26d74c53adb42539eba4a37dfca
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent 1539584d
......@@ -131,6 +131,13 @@ public:
* @throws out_of_range exception if account is not found
*/
void setAvatar(const std::string& accountId, const std::string& avatar);
/**
* Try to register a name
* @param accountId
* @param password
* @param username
* @return string like bootstrap1:port1;bootstrap2:port2;...
*/
/**
* Try to register a name
* @param accountId
......
......@@ -74,11 +74,6 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
this,
&CallbacksHandler::slotAccountMessageStatusChanged);
connect(&NameDirectory::instance(),
&NameDirectory::registeredNameFound,
this,
&CallbacksHandler::slotRegisteredNameFound);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::accountDetailsChanged,
this,
......@@ -138,6 +133,16 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent)
&ConfigurationManagerInterface::exportOnRingEnded,
this,
&CallbacksHandler::slotExportOnRingEnded);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::nameRegistrationEnded,
this,
&CallbacksHandler::slotNameRegistrationEnded);
connect(&ConfigurationManager::instance(),
&ConfigurationManagerInterface::registeredNameFound,
this,
&CallbacksHandler::slotRegisteredNameFound);
}
CallbacksHandler::~CallbacksHandler()
......@@ -200,18 +205,6 @@ CallbacksHandler::slotIncomingContactRequest(const QString& accountId,
emit incomingContactRequest(accountId.toStdString(), ringId.toStdString(), payload.toStdString());
}
void
CallbacksHandler::slotRegisteredNameFound(const Account* account, NameDirectory::LookupStatus status,
const QString& address, const QString& name)
{
if (!account) return;
if (status == NameDirectory::LookupStatus::SUCCESS) {
emit registeredNameFound(account->id().toStdString(), address.toStdString(), name.toStdString());
} else if((!address.trimmed().isEmpty() || !name.trimmed().isEmpty())) {
emit registeredNameNotFound(account->id().toStdString(), address.toStdString(), name.toStdString());
}
}
void
CallbacksHandler::slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri)
{
......@@ -381,4 +374,17 @@ CallbacksHandler::slotExportOnRingEnded(const QString& accountId, int status, co
emit exportOnRingEnded(accountId.toStdString(), status, pin.toStdString());
}
void
CallbacksHandler::slotNameRegistrationEnded(const QString& accountId, int status, const QString& name)
{
emit nameRegistrationEnded(accountId.toStdString(), status, name.toStdString());
}
void
CallbacksHandler::slotRegisteredNameFound(const QString& accountId, int status, const QString& address, const QString& name)
{
emit registeredNameFound(accountId.toStdString(), status, address.toStdString(), name.toStdString());
}
} // namespace lrc
......@@ -118,25 +118,6 @@ Q_SIGNALS:
* @param status the new status
*/
void accountStatusChanged(const std::string& accountId, const api::account::Status status);
/**
* Connect this signal to know when a registeredName is found
* @param accountId the account who receives this signal
* @param uri the URI of the profile found
* @param registeredName the registeredName linked to this URI
*/
void registeredNameFound(const std::string& accountId,
const std::string& uri,
const std::string& registeredName);
/**
* Connect this signal to know when a name is not found
* @param accountId the account who receives this signal
* @param uri the search uri
* @param name the search name
*/
void registeredNameNotFound(const std::string& accountId,
const std::string& uri,
const std::string& name);
/**
* Connect this signal to know where a VCard is incoming
* @param callId the call linked to this VCard
......@@ -218,6 +199,22 @@ Q_SIGNALS:
*/
void exportOnRingEnded(const std::string& accountId, int status, const std::string& pin);
/**
* Name registration has ended
* @param accountId
* @param status
* @param name
*/
void nameRegistrationEnded(const std::string& accountId, int status, const std::string& name);
/**
* Name registration has been found
* @param accountId
* @param status
* @param name
*/
void registeredNameFound(const std::string& accountId, int status, const std::string& address, const std::string& name);
private Q_SLOTS:
/**
* Emit newAccountMessage
......@@ -281,17 +278,6 @@ private Q_SLOTS:
const QString& registration_state,
unsigned detail_code,
const QString& detail_str);
/**
* Listen from the daemon when a profile is found.
* @param account account linked.
* @param status if the method succeeds
* @param address the URI of the profile
* @param name registeredName
*/
void slotRegisteredNameFound(const Account* account,
NameDirectory::LookupStatus status,
const QString& address,
const QString& name);
/**
* Get the URI of the peer and emit incomingCall
* @param accountId account linked
......@@ -371,6 +357,22 @@ private Q_SLOTS:
*/
void slotExportOnRingEnded(const QString& accountId, int status, const QString& pin);
/**
* Emit nameRegistrationEnded
* @param accountId
* @param status
* @param name
*/
void slotNameRegistrationEnded(const QString& accountId, int status, const QString& name);
/**
* Emit registeredNameFound
* @param accountId
* @param status
* @param name
*/
void slotRegisteredNameFound(const QString& accountId, int status, const QString& address, const QString& name);
private:
const api::Lrc& parent;
};
......
......@@ -115,17 +115,11 @@ public Q_SLOTS:
/**
* Listen CallbacksHandler when a registeredName is found
* @param accountId account linked
* @param status (0 = SUCCESS, 1 = Not found, 2 = Network error)
* @param uri of the contact found
* @param registeredName of the contact found
*/
void slotRegisteredNameFound(const std::string& accountId, const std::string& uri, const std::string& registeredName);
/**
* Listen CallbacksHandler when a name is not found
* @param accountId account linked
* @param uri the uri to search
* @param name the name to search
*/
void slotRegisteredNameNotFound(const std::string& accountId, const std::string& uri, const std::string& name);
void slotRegisteredNameFound(const std::string& accountId, int status, const std::string& uri, const std::string& registeredName);
/**
* Listen CallbacksHandler when an incoming request arrives
* @param accountId account linked
......@@ -189,7 +183,7 @@ ContactModel::pendingRequestCount() const
{
std::lock_guard<std::mutex> lk(pimpl_->contactsMtx_);
int pendingRequestCount = 0;
auto i = std::for_each(pimpl_->contacts.begin(), pimpl_->contacts.end(),
std::for_each(pimpl_->contacts.begin(), pimpl_->contacts.end(),
[&pendingRequestCount] (const auto& c) {
if (!c.second.isBanned)
pendingRequestCount += static_cast<int>(c.second.profileInfo.type == profile::Type::PENDING);
......@@ -415,8 +409,6 @@ ContactModelPimpl::ContactModelPimpl(const ContactModel& linked,
this, &ContactModelPimpl::slotIncomingContactRequest);
connect(&callbacksHandler, &CallbacksHandler::registeredNameFound,
this, &ContactModelPimpl::slotRegisteredNameFound);
connect(&callbacksHandler, &CallbacksHandler::registeredNameNotFound,
this, &ContactModelPimpl::slotRegisteredNameNotFound);
connect(&*linked.owner.callModel, &NewCallModel::newIncomingCall,
this, &ContactModelPimpl::slotIncomingCall);
connect(&callbacksHandler, &lrc::CallbacksHandler::newAccountMessage,
......@@ -437,8 +429,6 @@ ContactModelPimpl::~ContactModelPimpl()
this, &ContactModelPimpl::slotIncomingContactRequest);
disconnect(&callbacksHandler, &CallbacksHandler::registeredNameFound,
this, &ContactModelPimpl::slotRegisteredNameFound);
disconnect(&callbacksHandler, &CallbacksHandler::registeredNameNotFound,
this, &ContactModelPimpl::slotRegisteredNameNotFound);
disconnect(&*linked.owner.callModel, &NewCallModel::newIncomingCall,
this, &ContactModelPimpl::slotIncomingCall);
disconnect(&callbacksHandler, &lrc::CallbacksHandler::newAccountMessage,
......@@ -668,48 +658,43 @@ ContactModelPimpl::addToContacts(ContactMethod* cm, const profile::Type& type, b
void
ContactModelPimpl::slotRegisteredNameFound(const std::string& accountId,
int status,
const std::string& uri,
const std::string& registeredName)
{
if (accountId != linked.owner.id) return;
auto& temporaryContact = contacts[""];
{
std::lock_guard<std::mutex> lk(contactsMtx_);
if (contacts.find(uri) == contacts.end()) {
// contact not present, update the temporaryContact
lrc::api::profile::Info profileInfo = {uri, "", "", profile::Type::TEMPORARY};
temporaryContact = {profileInfo, registeredName, false, false};
} else {
// Update contact
contacts[uri].registeredName = registeredName;
if (temporaryContact.registeredName == uri || temporaryContact.registeredName == registeredName) {
// contact already present, remove the temporaryContact
lrc::api::profile::Info profileInfo = {"", "", "", profile::Type::TEMPORARY};
temporaryContact = {profileInfo, "", false, false};
if (status == 0 /* SUCCESS */) {
{
std::lock_guard<std::mutex> lk(contactsMtx_);
if (contacts.find(uri) == contacts.end()) {
// contact not present, update the temporaryContact
lrc::api::profile::Info profileInfo = {uri, "", "", profile::Type::TEMPORARY};
temporaryContact = {profileInfo, registeredName, false, false};
} else {
// Update contact
contacts[uri].registeredName = registeredName;
if (temporaryContact.registeredName == uri || temporaryContact.registeredName == registeredName) {
// contact already present, remove the temporaryContact
lrc::api::profile::Info profileInfo = {"", "", "", profile::Type::TEMPORARY};
temporaryContact = {profileInfo, "", false, false};
}
}
}
emit linked.modelUpdated(uri);
} else if (!uri.empty() || !registeredName.empty()) {
if (temporaryContact.registeredName != uri && temporaryContact.registeredName != registeredName) {
return;
}
{
std::lock_guard<std::mutex> lk(contactsMtx_);
temporaryContact.profileInfo.alias = "Not found";
}
emit linked.modelUpdated(uri);
} else {
qDebug() << "ContactModelPimpl::slotRegisteredNameFound, status = " << status << " with empty uri and registeredName";
}
emit linked.modelUpdated(uri);
}
void
ContactModelPimpl::slotRegisteredNameNotFound(const std::string& accountId,
const std::string& uri,
const std::string& name)
{
if (accountId != linked.owner.id) return;
auto& temporaryContact = contacts[""];
if (temporaryContact.registeredName != uri && temporaryContact.registeredName != name) {
return;
}
{
std::lock_guard<std::mutex> lk(contactsMtx_);
temporaryContact.profileInfo.alias = "Not found";
}
emit linked.modelUpdated(uri);
}
void
......
......@@ -104,6 +104,23 @@ public Q_SLOTS:
void slotAccountRemoved(Account* account);
void slotProfileUpdated(const Profile* profile);
/**
* Emit nameRegistrationEnded
* @param accountId
* @param status
* @param name
*/
void slotNameRegistrationEnded(const std::string& accountId, int status, const std::string& name);
/**
* Emit registeredNameFound
* @param accountId
* @param status
* @param address
* @param name
*/
void slotRegisteredNameFound(const std::string& accountId, int status, const std::string& address, const std::string& name);
};
NewAccountModel::NewAccountModel(Lrc& lrc,
......@@ -191,6 +208,12 @@ NewAccountModel::setAvatar(const std::string& accountId, const std::string& avat
}
}
bool
NewAccountModel::registerName(const std::string& accountId, const std::string& password, const std::string& username)
{
return ConfigurationManager::instance().registerName(accountId.c_str(), password.c_str(), username.c_str());
}
bool
NewAccountModel::exportToFile(const std::string& accountId, const std::string& path) const
{
......@@ -261,6 +284,8 @@ NewAccountModelPimpl::NewAccountModelPimpl(NewAccountModel& linked,
connect(&callbacksHandler, &CallbacksHandler::accountStatusChanged, this, &NewAccountModelPimpl::slotAccountStatusChanged);
connect(&callbacksHandler, &CallbacksHandler::accountDetailsChanged, this, &NewAccountModelPimpl::slotAccountDetailsChanged);
connect(&callbacksHandler, &CallbacksHandler::exportOnRingEnded, this, &NewAccountModelPimpl::slotExportOnRingEnded);
connect(&callbacksHandler, &CallbacksHandler::nameRegistrationEnded, this, &NewAccountModelPimpl::slotNameRegistrationEnded);
connect(&callbacksHandler, &CallbacksHandler::registeredNameFound, this, &NewAccountModelPimpl::slotRegisteredNameFound);
// NOTE: because we still use the legacy LRC for configuration, we are still using old signals
connect(&AccountModel::instance(), &AccountModel::accountRemoved, this, &NewAccountModelPimpl::slotAccountRemoved);
......@@ -328,6 +353,57 @@ NewAccountModelPimpl::slotExportOnRingEnded(const std::string& accountID, int st
emit linked.exportOnRingEnded(accountID, convertedStatus, pin);
}
void
NewAccountModelPimpl::slotNameRegistrationEnded(const std::string& accountId, int status, const std::string& name)
{
account::RegisterNameStatus convertedStatus = account::RegisterNameStatus::INVALID;
switch (status)
{
case 0:
convertedStatus = account::RegisterNameStatus::SUCCESS;
break;
case 1:
convertedStatus = account::RegisterNameStatus::WRONG_PASSWORD;
break;
case 2:
convertedStatus = account::RegisterNameStatus::INVALID_NAME;
break;
case 3:
convertedStatus = account::RegisterNameStatus::ALREADY_TAKEN;
break;
case 4:
convertedStatus = account::RegisterNameStatus::NETWORK_ERROR;
break;
default:
break;
}
emit linked.nameRegistrationEnded(accountId, convertedStatus, name);
}
void
NewAccountModelPimpl::slotRegisteredNameFound(const std::string& accountId, int status, const std::string& address, const std::string& name)
{
account::LookupStatus convertedStatus = account::LookupStatus::INVALID;
switch (status)
{
case 0:
convertedStatus = account::LookupStatus::SUCCESS;
break;
case 1:
convertedStatus = account::LookupStatus::INVALID_NAME;
break;
case 2:
convertedStatus = account::LookupStatus::NOT_FOUND;
break;
case 3:
convertedStatus = account::LookupStatus::ERROR;
break;
default:
break;
}
emit linked.registeredNameFound(accountId, convertedStatus, address, name);
}
void
NewAccountModelPimpl::addToAccounts(const std::string& accountId)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment