<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def inplace_delete_message_queue( chain_state: ChainState, state_change: Union[ReceiveDelivered, ReceiveProcessed], queueid: QueueIdentifier, ) -> None: """ Filter messages from queue, if the queue becomes empty, cleanup the queue itself. """

    queue = chain_state.queueids_to_queues.get(queueid)
    if not queue:
        return

    inplace_delete_message(
        message_queue=queue,
        state_change=state_change,
    )

    if len(queue) == 0:
        del chain_state.queueids_to_queues[queueid]
    else:
        chain_state.queueids_to_queues[queueid] = queue