diff --git a/react/features/polls/actions.js b/react/features/polls/actions.ts similarity index 97% rename from react/features/polls/actions.js rename to react/features/polls/actions.ts index 011437bbc..3f2f54db3 100644 --- a/react/features/polls/actions.js +++ b/react/features/polls/actions.ts @@ -1,5 +1,3 @@ -// @flow - import { CHANGE_VOTE, CLEAR_POLLS, @@ -9,7 +7,7 @@ import { RESET_NB_UNREAD_POLLS, RETRACT_VOTE } from './actionTypes'; -import type { Answer, Poll } from './types'; +import { Answer, Poll } from './types'; /** * Action to signal that existing polls needs to be cleared from state. diff --git a/react/features/polls/functions.js b/react/features/polls/functions.ts similarity index 83% rename from react/features/polls/functions.js rename to react/features/polls/functions.ts index b926bf92e..6c37e87d8 100644 --- a/react/features/polls/functions.js +++ b/react/features/polls/functions.ts @@ -1,4 +1,4 @@ -// @flow +import { IState } from '../app/types'; /** * Selector creator for determining if poll results should be displayed or not. @@ -7,7 +7,7 @@ * @returns {Function} */ export function shouldShowResults(id: string) { - return function(state: Object) { + return function(state: IState) { return Boolean(state['features/polls']?.polls[id].showResults); }; } @@ -19,7 +19,7 @@ export function shouldShowResults(id: string) { * @returns {Function} */ export function getPoll(pollId: string) { - return function(state: Object) { + return function(state: IState) { return state['features/polls'].polls[pollId]; }; } @@ -27,10 +27,10 @@ export function getPoll(pollId: string) { /** * Selector for calculating the number of unread poll messages. * - * @param {Object} state - The redux state. + * @param {IState} state - The redux state. * @returns {number} The number of unread messages. */ -export function getUnreadPollCount(state: Object) { +export function getUnreadPollCount(state: IState) { const { nbUnreadPolls } = state['features/polls']; return nbUnreadPolls; diff --git a/react/features/polls/middleware.js b/react/features/polls/middleware.ts similarity index 83% rename from react/features/polls/middleware.js rename to react/features/polls/middleware.ts index cad28362f..a2f2624d8 100644 --- a/react/features/polls/middleware.js +++ b/react/features/polls/middleware.ts @@ -1,16 +1,13 @@ -// @flow - -import { getCurrentConference } from '../base/conference'; +import { IStore } from '../app/types'; import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes'; +import { getCurrentConference } from '../base/conference/functions'; import { JitsiConferenceEvents } from '../base/lib-jitsi-meet'; -import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux'; -import { playSound } from '../base/sounds'; +import MiddlewareRegistry from '../base/redux/MiddlewareRegistry'; +import StateListenerRegistry from '../base/redux/StateListenerRegistry'; +import { playSound } from '../base/sounds/actions'; import { INCOMING_MSG_SOUND_ID } from '../chat/constants'; -import { - NOTIFICATION_TIMEOUT_TYPE, - NOTIFICATION_TYPE, - showNotification -} from '../notifications'; +import { showNotification } from '../notifications/actions'; +import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../notifications/constants'; import { RECEIVE_POLL } from './actionTypes'; import { clearPolls, receiveAnswer, receivePoll } from './actions'; @@ -19,7 +16,7 @@ import { COMMAND_NEW_POLL, COMMAND_OLD_POLLS } from './constants'; -import type { Answer, Poll } from './types'; +import { Answer, Poll, PollData } from './types'; /** * Set up state change listener to perform maintenance tasks when the conference @@ -36,7 +33,7 @@ StateListenerRegistry.register( } }); -const parsePollData = (pollData): Poll | null => { +const parsePollData = (pollData: PollData): Poll | null => { if (typeof pollData !== 'object' || pollData === null) { return null; } @@ -84,9 +81,9 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => { const { conference } = action; conference.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, - (_, data) => _handleReceivePollsMessage(data, dispatch)); + (_: any, data: any) => _handleReceivePollsMessage(data, dispatch)); conference.on(JitsiConferenceEvents.NON_PARTICIPANT_MESSAGE_RECEIVED, - (_, data) => _handleReceivePollsMessage(data, dispatch)); + (_: any, data: any) => _handleReceivePollsMessage(data, dispatch)); break; } @@ -118,7 +115,7 @@ MiddlewareRegistry.register(({ dispatch, getState }) => next => action => { * * @returns {void} */ -function _handleReceivePollsMessage(data, dispatch) { +function _handleReceivePollsMessage(data: any, dispatch: IStore['dispatch']) { switch (data.type) { case COMMAND_NEW_POLL: { const { question, answers, pollId, senderId, senderName } = data; @@ -130,7 +127,7 @@ function _handleReceivePollsMessage(data, dispatch) { showResults: false, lastVote: null, question, - answers: answers.map(answer => { + answers: answers.map((answer: Answer) => { return { name: answer, voters: new Map() diff --git a/react/features/polls/types.ts b/react/features/polls/types.ts index 18d37fbb0..7a05d099e 100644 --- a/react/features/polls/types.ts +++ b/react/features/polls/types.ts @@ -1,4 +1,4 @@ -export type Answer = { +export interface Answer { /** * An array of boolean: true if the answer was chosen by the responder, else false. @@ -19,9 +19,9 @@ export type Answer = { * Name of the voter. */ voterName: string; -}; +} -export type Poll = { +export interface Poll { /** * An array of answers: @@ -60,4 +60,8 @@ export type Poll = { * Whether the results should be shown instead of the answer form. */ showResults: boolean; -}; +} + +export interface PollData extends Poll { + id: string; +}