public async Task CollectAsync(EventType eventType, string cipherId = null, bool uploadImmediately = false) { return; // TODO var authed = await _userService.IsAuthenticatedAsync(); if (!authed) { return; } var organizations = await _userService.GetAllOrganizationAsync(); if (organizations == null) { return; } var orgIds = new HashSet <string>(organizations.Where(o => o.UseEvents).Select(o => o.Id)); if (!orgIds.Any()) { return; } if (cipherId != null) { var cipher = await _cipherService.GetAsync(cipherId); if (cipher?.OrganizationId == null || !orgIds.Contains(cipher.OrganizationId)) { return; } } var eventCollection = await _storageService.GetAsync <List <EventData> >(Constants.EventCollectionKey); if (eventCollection == null) { eventCollection = new List <EventData>(); } eventCollection.Add(new EventData { Type = eventType, CipherId = cipherId, Date = DateTime.UtcNow }); await _storageService.SaveAsync(Constants.EventCollectionKey, eventCollection); if (uploadImmediately) { await UploadEventsAsync(); } }
public async Task <bool> SyncUpsertCipherAsync(SyncCipherNotification notification, bool isEdit) { SyncStarted(); if (await _stateService.IsAuthenticatedAsync()) { try { var shouldUpdate = true; var localCipher = await _cipherService.GetAsync(notification.Id); if (localCipher != null && localCipher.RevisionDate >= notification.RevisionDate) { shouldUpdate = false; } var checkCollections = false; if (shouldUpdate) { if (isEdit) { shouldUpdate = localCipher != null; checkCollections = true; } else { if (notification.CollectionIds == null || notification.OrganizationId == null) { shouldUpdate = localCipher == null; } else { shouldUpdate = false; checkCollections = true; } } } if (!shouldUpdate && checkCollections && notification.OrganizationId != null && notification.CollectionIds != null && notification.CollectionIds.Any()) { var collections = await _collectionService.GetAllAsync(); if (collections != null) { foreach (var c in collections) { if (notification.CollectionIds.Contains(c.Id)) { shouldUpdate = true; break; } } } } if (shouldUpdate) { var remoteCipher = await _apiService.GetCipherAsync(notification.Id); if (remoteCipher != null) { var userId = await _stateService.GetActiveUserIdAsync(); await _cipherService.UpsertAsync(new CipherData(remoteCipher, userId)); _messagingService.Send("syncedUpsertedCipher", new Dictionary <string, string> { ["cipherId"] = notification.Id }); return(SyncCompleted(true)); } } } catch (ApiException e) { if (e.Error != null && e.Error.StatusCode == System.Net.HttpStatusCode.NotFound && isEdit) { await _cipherService.DeleteAsync(notification.Id); _messagingService.Send("syncedDeletedCipher", new Dictionary <string, string> { ["cipherId"] = notification.Id }); return(SyncCompleted(true)); } } } return(SyncCompleted(false)); }