mirror of
https://github.com/bitwarden/mobile
synced 2025-12-28 14:13:25 +00:00
remove incremental syncs and move to full syncs with revision checks
This commit is contained in:
@@ -10,6 +10,8 @@ namespace Bit.App.Repositories
|
||||
{
|
||||
public class AccountsApiRepository : BaseApiRepository, IAccountsApiRepository
|
||||
{
|
||||
private static readonly DateTime _epoc = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public AccountsApiRepository(
|
||||
IConnectivity connectivity,
|
||||
IHttpService httpService,
|
||||
@@ -82,5 +84,54 @@ namespace Bit.App.Repositories
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResult<DateTime?>> GetAccountRevisionDate()
|
||||
{
|
||||
if(!Connectivity.IsConnected)
|
||||
{
|
||||
return HandledNotConnected<DateTime?>();
|
||||
}
|
||||
|
||||
var tokenStateResponse = await HandleTokenStateAsync<DateTime?>();
|
||||
if(!tokenStateResponse.Succeeded)
|
||||
{
|
||||
return tokenStateResponse;
|
||||
}
|
||||
|
||||
using(var client = HttpService.Client)
|
||||
{
|
||||
var requestMessage = new TokenHttpRequestMessage()
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/revision-date")),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var response = await client.SendAsync(requestMessage).ConfigureAwait(false);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<DateTime?>(response).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
if(responseContent.Contains("null"))
|
||||
{
|
||||
return ApiResult<DateTime?>.Success(null, response.StatusCode);
|
||||
}
|
||||
|
||||
long ms;
|
||||
if(!long.TryParse(responseContent, out ms))
|
||||
{
|
||||
return await HandleErrorAsync<DateTime?>(response).ConfigureAwait(false);
|
||||
}
|
||||
return ApiResult<DateTime?>.Success(_epoc.AddMilliseconds(ms), response.StatusCode);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return HandledWebException<DateTime?>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace Bit.App.Repositories
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/token")),
|
||||
RequestUri = new Uri(client.BaseAddress, "connect/token"),
|
||||
Content = new FormUrlEncodedContent(new TokenRequest
|
||||
{
|
||||
Email = "abcdefgh",
|
||||
@@ -97,7 +97,7 @@ namespace Bit.App.Repositories
|
||||
var requestMessage = new HttpRequestMessage
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/token")),
|
||||
RequestUri = new Uri(client.BaseAddress, "connect/token"),
|
||||
Content = new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
{
|
||||
{ "grant_type", "refresh_token" },
|
||||
@@ -119,7 +119,7 @@ namespace Bit.App.Repositories
|
||||
TokenService.Token = tokenResponse.AccessToken;
|
||||
TokenService.RefreshToken = tokenResponse.RefreshToken;
|
||||
}
|
||||
catch
|
||||
catch(Exception ee)
|
||||
{
|
||||
return webException.Invoke();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user