예제 #1
0
 def fetch_user_presence(user_id):
     if user_id in address_manager._userid_to_presence.keys():
         return address_manager.get_userid_presence(user_id)
     else:
         presence = UserPresence(
             dummy_matrix_client.get_user_presence(user_id))
         address_manager._userid_to_presence[user_id] = presence
         return address_manager._userid_to_presence[user_id]
예제 #2
0
    def _presence_listener(self, event: Dict[str, Any],
                           presence_update_id: int) -> None:
        """
        Update cached user presence state from Matrix presence events.

        Due to the possibility of nodes using accounts on multiple homeservers a composite
        address state is synthesised from the cached individual user presence states.

        This is a copy from the super class with a slight change.
        Any user will automatically be added to the whitelist whenever the PFS receives
        a presence update. We do this since we can assume that the PFS needs to know
        about all raiden users.
        """
        if self._stop_event.ready():
            return

        user_id = event["sender"]

        if event["type"] != "m.presence" or user_id == self._user_id:
            return

        address = address_from_userid(user_id)

        # not a user authenticated by EthAuthProvider
        if address is None:
            return

        user = self._user_from_id(user_id, event["content"].get("displayname"))

        if not user:
            return

        self._displayname_cache.warm_users([user])
        # If for any reason we cannot resolve the displayname, then there was a server error.
        # Any properly logged in user that joined a room, will have a displayname.
        # A reason for not resolving it could be rate limiting by the other server.
        if user.displayname is None:
            new_state = UserPresence.SERVER_ERROR
            self._set_user_presence(user_id, new_state, presence_update_id)
            return

        address = self._validate_userid_signature(user)
        if not address:
            return

        self.add_userid_for_address(address, user_id)

        new_state = UserPresence(event["content"]["presence"])

        self._set_user_presence(user_id, new_state, presence_update_id)
        self._maybe_address_reachability_changed(address)