ensure metaspace changes correctly notify listeners (#8611)
This commit is contained in:
parent
9b92eca73d
commit
2d386556a6
2 changed files with 29 additions and 0 deletions
|
@ -1072,6 +1072,7 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
?.["m.room_versions"]?.["org.matrix.msc3244.room_capabilities"]?.["restricted"];
|
?.["m.room_versions"]?.["org.matrix.msc3244.room_capabilities"]?.["restricted"];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const oldMetaSpaces = this._enabledMetaSpaces;
|
||||||
const enabledMetaSpaces = SettingsStore.getValue("Spaces.enabledMetaSpaces");
|
const enabledMetaSpaces = SettingsStore.getValue("Spaces.enabledMetaSpaces");
|
||||||
this._enabledMetaSpaces = metaSpaceOrder.filter(k => enabledMetaSpaces[k]);
|
this._enabledMetaSpaces = metaSpaceOrder.filter(k => enabledMetaSpaces[k]);
|
||||||
|
|
||||||
|
@ -1079,6 +1080,11 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
||||||
this.sendUserProperties();
|
this.sendUserProperties();
|
||||||
|
|
||||||
this.rebuildSpaceHierarchy(); // trigger an initial update
|
this.rebuildSpaceHierarchy(); // trigger an initial update
|
||||||
|
// rebuildSpaceHierarchy will only send an update if the spaces have changed.
|
||||||
|
// If only the meta spaces have changed, we need to send an update ourselves.
|
||||||
|
if (arrayHasDiff(oldMetaSpaces, this._enabledMetaSpaces)) {
|
||||||
|
this.emit(UPDATE_TOP_LEVEL_SPACES, this.spacePanelSpaces, this.enabledMetaSpaces);
|
||||||
|
}
|
||||||
|
|
||||||
// restore selected state from last session if any and still valid
|
// restore selected state from last session if any and still valid
|
||||||
const lastSpaceId = window.localStorage.getItem(ACTIVE_SPACE_LS_KEY);
|
const lastSpaceId = window.localStorage.getItem(ACTIVE_SPACE_LS_KEY);
|
||||||
|
|
|
@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { EventEmitter } from "events";
|
||||||
import { mocked } from 'jest-mock';
|
import { mocked } from 'jest-mock';
|
||||||
import { EventType } from "matrix-js-sdk/src/@types/event";
|
import { EventType } from "matrix-js-sdk/src/@types/event";
|
||||||
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
|
||||||
|
@ -1221,4 +1222,26 @@ describe("SpaceStore", () => {
|
||||||
expect(SpaceStore.instance.spacePanelSpaces.map(r => r.roomId)).toStrictEqual([rootSpace.roomId]);
|
expect(SpaceStore.instance.spacePanelSpaces.map(r => r.roomId)).toStrictEqual([rootSpace.roomId]);
|
||||||
await prom;
|
await prom;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("correctly emits events for metaspace changes during onReady", async () => {
|
||||||
|
// similar to useEventEmitterState, but for use inside of tests
|
||||||
|
function testEventEmitterState(
|
||||||
|
emitter: EventEmitter | undefined,
|
||||||
|
eventName: string | symbol,
|
||||||
|
callback: (...args: any[]) => void,
|
||||||
|
): () => void {
|
||||||
|
callback();
|
||||||
|
emitter.addListener(eventName, callback);
|
||||||
|
return () => emitter.removeListener(eventName, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
let metaSpaces;
|
||||||
|
const removeListener = testEventEmitterState(store, UPDATE_TOP_LEVEL_SPACES, () => {
|
||||||
|
metaSpaces = store.enabledMetaSpaces;
|
||||||
|
});
|
||||||
|
expect(metaSpaces).toEqual(store.enabledMetaSpaces);
|
||||||
|
await run();
|
||||||
|
expect(metaSpaces).toEqual(store.enabledMetaSpaces);
|
||||||
|
removeListener();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue