@@ -178,89 +178,102 @@ private bool ValidateClientMessage(IDictionary<string, object> message, out int
178178 Int32 . TryParse ( requestIdObj ? . ToString ( ) , out requestId ) ;
179179 }
180180
181+ private bool GetDictEntry ( IDictionary < string , object > message , string key , out IDictionary < string , object > objDict )
182+ {
183+ if ( message . TryGetValue ( key , out object obj ) &&
184+ obj is IDictionary < string , object > dict )
185+ {
186+ objDict = dict ;
187+ return true ;
188+ }
189+
190+ objDict = null ;
191+ return false ;
192+ }
193+
181194 void ProcessDeleteEventMessage ( IDictionary < string , object > message )
182195 {
183196 if ( ! ValidateClientMessage ( message , out int requestId ) )
184197 return ;
185198
186- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
187- {
188- subscription . OnDelete ( ParseObjectCoder . Instance . Decode (
189- message [ "object" ] as IDictionary < string , object > ,
190- Decoder ,
191- ParseClient . Instance . Services ) ) ;
192- }
199+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
200+ return ;
201+
202+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
203+ return ;
204+
205+ subscription . OnDelete ( ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ) ;
193206 }
194207
195208 void ProcessLeaveEventMessage ( IDictionary < string , object > message )
196209 {
197210 if ( ! ValidateClientMessage ( message , out int requestId ) )
198211 return ;
199212
200- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
201- {
202- subscription . OnLeave (
203- ParseObjectCoder . Instance . Decode (
204- message [ "object" ] as IDictionary < string , object > ,
205- Decoder ,
206- ParseClient . Instance . Services ) ,
207- ParseObjectCoder . Instance . Decode (
208- message [ "original" ] as IDictionary < string , object > ,
209- Decoder ,
210- ParseClient . Instance . Services ) ) ;
211- }
213+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
214+ return ;
215+
216+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
217+ return ;
218+
219+ if ( ! GetDictEntry ( message , "original" , out IDictionary < string , object > originalDict ) )
220+ return ;
221+
222+ subscription . OnLeave (
223+ ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ,
224+ ParseObjectCoder . Instance . Decode ( originalDict , Decoder , ParseClient . Instance . Services ) ) ;
212225 }
213226
214227 void ProcessUpdateEventMessage ( IDictionary < string , object > message )
215228 {
216229 if ( ! ValidateClientMessage ( message , out int requestId ) )
217230 return ;
218231
219- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
220- {
221- subscription . OnUpdate (
222- ParseObjectCoder . Instance . Decode (
223- message [ "object" ] as IDictionary < string , object > ,
224- Decoder ,
225- ParseClient . Instance . Services ) ,
226- ParseObjectCoder . Instance . Decode (
227- message [ "original" ] as IDictionary < string , object > ,
228- Decoder ,
229- ParseClient . Instance . Services ) ) ;
230- }
232+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
233+ return ;
234+
235+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
236+ return ;
237+
238+ if ( ! GetDictEntry ( message , "original" , out IDictionary < string , object > originalDict ) )
239+ return ;
240+
241+ subscription . OnUpdate (
242+ ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ,
243+ ParseObjectCoder . Instance . Decode ( originalDict , Decoder , ParseClient . Instance . Services ) ) ;
231244 }
232245
233246 void ProcessEnterEventMessage ( IDictionary < string , object > message )
234247 {
235248 if ( ! ValidateClientMessage ( message , out int requestId ) )
236249 return ;
237250
238- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
239- {
240- subscription . OnEnter (
241- ParseObjectCoder . Instance . Decode (
242- message [ "object" ] as IDictionary < string , object > ,
243- Decoder ,
244- ParseClient . Instance . Services ) ,
245- ParseObjectCoder . Instance . Decode (
246- message [ "original" ] as IDictionary < string , object > ,
247- Decoder ,
248- ParseClient . Instance . Services ) ) ;
249- }
251+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
252+ return ;
253+
254+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
255+ return ;
256+
257+ if ( ! GetDictEntry ( message , "original" , out IDictionary < string , object > originalDict ) )
258+ return ;
259+
260+ subscription . OnEnter (
261+ ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ,
262+ ParseObjectCoder . Instance . Decode ( originalDict , Decoder , ParseClient . Instance . Services ) ) ;
250263 }
251264
252265 void ProcessCreateEventMessage ( IDictionary < string , object > message )
253266 {
254267 if ( ! ValidateClientMessage ( message , out int requestId ) )
255268 return ;
256269
257- if ( Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
258- {
259- subscription . OnCreate ( ParseObjectCoder . Instance . Decode (
260- message [ "object" ] as IDictionary < string , object > ,
261- Decoder ,
262- ParseClient . Instance . Services ) ) ;
263- }
270+ if ( ! Subscriptions . TryGetValue ( requestId , out IParseLiveQuerySubscription subscription ) )
271+ return ;
272+
273+ if ( ! GetDictEntry ( message , "object" , out IDictionary < string , object > objectDict ) )
274+ return ;
275+
276+ subscription . OnCreate ( ParseObjectCoder . Instance . Decode ( objectDict , Decoder , ParseClient . Instance . Services ) ) ;
264277 }
265278
266279 void ProcessErrorMessage ( IDictionary < string , object > message )
@@ -277,8 +290,7 @@ void ProcessErrorMessage(IDictionary<string, object> message)
277290 Boolean . TryParse ( reconnectObj ? . ToString ( ) , out bool reconnect ) ) )
278291 return ;
279292
280- ParseLiveQueryErrorEventArgs errorArgs = new ParseLiveQueryErrorEventArgs ( code , error , reconnect ) ;
281- Error ? . Invoke ( this , errorArgs ) ;
293+ Error ? . Invoke ( this , new ParseLiveQueryErrorEventArgs ( code , error , reconnect ) ) ;
282294 }
283295
284296 void ProcessUnsubscriptionMessage ( IDictionary < string , object > message )
0 commit comments