@@ -1815,52 +1815,45 @@ def _handle_event_relations(
18151815 txn: The current database transaction.
18161816 event: The event which might have relations.
18171817 """
1818- relation = event .content . get ( "m.relates_to" )
1818+ relation = event .relation ( )
18191819 if not relation :
1820- # No relations
1820+ # No relation, nothing to do.
18211821 return
18221822
1823- # Relations must have a type and parent event ID.
1824- rel_type = relation .get ("rel_type" )
1825- if not isinstance (rel_type , str ):
1826- return
1827-
1828- parent_id = relation .get ("event_id" )
1829- if not isinstance (parent_id , str ):
1830- return
1831-
1832- # Annotations have a key field.
1833- aggregation_key = None
1834- if rel_type == RelationTypes .ANNOTATION :
1835- aggregation_key = relation .get ("key" )
1836-
18371823 self .db_pool .simple_insert_txn (
18381824 txn ,
18391825 table = "event_relations" ,
18401826 values = {
18411827 "event_id" : event .event_id ,
1842- "relates_to_id" : parent_id ,
1843- "relation_type" : rel_type ,
1844- "aggregation_key" : aggregation_key ,
1828+ "relates_to_id" : relation . parent_id ,
1829+ "relation_type" : relation . rel_type ,
1830+ "aggregation_key" : relation . aggregation_key ,
18451831 },
18461832 )
18471833
1848- txn .call_after (self .store .get_relations_for_event .invalidate , (parent_id ,))
18491834 txn .call_after (
1850- self .store .get_aggregation_groups_for_event .invalidate , (parent_id ,)
1835+ self .store .get_relations_for_event .invalidate , (relation .parent_id ,)
1836+ )
1837+ txn .call_after (
1838+ self .store .get_aggregation_groups_for_event .invalidate ,
1839+ (relation .parent_id ,),
18511840 )
18521841
1853- if rel_type == RelationTypes .REPLACE :
1854- txn .call_after (self .store .get_applicable_edit .invalidate , (parent_id ,))
1842+ if relation .rel_type == RelationTypes .REPLACE :
1843+ txn .call_after (
1844+ self .store .get_applicable_edit .invalidate , (relation .parent_id ,)
1845+ )
18551846
1856- if rel_type == RelationTypes .THREAD :
1857- txn .call_after (self .store .get_thread_summary .invalidate , (parent_id ,))
1847+ if relation .rel_type == RelationTypes .THREAD :
1848+ txn .call_after (
1849+ self .store .get_thread_summary .invalidate , (relation .parent_id ,)
1850+ )
18581851 # It should be safe to only invalidate the cache if the user has not
18591852 # previously participated in the thread, but that's difficult (and
18601853 # potentially error-prone) so it is always invalidated.
18611854 txn .call_after (
18621855 self .store .get_thread_participated .invalidate ,
1863- (parent_id , event .sender ),
1856+ (relation . parent_id , event .sender ),
18641857 )
18651858
18661859 def _handle_insertion_event (self , txn : LoggingTransaction , event : EventBase ):
0 commit comments