Merge pull request #95 from onerain88/chore2

Chore2
oneRain 2021-01-12 15:03:04 +08:00 committed by GitHub
commit 2add0af58d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 50 additions and 13 deletions

View File

@ -32,5 +32,9 @@ namespace LeanCloud.Realtime {
public override Task Read() {
return Task.CompletedTask;
}
public override Task FetchReciptTimestamps() {
return Task.CompletedTask;
}
}
}

View File

@ -467,7 +467,7 @@ namespace LeanCloud.Realtime {
/// Fetches receipt timestamp.
/// </summary>
/// <returns></returns>
public async Task FetchReciptTimestamps() {
public virtual async Task FetchReciptTimestamps() {
await Client.ConversationController.FetchReciptTimestamp(Id);
}

View File

@ -17,5 +17,9 @@ namespace LeanCloud.Realtime {
public async Task<bool> CheckSubscription() {
return await Client.ConversationController.CheckSubscription(Id);
}
public override Task FetchReciptTimestamps() {
return Task.CompletedTask;
}
}
}

View File

@ -120,8 +120,8 @@ namespace LeanCloud.Realtime {
/// <summary>
/// Indicates whether this message is transient.
/// </summary>
public bool IsTransient {
get; internal set;
internal bool IsTransient {
get; set;
}
internal LCIMMessage() {

View File

@ -346,12 +346,13 @@ namespace LeanCloud.Storage {
return (int)ret["count"];
}
public Task<T> Get(string objectId) {
public async Task<T> Get(string objectId) {
if (string.IsNullOrEmpty(objectId)) {
throw new ArgumentNullException(nameof(objectId));
}
WhereEqualTo("objectId", objectId);
return First();
string path = $"classes/{ClassName}/{objectId}";
Dictionary<string, object> response = await LCApplication.HttpClient.Get<Dictionary<string, object>>(path);
return DecodeLCObject(response);
}
public async Task<ReadOnlyCollection<T>> Find() {
@ -361,9 +362,7 @@ namespace LeanCloud.Storage {
List<object> results = response["results"] as List<object>;
List<T> list = new List<T>();
foreach (object item in results) {
LCObjectData objectData = LCObjectData.Decode(item as Dictionary<string, object>);
T obj = LCObject.Create(ClassName) as T;
obj.Merge(objectData);
T obj = DecodeLCObject(item as Dictionary<string, object>);
list.Add(obj);
}
return list.AsReadOnly();
@ -412,5 +411,12 @@ namespace LeanCloud.Storage {
compositionQuery.ClassName = className;
return compositionQuery;
}
private T DecodeLCObject(Dictionary<string, object> data) {
LCObjectData objectData = LCObjectData.Decode(data);
T obj = LCObject.Create(ClassName) as T;
obj.Merge(objectData);
return obj;
}
}
}

View File

@ -326,7 +326,7 @@ namespace LeanCloud.Storage {
if (string.IsNullOrEmpty(platform)) {
throw new ArgumentNullException(nameof(platform));
}
return LinkWithAuthData(platform, null);
return UnlinkWithAuthData(platform);
}
/// <summary>
@ -523,11 +523,34 @@ namespace LeanCloud.Storage {
return new LCQuery<LCUser>(CLASS_NAME);
}
Task LinkWithAuthData(string authType, Dictionary<string, object> data) {
async Task LinkWithAuthData(string authType, Dictionary<string, object> data) {
Dictionary<string, object> oriAuthData = new Dictionary<string, object>(AuthData);
AuthData = new Dictionary<string, object> {
{ authType, data }
};
return Save();
try {
await Save();
oriAuthData.Add(authType, data);
AuthData = oriAuthData;
} catch (Exception e) {
AuthData = oriAuthData;
throw e;
}
}
async Task UnlinkWithAuthData(string authType) {
Dictionary<string, object> oriAuthData = new Dictionary<string, object>(AuthData);
AuthData = new Dictionary<string, object> {
{ authType, null }
};
try {
await Save();
oriAuthData.Remove(authType);
AuthData = oriAuthData;
} catch (Exception e) {
AuthData = oriAuthData;
throw e;
}
}
static async Task<LCUser> Login(Dictionary<string, object> data) {

View File

@ -97,7 +97,7 @@ namespace LeanCloud.Storage {
public static async Task<ReadOnlyCollection<LCStatistic>> UpdateStatistics(LCUser user,
Dictionary<string, double> statistics,
bool overwrite = true) {
bool overwrite = false) {
if (user == null) {
throw new ArgumentNullException(nameof(user));
}