monograph: add sync support (#39)

* monograph: add sync support

* monograph: fix password field && improve syncing logic && fix delete endpoint

* sync: get rid of unnecessary .ToList & ToListAsync

* sync: AddIdsToAllDevices is no longer asynchronous

* monograph: simplify and fix several bugs

- we were sending the triggerSync event to all users instead of all devices
- asynchronous methods did not have the `Async` suffix
- we weren't properly replacing the deleted monograph

* monograph: fix minor issues
* fix publishing
* don't return deleted monograph in monographs/:id endpoint
* persist UserId when soft deleting monograph

* monograph: check soft delete status in several endpoints

---------

Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
01zulfi
2025-08-04 11:51:15 +05:00
committed by GitHub
parent 1e2ef0685d
commit bf2e6efeff
4 changed files with 151 additions and 20 deletions

View File

@@ -194,6 +194,21 @@ namespace Notesnook.API.Services
}
}
public void AddIdsToAllDevices(List<string> ids)
{
foreach (var id in ListDevices())
{
if (IsSyncReset(id)) return;
lock (id)
{
if (!IsDeviceRegistered(id)) Directory.CreateDirectory(Path.Join(device.UserSyncDirectoryPath, id));
var oldIds = GetUnsyncedIds(id);
File.WriteAllLinesAsync(Path.Join(device.UserSyncDirectoryPath, id, "unsynced"), ids.Union(oldIds));
}
}
}
public void RegisterDevice()
{
lock (device.UserId)