mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-10-01 02:39:39 +02:00
sync: ensure monographs sync for first time ever on an existing device (#44)
This commit is contained in:
1 parent
34a09ad15d
commit
6e8fb81ade
2 files changed
+14
-1
No files matched your search
@@ -263,14 +263,17 @@ namespace Notesnook.API.Hubs
|
|||||||
|
|
||||||
if (includeMonographs)
|
if (includeMonographs)
|
||||||
{
|
{
|
||||||
|
var isSyncingMonographsForFirstTime = !device.HasInitialMonographsSync;
|
||||||
var unsyncedMonographs = ids.Where((id) => id.EndsWith(":monograph")).ToHashSet();
|
var unsyncedMonographs = ids.Where((id) => id.EndsWith(":monograph")).ToHashSet();
|
||||||
var unsyncedMonographIds = unsyncedMonographs.Select((id) => id.Split(":")[0]).ToArray();
|
var unsyncedMonographIds = unsyncedMonographs.Select((id) => id.Split(":")[0]).ToArray();
|
||||||
var userMonographs = isResetSync
|
var userMonographs = isResetSync || isSyncingMonographsForFirstTime
|
||||||
? await Repositories.Monographs.FindAsync(m => m.UserId == userId)
|
? await Repositories.Monographs.FindAsync(m => m.UserId == userId)
|
||||||
: await Repositories.Monographs.FindAsync(m => m.UserId == userId && unsyncedMonographIds.Contains(m.ItemId));
|
: await Repositories.Monographs.FindAsync(m => m.UserId == userId && unsyncedMonographIds.Contains(m.ItemId));
|
||||||
|
|
||||||
if (userMonographs.Any() && !await Clients.Caller.SendMonographs(userMonographs).WaitAsync(TimeSpan.FromMinutes(10)))
|
if (userMonographs.Any() && !await Clients.Caller.SendMonographs(userMonographs).WaitAsync(TimeSpan.FromMinutes(10)))
|
||||||
throw new HubException("Client rejected monographs.");
|
throw new HubException("Client rejected monographs.");
|
||||||
|
|
||||||
|
device.HasInitialMonographsSync = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceService.Reset();
|
deviceService.Reset();
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ namespace Notesnook.API.Services
|
|||||||
set => SetMetadata("LastAccessTime", value.ToString());
|
set => SetMetadata("LastAccessTime", value.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates if the monographs have been synced for the first time
|
||||||
|
/// ever on a device.
|
||||||
|
/// </summary>
|
||||||
|
public readonly bool HasInitialMonographsSync
|
||||||
|
{
|
||||||
|
get => !string.IsNullOrEmpty(GetMetadata("HasInitialMonographsSync"));
|
||||||
|
set => SetMetadata("HasInitialMonographsSync", value.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
private static string CreateFilePath(string userId, string? deviceId = null, string? metadataKey = null)
|
private static string CreateFilePath(string userId, string? deviceId = null, string? metadataKey = null)
|
||||||
{
|
{
|
||||||
return Path.Join("sync", userId, deviceId, metadataKey);
|
return Path.Join("sync", userId, deviceId, metadataKey);
|
||||||
|
|||||||
Reference in new issue
Block a user