mirror of https://github.com/jitsi/jitsi-meet
parent
2514617417
commit
60b4581cb5
@ -0,0 +1,23 @@ |
||||
/** |
||||
* The type of the action which signals that we need to remove poll from the history(local storage). |
||||
* |
||||
* { |
||||
* type: REMOVE_POLL_FROM_HISTORY, |
||||
* meetingId: string, |
||||
* pollId: string, |
||||
* poll: IPoll |
||||
* } |
||||
*/ |
||||
export const REMOVE_POLL_FROM_HISTORY = 'REMOVE_POLL_FROM_HISTORY'; |
||||
|
||||
/** |
||||
* The type of the action triggered when the poll is saved in history(local storage). |
||||
* |
||||
* { |
||||
* type: SAVE_POLL_IN_HISTORY, |
||||
* poll: Poll, |
||||
* pollId: string, |
||||
* saved: boolean |
||||
* } |
||||
*/ |
||||
export const SAVE_POLL_IN_HISTORY = 'SAVE_POLL_IN_HISTORY'; |
@ -0,0 +1,47 @@ |
||||
import { IPoll } from '../polls/types'; |
||||
|
||||
import { REMOVE_POLL_FROM_HISTORY, SAVE_POLL_IN_HISTORY } from './actionTypes'; |
||||
|
||||
/** |
||||
* Action to signal saving a poll in history(local storage). |
||||
* |
||||
* @param {string} meetingId - The id of the meeting in which polls get to be saved. |
||||
* @param {string} pollId - The id of the poll that gets to be saved. |
||||
* @param {IPoll} poll - The Poll object that gets to be saved. |
||||
* @returns {{ |
||||
* type: SAVE_POLL_IN_HISTORY, |
||||
* meetingId: string, |
||||
* pollId: string, |
||||
* poll: IPoll |
||||
* }} |
||||
*/ |
||||
export function savePollInHistory(meetingId: string | undefined, pollId: string, poll: IPoll) { |
||||
return { |
||||
type: SAVE_POLL_IN_HISTORY, |
||||
meetingId, |
||||
pollId, |
||||
poll |
||||
}; |
||||
} |
||||
|
||||
/** |
||||
* Action to signal that existing poll needs to be deleted from history(local storage). |
||||
* |
||||
* @param {string} meetingId - The id of the meeting in which poll gets to be removed. |
||||
* @param {string} pollId - The id of the poll that gets to be removed. |
||||
* @param {IPoll} poll - The incoming IPoll object. |
||||
* @returns {{ |
||||
* type: REMOVE_POLL_FROM_HISTORY, |
||||
* meetingId: string, |
||||
* pollId: string, |
||||
* poll: IPoll |
||||
* }} |
||||
*/ |
||||
export const removePollFromHistory = (meetingId: string | undefined, pollId: string, poll: IPoll) => { |
||||
return { |
||||
type: REMOVE_POLL_FROM_HISTORY, |
||||
meetingId, |
||||
pollId, |
||||
poll |
||||
}; |
||||
}; |
@ -0,0 +1,46 @@ |
||||
import { CONFERENCE_JOINED } from '../base/conference/actionTypes'; |
||||
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry'; |
||||
import { REMOVE_POLL, SAVE_POLL } from '../polls/actionTypes'; |
||||
import { savePoll } from '../polls/actions'; |
||||
|
||||
import { removePollFromHistory, savePollInHistory } from './actions'; |
||||
|
||||
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => { |
||||
const result = next(action); |
||||
const { room: meetingId } = getState()['features/base/conference']; |
||||
|
||||
switch (action.type) { |
||||
|
||||
case CONFERENCE_JOINED: { |
||||
const state = getState(); |
||||
const pollsHistory = meetingId && state['features/polls-history'].polls?.[meetingId]; |
||||
|
||||
if (!pollsHistory) { |
||||
return null; |
||||
} |
||||
|
||||
for (const key in pollsHistory) { |
||||
if (pollsHistory.hasOwnProperty(key) && pollsHistory[key].saved) { |
||||
dispatch(savePoll(key, pollsHistory[key])); |
||||
} |
||||
} |
||||
break; |
||||
} |
||||
|
||||
case REMOVE_POLL: { |
||||
const { poll, pollId } = action; |
||||
|
||||
dispatch(removePollFromHistory(meetingId, pollId, poll)); |
||||
break; |
||||
} |
||||
|
||||
case SAVE_POLL: { |
||||
const { poll, pollId } = action; |
||||
|
||||
dispatch(savePollInHistory(meetingId, pollId, poll)); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
return result; |
||||
}); |
@ -0,0 +1,52 @@ |
||||
import PersistenceRegistry from '../base/redux/PersistenceRegistry'; |
||||
import ReducerRegistry from '../base/redux/ReducerRegistry'; |
||||
import { IPoll } from '../polls/types'; |
||||
|
||||
import { REMOVE_POLL_FROM_HISTORY, SAVE_POLL_IN_HISTORY } from './actionTypes'; |
||||
|
||||
const INITIAL_STATE = { |
||||
polls: {} |
||||
}; |
||||
|
||||
export interface IPollsHistoryState { |
||||
polls: { |
||||
[meetingId: string]: { |
||||
[pollId: string]: IPoll; |
||||
}; |
||||
}; |
||||
} |
||||
|
||||
const STORE_NAME = 'features/polls-history'; |
||||
|
||||
PersistenceRegistry.register(STORE_NAME, INITIAL_STATE); |
||||
|
||||
ReducerRegistry.register<IPollsHistoryState>(STORE_NAME, (state = INITIAL_STATE, action): IPollsHistoryState => { |
||||
switch (action.type) { |
||||
|
||||
case REMOVE_POLL_FROM_HISTORY: { |
||||
if (Object.keys(state.polls[action.meetingId] ?? {})?.length === 1) { |
||||
delete state.polls[action.meetingId]; |
||||
} else { |
||||
delete state.polls[action.meetingId]?.[action.pollId]; |
||||
} |
||||
|
||||
return state; |
||||
} |
||||
|
||||
case SAVE_POLL_IN_HISTORY: { |
||||
return { |
||||
...state, |
||||
polls: { |
||||
...state.polls, |
||||
[action.meetingId]: { |
||||
...state.polls[action.meetingId], |
||||
[action.pollId]: action.poll |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
|
||||
default: |
||||
return state; |
||||
} |
||||
}); |
Loading…
Reference in new issue