Refactor ensureStateEvent to allow for specifying a stateKey.
ensureStateEvent
stateKey
In preparation for #2859 (closed) -> !2368 (merged)