Add line in to electret microphone and mute the microphone when plug is connected
simulate this circuit &ndash; Schematic created using CircuitLab

This may work.

R2 is to provide the DC load of the electret mic when the switch is on. At the same time Q1 is off disconnecting the mic.

When sourcing from the Audio Jack, vary R3 to get the signal level you want.



Looking at your second schematic again, if you replace the transistor with a PNP, and add a resistor (like 22K) in place of the "inverter" to reduce loading, the functions are equivalent to what I have above.