Skip to content

Commit

Permalink
Merge pull request #95 from onerain88/chore2
Browse files Browse the repository at this point in the history
Chore2
  • Loading branch information
onerain88 authored Jan 12, 2021
2 parents d263de1 + 4a1937c commit 2add0af
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Realtime/Realtime/Conversation/LCIMChatRoom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ public override Task<LCIMPartiallySuccessResult> AddMembers(IEnumerable<string>
public override Task Read() {
return Task.CompletedTask;
}

public override Task FetchReciptTimestamps() {
return Task.CompletedTask;
}
}
}
2 changes: 1 addition & 1 deletion Realtime/Realtime/Conversation/LCIMConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public async Task<ReadOnlyCollection<LCIMMessage>> QueryMessages(LCIMMessageQuer
/// Fetches receipt timestamp.
/// </summary>
/// <returns></returns>
public async Task FetchReciptTimestamps() {
public virtual async Task FetchReciptTimestamps() {
await Client.ConversationController.FetchReciptTimestamp(Id);
}

Expand Down
4 changes: 4 additions & 0 deletions Realtime/Realtime/Conversation/LCIMServiceConversation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ public async Task Unsubscribe() {
public async Task<bool> CheckSubscription() {
return await Client.ConversationController.CheckSubscription(Id);
}

public override Task FetchReciptTimestamps() {
return Task.CompletedTask;
}
}
}
4 changes: 2 additions & 2 deletions Realtime/Realtime/Message/LCIMMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public bool Mentioned {
/// <summary>
/// Indicates whether this message is transient.
/// </summary>
public bool IsTransient {
get; internal set;
internal bool IsTransient {
get; set;
}

internal LCIMMessage() {
Expand Down
18 changes: 12 additions & 6 deletions Storage/Storage/LCQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,13 @@ public async Task<int> Count() {
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() {
Expand All @@ -361,9 +362,7 @@ public async Task<ReadOnlyCollection<T>> Find() {
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();
Expand Down Expand Up @@ -412,5 +411,12 @@ public static LCQuery<T> Or(IEnumerable<LCQuery<T>> queries) {
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;
}
}
}
29 changes: 26 additions & 3 deletions Storage/Storage/LCUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public Task DisassociateWithAuthData(string platform) {
if (string.IsNullOrEmpty(platform)) {
throw new ArgumentNullException(nameof(platform));
}
return LinkWithAuthData(platform, null);
return UnlinkWithAuthData(platform);
}

/// <summary>
Expand Down Expand Up @@ -523,11 +523,34 @@ public static LCQuery<LCUser> GetQuery() {
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) {
Expand Down
2 changes: 1 addition & 1 deletion Storage/Storage/Leaderboard/LCLeaderboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static Task<LCLeaderboard> GetLeaderboard(string statisticName) {

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));
}
Expand Down

0 comments on commit 2add0af

Please sign in to comment.