diff --git a/react/features/app/components/App.native.js b/react/features/app/components/App.native.js index f1c755a00..0346ddb76 100644 --- a/react/features/app/components/App.native.js +++ b/react/features/app/components/App.native.js @@ -5,6 +5,7 @@ import React from 'react'; import '../../analytics'; import '../../authentication'; import { Platform } from '../../base/react'; +import '../../recent'; import '../../mobile/audio-mode'; import '../../mobile/background'; import '../../mobile/callkit'; diff --git a/react/features/recent/actionTypes.js b/react/features/recent/actionTypes.js new file mode 100644 index 000000000..56dbcacf5 --- /dev/null +++ b/react/features/recent/actionTypes.js @@ -0,0 +1,8 @@ +/** + * { + * type: ADD_RECENT_URL, + * roomURL: string, + * timestamp: Number + * } + */ +export const ADD_RECENT_URL = Symbol('ADD_RECENT_URL'); diff --git a/react/features/recent/index.js b/react/features/recent/index.js new file mode 100644 index 000000000..79da85d3d --- /dev/null +++ b/react/features/recent/index.js @@ -0,0 +1,4 @@ +export * from './actionTypes'; + +import './middleware'; +import './reducer'; diff --git a/react/features/recent/middleware.js b/react/features/recent/middleware.js new file mode 100644 index 000000000..075935fec --- /dev/null +++ b/react/features/recent/middleware.js @@ -0,0 +1,32 @@ +/* @flow */ + +import { MiddlewareRegistry } from '../base/redux'; +import { getInviteURL } from '../base/connection'; +import { CONFERENCE_WILL_JOIN } from '../base/conference'; + +import { ADD_RECENT_URL } from './actionTypes'; + +/** + * Middleware that captures conference actions and sets the correct audio mode + * based on the type of conference. Audio-only conferences don't use the speaker + * by default, and video conferences do. + * + * @param {Store} store - The redux store. + * @returns {Function} + */ +MiddlewareRegistry.register(({ dispatch, getState }) => next => action => { + const result = next(action); + + switch (action.type) { + case CONFERENCE_WILL_JOIN: { + dispatch({ + type: ADD_RECENT_URL, + roomURL: getInviteURL(getState), + timestamp: Date.now() + }); + break; + } + } + + return result; +}); diff --git a/react/features/recent/reducer.js b/react/features/recent/reducer.js new file mode 100644 index 000000000..1c61ab2ea --- /dev/null +++ b/react/features/recent/reducer.js @@ -0,0 +1,60 @@ +import { ReducerRegistry } from '../base/redux'; +import { ADD_RECENT_URL } from './actionTypes'; + +const MAX_LENGTH = 25; + +const INITIAL_STATE = { + entries: [] +}; + +/** + * Reduces the Redux actions of the feature features/recording. + */ +ReducerRegistry.register('features/recent', (state = INITIAL_STATE, action) => { + switch (action.type) { + case ADD_RECENT_URL: { + return _addRecentUrl(state, action); + } + default: + return state; + } +}); + +/** + * FIXME. + * @param state + * @param action + * @returns {Object} + * @private + */ +function _addRecentUrl(state, action) { + const { roomURL, timestamp } = action; + let existingIdx = -1; + + for (let i = 0; i < state.entries.length; i++) { + if (state.entries[i].roomURL === roomURL) { + existingIdx = i; + break; + } + } + + if (existingIdx !== -1) { + console.info('DELETED ALREADY EXISTING', roomURL); + state.entries.splice(existingIdx, 1); + } + + state.entries = new Array({ + roomURL, + timestamp + }).concat(state.entries); + + if (state.entries.length > MAX_LENGTH) { + const removed = state.entries.pop(); + + console.info('SIZE LIMIT exceeded, removed:', removed); + } + + console.info('RECENT URLs', state); + + return state; +}