From aec2a9409b7f23ae203ad9befb4b4ac34efb9c1c Mon Sep 17 00:00:00 2001 From: oneRain Date: Tue, 5 Jan 2021 17:10:49 +0800 Subject: [PATCH 1/5] chore: UpdateStatistics overwrite defaults to false. --- Storage/Storage/Leaderboard/LCLeaderboard.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Storage/Storage/Leaderboard/LCLeaderboard.cs b/Storage/Storage/Leaderboard/LCLeaderboard.cs index 8062563..29b39b7 100644 --- a/Storage/Storage/Leaderboard/LCLeaderboard.cs +++ b/Storage/Storage/Leaderboard/LCLeaderboard.cs @@ -97,7 +97,7 @@ namespace LeanCloud.Storage { public static async Task> UpdateStatistics(LCUser user, Dictionary statistics, - bool overwrite = true) { + bool overwrite = false) { if (user == null) { throw new ArgumentNullException(nameof(user)); } From 965ca7ab85242884d7057401ac376a14fc7f7c9a Mon Sep 17 00:00:00 2001 From: oneRain Date: Tue, 5 Jan 2021 17:10:59 +0800 Subject: [PATCH 2/5] chore: LCIMMessage.IsTransient --- Realtime/Realtime/Message/LCIMMessage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Realtime/Realtime/Message/LCIMMessage.cs b/Realtime/Realtime/Message/LCIMMessage.cs index 4652845..85bdf01 100644 --- a/Realtime/Realtime/Message/LCIMMessage.cs +++ b/Realtime/Realtime/Message/LCIMMessage.cs @@ -120,8 +120,8 @@ namespace LeanCloud.Realtime { /// /// Indicates whether this message is transient. /// - public bool IsTransient { - get; internal set; + internal bool IsTransient { + get; set; } internal LCIMMessage() { From 58245c18da6b45080e5751a036be3d65348fc0a0 Mon Sep 17 00:00:00 2001 From: oneRain Date: Tue, 5 Jan 2021 17:12:43 +0800 Subject: [PATCH 3/5] chore: ignore chatroom and service conversation to fetch recipt timestamps. --- Realtime/Realtime/Conversation/LCIMChatRoom.cs | 4 ++++ Realtime/Realtime/Conversation/LCIMConversation.cs | 2 +- Realtime/Realtime/Conversation/LCIMServiceConversation.cs | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Realtime/Realtime/Conversation/LCIMChatRoom.cs b/Realtime/Realtime/Conversation/LCIMChatRoom.cs index 5b77f92..0ecccf1 100644 --- a/Realtime/Realtime/Conversation/LCIMChatRoom.cs +++ b/Realtime/Realtime/Conversation/LCIMChatRoom.cs @@ -32,5 +32,9 @@ namespace LeanCloud.Realtime { public override Task Read() { return Task.CompletedTask; } + + public override Task FetchReciptTimestamps() { + return Task.CompletedTask; + } } } diff --git a/Realtime/Realtime/Conversation/LCIMConversation.cs b/Realtime/Realtime/Conversation/LCIMConversation.cs index c2553d5..f74ace8 100644 --- a/Realtime/Realtime/Conversation/LCIMConversation.cs +++ b/Realtime/Realtime/Conversation/LCIMConversation.cs @@ -467,7 +467,7 @@ namespace LeanCloud.Realtime { /// Fetches receipt timestamp. /// /// - public async Task FetchReciptTimestamps() { + public virtual async Task FetchReciptTimestamps() { await Client.ConversationController.FetchReciptTimestamp(Id); } diff --git a/Realtime/Realtime/Conversation/LCIMServiceConversation.cs b/Realtime/Realtime/Conversation/LCIMServiceConversation.cs index b2159a6..d55a16f 100644 --- a/Realtime/Realtime/Conversation/LCIMServiceConversation.cs +++ b/Realtime/Realtime/Conversation/LCIMServiceConversation.cs @@ -17,5 +17,9 @@ namespace LeanCloud.Realtime { public async Task CheckSubscription() { return await Client.ConversationController.CheckSubscription(Id); } + + public override Task FetchReciptTimestamps() { + return Task.CompletedTask; + } } } From 346dcb3ba6c758b757d2e33c6b9cfd235c7b5465 Mon Sep 17 00:00:00 2001 From: oneRain Date: Thu, 7 Jan 2021 15:53:51 +0800 Subject: [PATCH 4/5] chore: LCQuery#Get(string objectId) --- Storage/Storage/LCQuery.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Storage/Storage/LCQuery.cs b/Storage/Storage/LCQuery.cs index 928bc1e..c9396f7 100644 --- a/Storage/Storage/LCQuery.cs +++ b/Storage/Storage/LCQuery.cs @@ -346,12 +346,13 @@ namespace LeanCloud.Storage { return (int)ret["count"]; } - public Task Get(string objectId) { + public async Task Get(string objectId) { if (string.IsNullOrEmpty(objectId)) { throw new ArgumentNullException(nameof(objectId)); } - WhereEqualTo("objectId", objectId); - return First(); + string path = $"classes/{ClassName}/{objectId}"; + Dictionary response = await LCApplication.HttpClient.Get>(path); + return DecodeLCObject(response); } public async Task> Find() { @@ -361,9 +362,7 @@ namespace LeanCloud.Storage { List results = response["results"] as List; List list = new List(); foreach (object item in results) { - LCObjectData objectData = LCObjectData.Decode(item as Dictionary); - T obj = LCObject.Create(ClassName) as T; - obj.Merge(objectData); + T obj = DecodeLCObject(item as Dictionary); list.Add(obj); } return list.AsReadOnly(); @@ -412,5 +411,12 @@ namespace LeanCloud.Storage { compositionQuery.ClassName = className; return compositionQuery; } + + private T DecodeLCObject(Dictionary data) { + LCObjectData objectData = LCObjectData.Decode(data); + T obj = LCObject.Create(ClassName) as T; + obj.Merge(objectData); + return obj; + } } } From 4a1937c3123638d27aea724e6d8f84c6e14ff232 Mon Sep 17 00:00:00 2001 From: oneRain Date: Tue, 12 Jan 2021 14:51:12 +0800 Subject: [PATCH 5/5] fix: roll back when auth failed. --- Storage/Storage/LCUser.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Storage/Storage/LCUser.cs b/Storage/Storage/LCUser.cs index af1aa03..70e8f28 100644 --- a/Storage/Storage/LCUser.cs +++ b/Storage/Storage/LCUser.cs @@ -326,7 +326,7 @@ namespace LeanCloud.Storage { if (string.IsNullOrEmpty(platform)) { throw new ArgumentNullException(nameof(platform)); } - return LinkWithAuthData(platform, null); + return UnlinkWithAuthData(platform); } /// @@ -523,11 +523,34 @@ namespace LeanCloud.Storage { return new LCQuery(CLASS_NAME); } - Task LinkWithAuthData(string authType, Dictionary data) { + async Task LinkWithAuthData(string authType, Dictionary data) { + Dictionary oriAuthData = new Dictionary(AuthData); AuthData = new Dictionary { { 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 oriAuthData = new Dictionary(AuthData); + AuthData = new Dictionary { + { authType, null } + }; + try { + await Save(); + oriAuthData.Remove(authType); + AuthData = oriAuthData; + } catch (Exception e) { + AuthData = oriAuthData; + throw e; + } } static async Task Login(Dictionary data) {