Exemplo n.º 1
0
def _fetch_new_members_for_network(api: GMatrixHttpApi,
                                   user_activity: Dict[str, int],
                                   discovery_room: RoomInfo,
                                   current_time: int) -> None:
    try:
        response = api._send(
            "GET",
            f"/_synapse/admin/v1/rooms/{discovery_room.room_id}/members")
        server_name = urlparse(api.base_url).netloc
        room_members = [
            member for member in response["members"]
            if member.split(":")[1] == server_name
            and not member.startswith("@admin")
        ]

        # Add new members with an overdue activity time
        # to trigger presence update later
        for user_id in room_members:
            if user_id not in user_activity:
                user_activity[
                    user_id] = current_time - USER_PURGING_THRESHOLD - 1

    except MatrixError as ex:
        click.secho(
            f"Could not fetch members for {discovery_room.alias} with error {ex}"
        )
Exemplo n.º 2
0
def _purge_inactive_users_for_network(
    api: GMatrixHttpApi,
    user_activity: Dict[str, int],
    due_users: List[str],
) -> None:
    for user_id in due_users:
        try:
            # delete user account and remove him from the user_activity_file
            last_ago = (int(time.time()) - user_activity[user_id]) / (60 * 60 *
                                                                      24)
            api._send(
                "POST",
                f"/deactivate/{user_id}",
                content={"erase": True},
                api_path="/_synapse/admin/v1",
            )
            user_activity.pop(user_id, None)
            click.secho(f"{user_id} deleted. Offline for {last_ago} days.")
        except MatrixError as ex:
            click.secho(f"Could not delete user {user_id} with error {ex}")
        finally:
            time.sleep(0.1)