@@ -620,19 +620,38 @@ async def _get_events_from_db(self, event_ids, allow_rejected=False):
620620 room_version_id = row ["room_version_id" ]
621621
622622 if not room_version_id :
623- # this should only happen for out-of-band membership events
624- if not internal_metadata .get ("out_of_band_membership" ):
625- logger .warning (
626- "Room %s for event %s is unknown" , d ["room_id" ], event_id
623+ # this should only happen for out-of-band membership events which
624+ # arrived before #6983 landed. For all other events, we should have
625+ # an entry in the 'rooms' table.
626+ #
627+ # However, the 'out_of_band_membership' flag is unreliable for older
628+ # invites, so just accept it for all membership events.
629+ #
630+ if d ["type" ] != EventTypes .Member :
631+ raise Exception (
632+ "Room %s for event %s is unknown" % (d ["room_id" ], event_id )
627633 )
628- continue
629634
630- # take a wild stab at the room version based on the event format
635+ # so, assuming this is an out-of-band-invite that arrived before #6983
636+ # landed, we know that the room version must be v5 or earlier (because
637+ # v6 hadn't been invented at that point, so invites from such rooms
638+ # would have been rejected.)
639+ #
640+ # The main reason we need to know the room version here (other than
641+ # choosing the right python Event class) is in case the event later has
642+ # to be redacted - and all the room versions up to v5 used the same
643+ # redaction algorithm.
644+ #
645+ # So, the following approximations should be adequate.
646+
631647 if format_version == EventFormatVersions .V1 :
648+ # if it's event format v1 then it must be room v1 or v2
632649 room_version = RoomVersions .V1
633650 elif format_version == EventFormatVersions .V2 :
651+ # if it's event format v2 then it must be room v3
634652 room_version = RoomVersions .V3
635653 else :
654+ # if it's event format v3 then it must be room v4 or v5
636655 room_version = RoomVersions .V5
637656 else :
638657 room_version = KNOWN_ROOM_VERSIONS .get (room_version_id )
0 commit comments