Skip to content

Commit

Permalink
Merge pull request #128 from onerain88/fix-user-save
Browse files Browse the repository at this point in the history
Fix user save
  • Loading branch information
onerain88 authored May 7, 2021
2 parents 2078faa + c28f662 commit f833cd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Common/Common/Persistence/PersistenceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task WriteText(string filename, string text) {
}

string path = GetFileFullPath(filename);
using (FileStream fs = IOFile.OpenWrite(path)) {
using (FileStream fs = IOFile.Create(path)) {
byte[] buffer = Encoding.UTF8.GetBytes(text);
await fs.WriteAsync(buffer, 0, buffer.Length);
}
Expand Down
4 changes: 2 additions & 2 deletions Storage/Storage/Public/LCObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ void ApplyOperation(string key, ILCOperation op) {
public void Merge(LCObjectData objectData) {
data.ClassName = objectData.ClassName ?? data.ClassName;
data.ObjectId = objectData.ObjectId ?? data.ObjectId;
data.CreatedAt = objectData.CreatedAt != null ? objectData.CreatedAt : data.CreatedAt;
data.UpdatedAt = objectData.UpdatedAt != null ? objectData.UpdatedAt : data.UpdatedAt;
data.CreatedAt = !objectData.CreatedAt.Equals(default) ? objectData.CreatedAt : data.CreatedAt;
data.UpdatedAt = !objectData.UpdatedAt.Equals(default) ? objectData.UpdatedAt : data.UpdatedAt;
// 先将本地的预估数据直接替换
data.CustomPropertyDict = estimatedData;
// 再将服务端的数据覆盖
Expand Down
14 changes: 9 additions & 5 deletions Storage/Storage/Public/LCUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ public async Task<LCUser> SignUp() {
throw new ArgumentException("Cannot sign up a user that already exists.");
}
await Save();
currentUser = this;

await SaveToLocal();

return this;
}
Expand Down Expand Up @@ -555,7 +552,7 @@ async Task LinkWithAuthData(string authType, Dictionary<string, object> data) {
{ authType, data }
};
try {
await Save();
await base.Save();
oriAuthData[authType] = data;
await UpdateAuthData(oriAuthData);
} catch (Exception e) {
Expand All @@ -570,7 +567,7 @@ async Task UnlinkWithAuthData(string authType) {
{ authType, null }
};
try {
await Save();
await base.Save();
oriAuthData.Remove(authType);
await UpdateAuthData(oriAuthData);
} catch (Exception e) {
Expand Down Expand Up @@ -765,5 +762,12 @@ public async Task<LCFollowersAndFollowees> GetFollowersAndFollowees(bool include
}
return result;
}

public new async Task<LCUser> Save(bool fetchWhenSave = false, LCQuery<LCObject> query = null) {
await base.Save(fetchWhenSave, query);
currentUser = this;
await SaveToLocal();
return this;
}
}
}

0 comments on commit f833cd6

Please sign in to comment.