cascade null to sites on folder delete

This commit is contained in:
Kyle Spearrin 2016-07-31 00:19:12 -04:00
parent cf8ee2273a
commit d0fa6841c3
5 changed files with 23 additions and 4 deletions

View File

@ -8,5 +8,6 @@ namespace Bit.App.Abstractions
public interface IFolderRepository : IRepository<FolderData, string>
{
Task<IEnumerable<FolderData>> GetAllByUserIdAsync(string userId);
Task DeleteWithSiteUpdateAsync(string id, DateTime revisionDate);
}
}

View File

@ -7,7 +7,7 @@ namespace Bit.App.Abstractions
{
bool SyncInProgress { get; }
Task<bool> SyncAsync(string id);
Task<bool> SyncDeleteFolderAsync(string id);
Task<bool> SyncDeleteFolderAsync(string id, DateTime revisionDate);
Task<bool> SyncDeleteSiteAsync(string id);
Task<bool> FullSyncAsync();
Task<bool> IncrementalSyncAsync(TimeSpan syncThreshold);

View File

@ -18,5 +18,23 @@ namespace Bit.App.Repositories
var folders = Connection.Table<FolderData>().Where(f => f.UserId == userId).Cast<FolderData>();
return Task.FromResult(folders);
}
public override Task DeleteAsync(string id)
{
var now = DateTime.UtcNow;
DeleteWithSiteUpdateAsync(id, now);
return Task.FromResult(0);
}
public Task DeleteWithSiteUpdateAsync(string id, DateTime revisionDate)
{
Connection.RunInTransaction(() =>
{
Connection.Execute("UPDATE Site SET FolderId = ?, RevisionDateTime = ? WHERE FolderId = ?", null, revisionDate, id);
Connection.Delete<FolderData>(id);
});
return Task.FromResult(0);
}
}
}

View File

@ -59,7 +59,7 @@ namespace Bit.App.Services
break;
case Enums.PushType.SyncFolderDelete:
var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>();
_syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id);
_syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id, folderDeleteMessage.RevisionDate);
break;
case Enums.PushType.SyncSiteDelete:
var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>();

View File

@ -98,7 +98,7 @@ namespace Bit.App.Services
return true;
}
public async Task<bool> SyncDeleteFolderAsync(string id)
public async Task<bool> SyncDeleteFolderAsync(string id, DateTime revisionDate)
{
if(!_authService.IsAuthenticated)
{
@ -107,7 +107,7 @@ namespace Bit.App.Services
SyncStarted();
await _folderRepository.DeleteAsync(id);
await _folderRepository.DeleteWithSiteUpdateAsync(id, revisionDate);
SyncCompleted(true);
return true;
}