refactor: Simplify relates to and make it more type safe
Everything in content is user generated so we should never expect correct types and return null instead.
This commit is contained in:
		
							parent
							
								
									08e0284cef
								
							
						
					
					
						commit
						657a332b03
					
				|  | @ -673,17 +673,11 @@ class Event extends MatrixEvent { | ||||||
| 
 | 
 | ||||||
|   /// Get the event ID that this relationship will reference. `null` if there is none |   /// Get the event ID that this relationship will reference. `null` if there is none | ||||||
|   String? get relationshipEventId { |   String? get relationshipEventId { | ||||||
|     if (!(content['m.relates_to'] is Map)) { |     final relatesToMap = content.tryGetMap<String, dynamic>('m.relates_to'); | ||||||
|       return null; |     return relatesToMap?.tryGet<String>('event_id') ?? | ||||||
|     } |         relatesToMap | ||||||
|     if (content['m.relates_to'].containsKey('event_id')) { |             ?.tryGetMap<String, dynamic>('m.in_reply_to') | ||||||
|       return content['m.relates_to']['event_id']; |             ?.tryGet<String>('event_id'); | ||||||
|     } |  | ||||||
|     if (content['m.relates_to']['m.in_reply_to'] is Map && |  | ||||||
|         content['m.relates_to']['m.in_reply_to'].containsKey('event_id')) { |  | ||||||
|       return content['m.relates_to']['m.in_reply_to']['event_id']; |  | ||||||
|     } |  | ||||||
|     return null; |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   /// Get whether this event has aggregated events from a certain [type] |   /// Get whether this event has aggregated events from a certain [type] | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue