import appDispatcher from '../dispatcher';
import cons from '../state/cons';
+/**
+ * @param {string | string[]} roomId - room id or array of them to add into shortcuts
+ */
export function createSpaceShortcut(roomId) {
appDispatcher.dispatch({
type: cons.actions.accountData.CREATE_SPACE_SHORTCUT,
accountActions(action) {
const actions = {
[cons.actions.accountData.CREATE_SPACE_SHORTCUT]: () => {
- if (this.spaceShortcut.has(action.roomId)) return;
- this.spaceShortcut.add(action.roomId);
+ const addRoomId = (id) => {
+ if (this.spaceShortcut.has(id)) return;
+ this.spaceShortcut.add(id);
+ };
+ if (Array.isArray(action.roomId)) {
+ action.roomId.forEach(addRoomId);
+ } else {
+ addRoomId(action.roomId);
+ }
this._updateSpaceShortcutData([...this.spaceShortcut]);
this.emit(cons.events.accountData.SPACE_SHORTCUT_UPDATED, action.roomId);
},