Skip to content

Commit 850b84d

Browse files
Made installation fields properly update during save.
Because `SetIfDifferent` checks the `IsKeyMutable` function which we override, we need to have another way of setting these fields on installation save. Fixes #40.
1 parent e7049fc commit 850b84d

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

Parse/ParseInstallation.cs

100644100755
+26-7
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ internal override bool IsKeyMutable(string key) {
220220
internal override Task SaveAsync(Task toAwait, CancellationToken cancellationToken) {
221221
Task platformHookTask = null;
222222
if (CurrentInstallationController.IsCurrent(this)) {
223-
SetIfDifferent("deviceType", ParseClient.PlatformHooks.DeviceType);
224-
SetIfDifferent("timeZone", ParseClient.PlatformHooks.DeviceTimeZone);
225-
SetIfDifferent("localeIdentifier", GetLocaleIdentifier());
226-
SetIfDifferent("parseVersion", GetParseVersion().ToString());
227-
SetIfDifferent("appVersion", ParseClient.PlatformHooks.AppBuildVersion);
228-
SetIfDifferent("appIdentifier", ParseClient.PlatformHooks.AppIdentifier);
229-
SetIfDifferent("appName", ParseClient.PlatformHooks.AppName);
223+
ForceSetIfDifferent("deviceType", ParseClient.PlatformHooks.DeviceType);
224+
ForceSetIfDifferent("timeZone", ParseClient.PlatformHooks.DeviceTimeZone);
225+
ForceSetIfDifferent("localeIdentifier", GetLocaleIdentifier());
226+
ForceSetIfDifferent("parseVersion", GetParseVersion().ToString());
227+
ForceSetIfDifferent("appVersion", ParseClient.PlatformHooks.AppBuildVersion);
228+
ForceSetIfDifferent("appIdentifier", ParseClient.PlatformHooks.AppIdentifier);
229+
ForceSetIfDifferent("appName", ParseClient.PlatformHooks.AppName);
230230

231231
// TODO (hallucinogen): this probably should have been a controller.
232232
platformHookTask = ParseClient.PlatformHooks.ExecuteParseInstallationSaveHookAsync(this);
@@ -241,6 +241,25 @@ internal override Task SaveAsync(Task toAwait, CancellationToken cancellationTok
241241
}
242242
return CurrentInstallationController.SetAsync(this, cancellationToken);
243243
}).Unwrap();
244+
}
245+
246+
/// <summary>
247+
/// We need this to set a key irrespective of the 'IsKeyMutable' function.
248+
/// </summary>
249+
/// <param name="key">Key to update</param>
250+
/// <param name="value">New value to set</param>
251+
private void ForceSetIfDifferent(string key, object value) {
252+
lock (mutex) {
253+
// Check if the value has changed.
254+
object currentValue = this[key];
255+
if (Object.ReferenceEquals(currentValue, value) ||
256+
(currentValue != null && currentValue.Equals(value))) {
257+
// No change in value.
258+
return;
259+
}
260+
261+
PerformOperation(key, new ParseSetOperation(value));
262+
}
244263
}
245264

246265
/// <summary>

0 commit comments

Comments
 (0)