Skip to content

Commit

Permalink
Merge pull request #1087 from deXol/develop
Browse files Browse the repository at this point in the history
[BLE] Fetch notes on user change
  • Loading branch information
limpkin authored Nov 16, 2022
2 parents 177183d + 5c9a9cc commit eccd352
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/MPDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4110,6 +4110,7 @@ void MPDevice::getChangeNumbers()
if (isBLE())
{
bleImpl->fetchDataFiles();
bleImpl->fetchNotes();
}
else
{
Expand Down Expand Up @@ -5034,7 +5035,7 @@ void MPDevice::deleteDataNodesAndLeave(QStringList services, QStringList notes,

/* Generate save packets */
AsyncJobs* saveJobs = new AsyncJobs("Starting save operations...", this);
connect(saveJobs, &AsyncJobs::finished, [this, services, cb](const QByteArray &data)
connect(saveJobs, &AsyncJobs::finished, [this, services, cb, notes](const QByteArray &data)
{
Q_UNUSED(data);
exitMemMgmtMode(true);
Expand All @@ -5048,6 +5049,15 @@ void MPDevice::deleteDataNodesAndLeave(QStringList services, QStringList notes,
removeFileFromCache(services[i]);
}

if (isBLE() && !notes.isEmpty())
{
/* If a note was deleted fetch notes again,
* fetchNotesLater ensures this happens only
* after exitMMM run.
*/
bleImpl->fetchNotesLater();
}

return;
});
connect(saveJobs, &AsyncJobs::failed, [this, cb](AsyncJob *failedJob)
Expand Down Expand Up @@ -6212,6 +6222,10 @@ void MPDevice::startImportFileMerging(const MPDeviceProgressCb &cbProgress, Mess
filesCache.save(list);
filesCache.setDbChangeNumber(importedDataDbChangeNumber);
emit filesCacheChanged();
if (isBLE())
{
emit bleImpl->notesFetched();
}

cleanImportedVars();
exitMemMgmtMode(false);
Expand Down Expand Up @@ -6297,6 +6311,11 @@ void MPDevice::startImportFileMerging(const MPDeviceProgressCb &cbProgress, Mess
filesCache.setDbChangeNumber(importedDataDbChangeNumber);
emit filesCacheChanged();

if (isBLE())
{
emit bleImpl->notesFetched();
}

cleanImportedVars();
exitMemMgmtMode(false);
qInfo() << "Merge operations succeeded!";
Expand Down
7 changes: 6 additions & 1 deletion src/MPDeviceBleImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void MPDeviceBleImpl::deleteFile(QString file, bool isNote, std::function<void (

void MPDeviceBleImpl::fetchNotes()
{
if (mpDev->get_status() != Common::Unlocked)
if (mpDev->get_status() != Common::Unlocked && mpDev->get_status() != Common::MMMMode)
{
if (AppDaemon::isDebugDev())
{
Expand Down Expand Up @@ -338,6 +338,11 @@ void MPDeviceBleImpl::fetchNotes(AsyncJobs *jobs, QByteArray addr)
));
}

void MPDeviceBleImpl::fetchNotesLater()
{
createAndAddCustomJob("Fetch notes", [this](){fetchNotes();});
}

void MPDeviceBleImpl::getNoteNode(QString note, std::function<void (bool, QString, QString, QByteArray)> cb)
{
if (note.isEmpty())
Expand Down
1 change: 1 addition & 0 deletions src/MPDeviceBleImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MPDeviceBleImpl: public QObject

void fetchNotes();
void fetchNotes(AsyncJobs *jobs, QByteArray addr);
void fetchNotesLater();
QList<QString> getNotes() const { return m_notes; }
void getNoteNode(QString note, std::function<void(bool, QString, QString, QByteArray)> cb);

Expand Down

0 comments on commit eccd352

Please sign in to comment.