Delete a device from the list if the job succeed
This commit is contained in:
committed by
Tobias Fella
parent
ace62b4df1
commit
6bef2205db
@@ -70,7 +70,12 @@ void DevicesModel::logout(int index, const QString &password)
|
|||||||
auto job = Controller::instance().activeConnection()->callApi<NeochatDeleteDeviceJob>(m_devices[index].deviceId);
|
auto job = Controller::instance().activeConnection()->callApi<NeochatDeleteDeviceJob>(m_devices[index].deviceId);
|
||||||
|
|
||||||
connect(job, &BaseJob::result, this, [this, job, password, index] {
|
connect(job, &BaseJob::result, this, [this, job, password, index] {
|
||||||
if (job->error() != 0) {
|
auto onSuccess = [this, index]() {
|
||||||
|
beginRemoveRows(QModelIndex(), index, index);
|
||||||
|
m_devices.remove(index);
|
||||||
|
endRemoveRows();
|
||||||
|
};
|
||||||
|
if (job->error() != BaseJob::Success) {
|
||||||
QJsonObject replyData = job->jsonData();
|
QJsonObject replyData = job->jsonData();
|
||||||
QJsonObject authData;
|
QJsonObject authData;
|
||||||
authData["session"] = replyData["session"];
|
authData["session"] = replyData["session"];
|
||||||
@@ -79,11 +84,9 @@ void DevicesModel::logout(int index, const QString &password)
|
|||||||
QJsonObject identifier = {{"type", "m.id.user"}, {"user", Controller::instance().activeConnection()->user()->id()}};
|
QJsonObject identifier = {{"type", "m.id.user"}, {"user", Controller::instance().activeConnection()->user()->id()}};
|
||||||
authData["identifier"] = identifier;
|
authData["identifier"] = identifier;
|
||||||
auto *innerJob = Controller::instance().activeConnection()->callApi<NeochatDeleteDeviceJob>(m_devices[index].deviceId, authData);
|
auto *innerJob = Controller::instance().activeConnection()->callApi<NeochatDeleteDeviceJob>(m_devices[index].deviceId, authData);
|
||||||
connect(innerJob, &BaseJob::success, this, [this, index]() {
|
connect(innerJob, &BaseJob::success, this, onSuccess);
|
||||||
beginRemoveRows(QModelIndex(), index, index);
|
} else {
|
||||||
m_devices.remove(index);
|
onSuccess();
|
||||||
endRemoveRows();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user