Handle text messages sent to listening rooms

def _handle_message(self, room, event) -> bool:
        """ Handle text messages sent to listening rooms """
        if (
                event['type'] != 'm.room.message' or
                event['content']['msgtype'] != 'm.text' or
                self._stop_event.ready()
        ):
            # Ignore non-messages and non-text messages
            return False

        sender_id = event['sender']

        if sender_id == self._user_id:
            # Ignore our own messages
            return False

        user = self._get_user(sender_id)
        peer_address = validate_userid_signature(user)
        if not peer_address:
            self.log.debug(
                'Message from invalid user displayName signature',
                peer_user=user.user_id,
                room=room,
            )
            return False

        # don't proceed if user isn't whitelisted (yet)
        if not self._address_mgr.is_address_known(peer_address):
            # user not start_health_check'ed
            self.log.debug(
                'Message from non-whitelisted peer - ignoring',
                sender=user,
                sender_address=pex(peer_address),
                room=room,
            )
            return False

        # rooms we created and invited user, or were invited specifically by them
        room_ids = self._get_room_ids_for_address(peer_address)

        # TODO: Remove clause after `and` and check if things still don't hang
        if room.room_id not in room_ids and (self._private_rooms and not room.invite_only):
            # this should not happen, but is not fatal, as we may not know user yet
            if self._private_rooms and not room.invite_only:
                reason = 'required private room, but received message in a public'
            else:
                reason = 'unknown room for user'
            self.log.debug(
                'Ignoring invalid message',
                peer_user=user.user_id,
                peer_address=pex(peer_address),
                room=room,
                expected_room_ids=room_ids,
                reason=reason,
            )
            return False

        # TODO: With the condition in the TODO above restored this one won't have an effect, check
        #       if it can be removed after the above is solved
        if not room_ids or room.room_id != room_ids[0]:
            self.log.debug(
                'Received message triggered new comms room for peer',
                peer_user=user.user_id,
                peer_address=pex(peer_address),
                known_user_rooms=room_ids,
                room=room,
            )
            self._set_room_id_for_address(peer_address, room.room_id)

        is_peer_reachable = self._address_mgr.get_address_reachability(peer_address) is (
            AddressReachability.REACHABLE
        )
        if not is_peer_reachable:
            self.log.debug('Forcing presence update', peer_address=peer_address, user_id=sender_id)
            self._address_mgr.force_user_presence(user, UserPresence.ONLINE)
            self._address_mgr.refresh_address_presence(peer_address)

        data = event['content']['body']
        if not isinstance(data, str):
            self.log.warning(
                'Received message body not a string',
                peer_user=user.user_id,
                peer_address=to_checksum_address(peer_address),
                room=room,
            )
            return False

        messages: List[Message] = list()

        if data.startswith('0x'):
            try:
                message = message_from_bytes(decode_hex(data))
                if not message:
                    raise InvalidProtocolMessage
            except (DecodeError, AssertionError) as ex:
                self.log.warning(
                    "Can't parse message binary data",
                    message_data=data,
                    peer_address=pex(peer_address),
                    _exc=ex,
                )
                return False
            except InvalidProtocolMessage as ex:
                self.log.warning(
                    'Received message binary data is not a valid message',
                    message_data=data,
                    peer_address=pex(peer_address),
                    _exc=ex,
                )
                return False
            else:
                messages.append(message)

        else:
            for line in data.splitlines():
                line = line.strip()
                if not line:
                    continue
                try:
                    message_dict = json.loads(line)
                    message = message_from_dict(message_dict)
                except (UnicodeDecodeError, json.JSONDecodeError) as ex:
                    self.log.warning(
                        "Can't parse message data JSON",
                        message_data=line,
                        peer_address=pex(peer_address),
                        _exc=ex,
                    )
                    continue
                except InvalidProtocolMessage as ex:
                    self.log.warning(
                        "Message data JSON are not a valid message",
                        message_data=line,
                        peer_address=pex(peer_address),
                        _exc=ex,
                    )
                    continue
                if not isinstance(message, (SignedRetrieableMessage, SignedMessage)):
                    self.log.warning(
                        'Received invalid message',
                        message=message,
                    )
                    continue
                elif message.sender != peer_address:
                    self.log.warning(
                        'Message not signed by sender!',
                        message=message,
                        signer=message.sender,
                        peer_address=peer_address,
                    )
                    continue
                messages.append(message)

        if not messages:
            return False

        self.log.debug(
            'Incoming messages',
            messages=messages,
            sender=pex(peer_address),
            sender_user=user,
            room=room,
        )

        for message in messages:
            if isinstance(message, Delivered):
                self._receive_delivered(message)
            elif isinstance(message, Processed):
                self._receive_message(message)
            else:
                assert isinstance(message, SignedRetrieableMessage)
                self._receive_message(message)

        return True