feat: add recent URL
Store up to 25 recent URLs with timestamps (cherry picked from commit 29b99a4)
This commit is contained in:
parent
94a26a33c6
commit
2d1f2ed8bd
|
@ -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';
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
/**
|
||||
* {
|
||||
* type: ADD_RECENT_URL,
|
||||
* roomURL: string,
|
||||
* timestamp: Number
|
||||
* }
|
||||
*/
|
||||
export const ADD_RECENT_URL = Symbol('ADD_RECENT_URL');
|
|
@ -0,0 +1,4 @@
|
|||
export * from './actionTypes';
|
||||
|
||||
import './middleware';
|
||||
import './reducer';
|
|
@ -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;
|
||||
});
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue