Skip to content

Commit cfd1bc4

Browse files
authored
fix: LiveQuery event lost for operation on class with pointer field (#1863)
1 parent 13e68c2 commit cfd1bc4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Parse/Parse/Source/PFDecoder.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ - (id)decodeDictionary:(NSDictionary *)dictionary {
4747
}
4848

4949
NSString *type = dictionary[@"__type"];
50+
// Inject __type = @"Object" if missing but className/objectId present and on the presence of additional data fields so that bare pointer stubs continue to fall back to the legacy dictionary path.
51+
if (!type && dictionary[@"className"] && dictionary[@"objectId"]) {
52+
static NSSet<NSString *> *pointerKeys;
53+
static dispatch_once_t onceToken;
54+
dispatch_once(&onceToken, ^{
55+
pointerKeys = [NSSet setWithObjects:@"className", @"objectId", @"localId", nil];
56+
});
57+
BOOL hasAdditionalFields = NO;
58+
for (NSString *key in dictionary) {
59+
if (![pointerKeys containsObject:key]) {
60+
hasAdditionalFields = YES;
61+
break;
62+
}
63+
}
64+
if (!hasAdditionalFields) {
65+
return dictionary;
66+
}
67+
NSMutableDictionary *mutable = [dictionary mutableCopy];
68+
mutable[@"__type"] = @"Object";
69+
type = @"Object";
70+
dictionary = mutable;
71+
}
5072
if (type) {
5173
if ([type isEqualToString:@"Date"]) {
5274
return [[PFDateFormatter sharedFormatter] dateFromString:dictionary[@"iso"]];

ParseLiveQuery/ParseLiveQuery/Internal/ClientPrivate.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ private func parseObject<T: PFObject>(_ objectDictionary: [String:AnyObject]) th
1818
guard let _ = objectDictionary["objectId"] as? String else {
1919
throw LiveQueryErrors.InvalidJSONError(json: objectDictionary, expectedKey: "objectId")
2020
}
21-
2221
guard let object = PFDecoder.object().decode(objectDictionary) as? T else {
2322
throw LiveQueryErrors.InvalidJSONObject(json: objectDictionary, details: "cannot decode json into \(T.self)")
2423
}

0 commit comments

Comments
 (0)