1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-26 12:16:07 +01:00

Push notification and sync fixes

This commit is contained in:
Kyle Spearrin 2016-06-30 00:36:44 -04:00
parent 8653a76e26
commit 7a48128e43
8 changed files with 26 additions and 20 deletions

View File

@ -1,5 +1,6 @@
using Bit.App.Enums; using Bit.App.Enums;
using System; using System;
using Newtonsoft.Json.Linq;
namespace Bit.App.Models.Api namespace Bit.App.Models.Api
{ {
@ -9,7 +10,7 @@ namespace Bit.App.Models.Api
public string FolderId { get; set; } public string FolderId { get; set; }
public CipherType Type { get; set; } public CipherType Type { get; set; }
public bool Favorite { get; set; } public bool Favorite { get; set; }
public dynamic Data { get; set; } public JObject Data { get; set; }
public DateTime RevisionDate { get; set; } public DateTime RevisionDate { get; set; }
} }
} }

View File

@ -32,11 +32,7 @@ namespace Bit.App.Models.Data
throw new ArgumentException(nameof(cipher.Type)); throw new ArgumentException(nameof(cipher.Type));
} }
var data = cipher.Data as FolderDataModel; var data = cipher.Data.ToObject<SiteDataModel>();
if(data == null)
{
throw new ArgumentException(nameof(cipher.Data));
}
Id = cipher.Id; Id = cipher.Id;
UserId = userId; UserId = userId;

View File

@ -2,6 +2,7 @@
using SQLite; using SQLite;
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Bit.App.Models.Api; using Bit.App.Models.Api;
using Newtonsoft.Json.Linq;
namespace Bit.App.Models.Data namespace Bit.App.Models.Data
{ {
@ -44,11 +45,7 @@ namespace Bit.App.Models.Data
throw new ArgumentException(nameof(cipher.Type)); throw new ArgumentException(nameof(cipher.Type));
} }
var data = cipher.Data as SiteDataModel; var data = cipher.Data.ToObject<SiteDataModel>();
if(data == null)
{
throw new ArgumentException(nameof(cipher.Data));
}
Id = cipher.Id; Id = cipher.Id;
UserId = userId; UserId = userId;

View File

@ -15,7 +15,7 @@ namespace Bit.App.Models.Page
Id = site.Id; Id = site.Id;
FolderId = folderId; FolderId = folderId;
Name = site.Name?.Decrypt(); Name = site.Name?.Decrypt();
Username = site.Username?.Decrypt(); Username = site.Username?.Decrypt() ?? " ";
Password = site.Password?.Decrypt(); Password = site.Password?.Decrypt();
Uri = site.Uri?.Decrypt(); Uri = site.Uri?.Decrypt();
} }

View File

@ -1,4 +1,5 @@
using Bit.App.Enums; using System;
using Bit.App.Enums;
namespace Bit.App.Models namespace Bit.App.Models
{ {
@ -7,13 +8,19 @@ namespace Bit.App.Models
public PushType Type { get; set; } public PushType Type { get; set; }
} }
public class SyncPushNotification : PushNotification public abstract class SyncPushNotification : PushNotification
{ {
public string UserId { get; set; } public string UserId { get; set; }
} }
public class SyncCipherPushNotification : SyncPushNotification public class SyncCipherPushNotification : SyncPushNotification
{ {
public string CipherId { get; set; } public string Id { get; set; }
public DateTime RevisionDate { get; set; }
}
public class SyncCiphersPushNotification : SyncPushNotification
{
public DateTime Date { get; set; }
} }
} }

View File

@ -7,6 +7,7 @@ using Bit.App.Controls;
using Acr.UserDialogs; using Acr.UserDialogs;
using Plugin.Settings.Abstractions; using Plugin.Settings.Abstractions;
using Plugin.Fingerprint.Abstractions; using Plugin.Fingerprint.Abstractions;
using PushNotification.Plugin.Abstractions;
namespace Bit.App.Pages namespace Bit.App.Pages
{ {
@ -16,6 +17,7 @@ namespace Bit.App.Pages
private readonly IUserDialogs _userDialogs; private readonly IUserDialogs _userDialogs;
private readonly ISettings _settings; private readonly ISettings _settings;
private readonly IFingerprint _fingerprint; private readonly IFingerprint _fingerprint;
private readonly IPushNotification _pushNotification;
// TODO: Model binding context? // TODO: Model binding context?
@ -25,6 +27,7 @@ namespace Bit.App.Pages
_userDialogs = Resolver.Resolve<IUserDialogs>(); _userDialogs = Resolver.Resolve<IUserDialogs>();
_settings = Resolver.Resolve<ISettings>(); _settings = Resolver.Resolve<ISettings>();
_fingerprint = Resolver.Resolve<IFingerprint>(); _fingerprint = Resolver.Resolve<IFingerprint>();
_pushNotification = Resolver.Resolve<IPushNotification>();
Init(); Init();
} }
@ -174,6 +177,7 @@ namespace Bit.App.Pages
} }
_authService.LogOut(); _authService.LogOut();
_pushNotification.Unregister();
Application.Current.MainPage = new HomePage(); Application.Current.MainPage = new HomePage();
} }

View File

@ -39,17 +39,18 @@ namespace Bit.App.Services
case Enums.PushType.SyncCipherUpdate: case Enums.PushType.SyncCipherUpdate:
case Enums.PushType.SyncCipherCreate: case Enums.PushType.SyncCipherCreate:
var createUpdateMessage = values.ToObject<SyncCipherPushNotification>(); var createUpdateMessage = values.ToObject<SyncCipherPushNotification>();
_syncService.SyncAsync(createUpdateMessage.CipherId); _syncService.SyncAsync(createUpdateMessage.Id);
break; break;
case Enums.PushType.SyncFolderDelete: case Enums.PushType.SyncFolderDelete:
var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>(); var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>();
_syncService.SyncDeleteFolderAsync(folderDeleteMessage.CipherId); _syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id);
break; break;
case Enums.PushType.SyncSiteDelete: case Enums.PushType.SyncSiteDelete:
var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>(); var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>();
_syncService.SyncDeleteFolderAsync(siteDeleteMessage.CipherId); _syncService.SyncDeleteSiteAsync(siteDeleteMessage.Id);
break; break;
case Enums.PushType.SyncCiphers: case Enums.PushType.SyncCiphers:
var cipherMessage = values.ToObject<SyncCiphersPushNotification>();
_syncService.FullSyncAsync(); _syncService.FullSyncAsync();
break; break;
default: default:

View File

@ -125,7 +125,7 @@ namespace Bit.App.Services
var folderTask = SyncFoldersAsync(ciphers.Result.Data.Where(c => c.Type == Enums.CipherType.Folder), true); var folderTask = SyncFoldersAsync(ciphers.Result.Data.Where(c => c.Type == Enums.CipherType.Folder), true);
await Task.WhenAll(siteTask, folderTask); await Task.WhenAll(siteTask, folderTask);
if(folderTask.Exception == null || siteTask.Exception == null) if(folderTask.Exception != null || siteTask.Exception != null)
{ {
return false; return false;
} }
@ -164,7 +164,7 @@ namespace Bit.App.Services
await Task.WhenAll(siteTask, folderTask); await Task.WhenAll(siteTask, folderTask);
if(folderTask.Exception == null || siteTask.Exception == null) if(folderTask.Exception != null || siteTask.Exception != null)
{ {
return false; return false;
} }