Przeglądaj źródła

ref(reactions) Re-write using TypeScript (#11603)

master
Robert Pintilii 3 lat temu
rodzic
commit
38724458e3
No account linked to committer's email address

+ 4
- 0
react/features/app/types.ts Wyświetl plik

@@ -0,0 +1,4 @@
1
+export interface IStore {
2
+    getState: Function,
3
+    dispatch: Function
4
+}

react/features/reactions/actions.any.js → react/features/reactions/actions.any.ts Wyświetl plik

@@ -1,5 +1,3 @@
1
-// @flow
2
-
3 1
 import {
4 2
     ADD_REACTION_BUFFER,
5 3
     ADD_REACTION_MESSAGE,
@@ -8,18 +6,18 @@ import {
8 6
     SEND_REACTIONS,
9 7
     SET_REACTION_QUEUE
10 8
 } from './actionTypes';
11
-import { type ReactionEmojiProps } from './constants';
9
+import { ReactionEmojiProps } from './constants';
10
+import { ReactionsAction } from './reducer';
12 11
 
13 12
 /**
14 13
  * Sets the reaction queue.
15 14
  *
16
- * @param {Array} value - The new queue.
17
- * @returns {Function}
15
+ * @param {Array} queue - The new queue.
18 16
  */
19
-export function setReactionQueue(value: Array<ReactionEmojiProps>) {
17
+export function setReactionQueue(queue: Array<ReactionEmojiProps>): ReactionsAction {
20 18
     return {
21 19
         type: SET_REACTION_QUEUE,
22
-        value
20
+        queue
23 21
     };
24 22
 }
25 23
 
@@ -27,26 +25,21 @@ export function setReactionQueue(value: Array<ReactionEmojiProps>) {
27 25
 /**
28 26
  * Removes a reaction from the queue.
29 27
  *
30
- * @param {number} uid - Id of the reaction to be removed.
31
- * @returns {void}
28
+ * @param {string} uid - Id of the reaction to be removed.
32 29
  */
33
-export function removeReaction(uid: number) {
30
+export function removeReaction(uid: string): Function {
34 31
     return (dispatch: Function, getState: Function) => {
35 32
         const queue = getState()['features/reactions'].queue;
36 33
 
37
-        dispatch(setReactionQueue(queue.filter(reaction => reaction.uid !== uid)));
34
+        dispatch(setReactionQueue(queue.filter((reaction: ReactionEmojiProps) => reaction.uid !== uid)));
38 35
     };
39 36
 }
40 37
 
41 38
 
42 39
 /**
43 40
  * Sends the reactions buffer to everyone in the conference.
44
- *
45
- * @returns {{
46
- *     type: SEND_REACTION
47
- * }}
48 41
  */
49
-export function sendReactions() {
42
+export function sendReactions(): ReactionsAction {
50 43
     return {
51 44
         type: SEND_REACTIONS
52 45
     };
@@ -56,12 +49,8 @@ export function sendReactions() {
56 49
  * Adds a reaction to the local buffer.
57 50
  *
58 51
  * @param {string} reaction - The reaction to be added.
59
- * @returns {{
60
- *     type: ADD_REACTION_BUFFER,
61
- *     reaction: string
62
- * }}
63 52
  */
64
-export function addReactionToBuffer(reaction: string) {
53
+export function addReactionToBuffer(reaction: string): ReactionsAction {
65 54
     return {
66 55
         type: ADD_REACTION_BUFFER,
67 56
         reaction
@@ -70,12 +59,8 @@ export function addReactionToBuffer(reaction: string) {
70 59
 
71 60
 /**
72 61
  * Clears the reaction buffer.
73
- *
74
- * @returns {{
75
- *     type: FLUSH_REACTION_BUFFER
76
- * }}
77 62
  */
78
-export function flushReactionBuffer() {
63
+export function flushReactionBuffer(): ReactionsAction {
79 64
     return {
80 65
         type: FLUSH_REACTION_BUFFER
81 66
     };
@@ -85,12 +70,8 @@ export function flushReactionBuffer() {
85 70
  * Adds a reaction message to the chat.
86 71
  *
87 72
  * @param {string} message - The reaction message.
88
- * @returns {{
89
- *     type: ADD_REACTION_MESSAGE,
90
- *     message: string
91
- * }}
92 73
  */
93
-export function addReactionsToChat(message: string) {
74
+export function addReactionsToChat(message: string): ReactionsAction {
94 75
     return {
95 76
         type: ADD_REACTION_MESSAGE,
96 77
         message
@@ -101,12 +82,8 @@ export function addReactionsToChat(message: string) {
101 82
  * Adds reactions to the animation queue.
102 83
  *
103 84
  * @param {Array} reactions - The reactions to be animated.
104
- * @returns {{
105
- *     type: PUSH_REACTIONS,
106
- *     reactions: Array
107
- * }}
108 85
  */
109
-export function pushReactions(reactions: Array<string>) {
86
+export function pushReactions(reactions: Array<string>): ReactionsAction {
110 87
     return {
111 88
         type: PUSH_REACTIONS,
112 89
         reactions

react/features/reactions/actions.native.js → react/features/reactions/actions.native.ts Wyświetl plik


react/features/reactions/actions.web.js → react/features/reactions/actions.web.ts Wyświetl plik

@@ -1,16 +1,13 @@
1
-// @flow
2
-
3 1
 import {
4 2
     SHOW_SOUNDS_NOTIFICATION,
5 3
     TOGGLE_REACTIONS_VISIBLE
6 4
 } from './actionTypes';
5
+import { ReactionsAction } from './reducer';
7 6
 
8 7
 /**
9 8
  * Toggles the visibility of the reactions menu.
10
- *
11
- * @returns {Object}
12 9
  */
13
-export function toggleReactionsMenuVisibility() {
10
+export function toggleReactionsMenuVisibility(): ReactionsAction {
14 11
     return {
15 12
         type: TOGGLE_REACTIONS_VISIBLE
16 13
     };
@@ -18,10 +15,8 @@ export function toggleReactionsMenuVisibility() {
18 15
 
19 16
 /**
20 17
  * Displays the disable sounds notification.
21
- *
22
- * @returns {Object}
23 18
  */
24
-export function displayReactionSoundsNotification() {
19
+export function displayReactionSoundsNotification(): ReactionsAction {
25 20
     return {
26 21
         type: SHOW_SOUNDS_NOTIFICATION
27 22
     };

+ 1
- 3
react/features/reactions/components/web/RaiseHandButton.js Wyświetl plik

@@ -1,5 +1,3 @@
1
-// @flow
2
-
3 1
 import { translate } from '../../../base/i18n';
4 2
 import { IconRaisedHand } from '../../../base/icons';
5 3
 import { getLocalParticipant, hasRaisedHand } from '../../../base/participants';
@@ -15,7 +13,7 @@ type Props = AbstractButtonProps & {
15 13
     /**
16 14
      * Whether or not the hand is raised.
17 15
      */
18
-     raisedHand: boolean,
16
+    raisedHand: boolean,
19 17
 };
20 18
 
21 19
 /**

react/features/reactions/components/web/ReactionEmoji.js → react/features/reactions/components/web/ReactionEmoji.tsx Wyświetl plik

@@ -1,10 +1,10 @@
1
-// @flow
2
-
3 1
 import React, { Component } from 'react';
4 2
 
3
+// @ts-ignore
5 4
 import { connect } from '../../../base/redux';
6 5
 import { removeReaction } from '../../actions.any';
7 6
 import { REACTIONS } from '../../constants';
7
+import { IStore } from '../../../app/types';
8 8
 
9 9
 type Props = {
10 10
 
@@ -16,12 +16,12 @@ type Props = {
16 16
     /**
17 17
      * Id of the reaction.
18 18
      */
19
-    uid: Number,
19
+    uid: string,
20 20
 
21 21
     /**
22 22
      * Removes reaction from redux state.
23 23
      */
24
-    removeReaction: Function,
24
+    reactionRemove: Function,
25 25
 
26 26
     /**
27 27
      * Index of the reaction in the queue.
@@ -64,7 +64,7 @@ class ReactionEmoji extends Component<Props, State> {
64 64
      * @inheritdoc
65 65
      */
66 66
     componentDidMount() {
67
-        setTimeout(() => this.props.removeReaction(this.props.uid), 5000);
67
+        setTimeout(() => this.props.reactionRemove(this.props.uid), 5000);
68 68
     }
69 69
 
70 70
     /**
@@ -86,11 +86,8 @@ class ReactionEmoji extends Component<Props, State> {
86 86
     }
87 87
 }
88 88
 
89
-const mapDispatchToProps = {
90
-    removeReaction
91
-};
89
+const mapDispatchToProps = (dispatch: IStore['dispatch']) => ({
90
+    reactionRemove: (uid: string) => dispatch(removeReaction(uid))
91
+});
92 92
 
93
-export default connect(
94
-    null,
95
-    mapDispatchToProps
96
-)(ReactionEmoji);
93
+export default connect(null, mapDispatchToProps)(ReactionEmoji);

react/features/reactions/components/web/ReactionsMenu.js → react/features/reactions/components/web/ReactionsMenu.tsx Wyświetl plik

@@ -1,7 +1,3 @@
1
-// @flow
2
-
3
-/* eslint-disable react/jsx-no-bind */
4
-
5 1
 import { withStyles } from '@material-ui/styles';
6 2
 import clsx from 'clsx';
7 3
 import React, { Component } from 'react';
@@ -11,20 +7,34 @@ import {
11 7
     createReactionMenuEvent,
12 8
     createToolbarEvent,
13 9
     sendAnalytics
10
+    // @ts-ignore
14 11
 } from '../../../analytics';
12
+import { IStore } from '../../../app/types';
13
+// @ts-ignore
15 14
 import { isMobileBrowser } from '../../../base/environment/utils';
15
+// @ts-ignore
16 16
 import { translate } from '../../../base/i18n';
17
+// @ts-ignore
17 18
 import { getLocalParticipant, hasRaisedHand, raiseHand } from '../../../base/participants';
19
+// @ts-ignore
18 20
 import { connect } from '../../../base/redux';
21
+// @ts-ignore
19 22
 import { GifsMenu, GifsMenuButton } from '../../../gifs/components';
23
+// @ts-ignore
20 24
 import { isGifEnabled, isGifsMenuOpen } from '../../../gifs/functions';
25
+// @ts-ignore
21 26
 import { dockToolbox } from '../../../toolbox/actions.web';
22 27
 import { addReactionToBuffer } from '../../actions.any';
23 28
 import { toggleReactionsMenuVisibility } from '../../actions.web';
24 29
 import { REACTIONS, REACTIONS_MENU_HEIGHT } from '../../constants';
25 30
 
31
+// @ts-ignore
26 32
 import ReactionButton from './ReactionButton';
27 33
 
34
+interface Classes {
35
+    overflow: string
36
+}
37
+
28 38
 type Props = {
29 39
 
30 40
     /**
@@ -60,7 +70,7 @@ type Props = {
60 70
     /**
61 71
      * An object containing the CSS classes.
62 72
      */
63
-    classes: Object,
73
+    classes: Classes,
64 74
 
65 75
     /**
66 76
      * The Redux Dispatch function.
@@ -80,7 +90,7 @@ type Props = {
80 90
 
81 91
 declare var APP: Object;
82 92
 
83
-const styles = theme => {
93
+const styles = (theme: any) => {
84 94
     return {
85 95
         overflow: {
86 96
             width: 'auto',
@@ -114,10 +124,6 @@ class ReactionsMenu extends Component<Props> {
114 124
         this._getReactionButtons = this._getReactionButtons.bind(this);
115 125
     }
116 126
 
117
-    _onToolbarToggleRaiseHand: () => void;
118
-
119
-    _getReactionButtons: () => Array<React$Element<*>>;
120
-
121 127
     /**
122 128
      * Implements React Component's componentDidMount.
123 129
      *
@@ -190,6 +196,7 @@ class ReactionsMenu extends Component<Props> {
190 196
                 sendAnalytics(createReactionMenuEvent(key));
191 197
             }
192 198
 
199
+            // @ts-ignore
193 200
             return (<ReactionButton
194 201
                 accessibilityLabel = { t(`toolbar.accessibilityLabel.${key}`) }
195 202
                 icon = { REACTIONS[key].emoji }
@@ -219,6 +226,7 @@ class ReactionsMenu extends Component<Props> {
219 226
                 </div>
220 227
                 {_isMobile && (
221 228
                     <div className = 'raise-hand-row'>
229
+                        {/* @ts-ignore */}
222 230
                         <ReactionButton
223 231
                             accessibilityLabel = { t('toolbar.accessibilityLabel.raiseHand') }
224 232
                             icon = '✋'
@@ -242,7 +250,7 @@ class ReactionsMenu extends Component<Props> {
242 250
  * @param {Object} state - Redux state.
243 251
  * @returns {Object}
244 252
  */
245
-function mapStateToProps(state) {
253
+function mapStateToProps(state: any) {
246 254
     const localParticipant = getLocalParticipant(state);
247 255
 
248 256
     return {
@@ -260,12 +268,13 @@ function mapStateToProps(state) {
260 268
  * @param {Object} dispatch - Redux dispatch.
261 269
  * @returns {Object}
262 270
  */
263
-function mapDispatchToProps(dispatch) {
271
+function mapDispatchToProps(dispatch: IStore['dispatch']) {
264 272
     return {
265 273
         dispatch,
266 274
         ...bindActionCreators(
267 275
         {
268 276
             _dockToolbox: dockToolbox
277
+        // @ts-ignore
269 278
         }, dispatch)
270 279
     };
271 280
 }
@@ -273,4 +282,5 @@ function mapDispatchToProps(dispatch) {
273 282
 export default translate(connect(
274 283
     mapStateToProps,
275 284
     mapDispatchToProps
285
+    // @ts-ignore
276 286
 )(withStyles(styles)(ReactionsMenu)));

react/features/reactions/components/web/ReactionsMenuButton.js → react/features/reactions/components/web/ReactionsMenuButton.tsx Wyświetl plik

@@ -1,18 +1,25 @@
1 1
 // @flow
2 2
 
3 3
 import React, { useCallback } from 'react';
4
+// @ts-ignore
4 5
 import { useSelector } from 'react-redux';
5 6
 
7
+// @ts-ignore
6 8
 import { isMobileBrowser } from '../../../base/environment/utils';
9
+// @ts-ignore
7 10
 import { translate } from '../../../base/i18n';
11
+// @ts-ignore
8 12
 import { IconArrowUp } from '../../../base/icons';
13
+// @ts-ignore
9 14
 import { connect } from '../../../base/redux';
15
+// @ts-ignore
10 16
 import ToolboxButtonWithIconPopup from '../../../base/toolbox/components/web/ToolboxButtonWithIconPopup';
11 17
 import { toggleReactionsMenuVisibility } from '../../actions.web';
12
-import { type ReactionEmojiProps } from '../../constants';
18
+import { ReactionEmojiProps } from '../../constants';
13 19
 import { getReactionsQueue, isReactionsEnabled } from '../../functions.any';
14 20
 import { getReactionsMenuVisibility } from '../../functions.web';
15 21
 
22
+// @ts-ignore
16 23
 import RaiseHandButton from './RaiseHandButton';
17 24
 import ReactionEmoji from './ReactionEmoji';
18 25
 import ReactionsMenu from './ReactionsMenu';
@@ -111,11 +118,9 @@ function ReactionsMenuButton({
111 118
                         ariaExpanded = { isOpen }
112 119
                         ariaHasPopup = { true }
113 120
                         ariaLabel = { t('toolbar.accessibilityLabel.reactionsMenu') }
114
-                        buttonKey = { buttonKey }
115 121
                         icon = { IconArrowUp }
116 122
                         iconDisabled = { false }
117 123
                         iconId = 'reactions-menu-button'
118
-                        notifyMode = { notifyMode }
119 124
                         onPopoverClose = { toggleReactionsMenu }
120 125
                         onPopoverOpen = { openReactionsMenu }
121 126
                         popoverContent = { reactionsMenu }
@@ -141,7 +146,7 @@ function ReactionsMenuButton({
141 146
  * @param {Object} state - Redux state.
142 147
  * @returns {Object}
143 148
  */
144
-function mapStateToProps(state) {
149
+function mapStateToProps(state: any) {
145 150
     return {
146 151
         _reactionsEnabled: isReactionsEnabled(state),
147 152
         isOpen: getReactionsMenuVisibility(state),

react/features/reactions/constants.js → react/features/reactions/constants.ts Wyświetl plik

@@ -1,5 +1,3 @@
1
-// @flow
2
-
3 1
 import {
4 2
     CLAP_SOUND_FILES,
5 3
     LAUGH_SOUND_FILES,
@@ -87,7 +85,7 @@ export const SILENCE_SOUND_ID = `${REACTION_SOUND}_SILENCE_`;
87 85
  */
88 86
 export const RAISE_HAND_SOUND_ID = 'RAISE_HAND_SOUND';
89 87
 
90
-export type ReactionEmojiProps = {
88
+export interface ReactionEmojiProps {
91 89
 
92 90
     /**
93 91
      * Reaction to be displayed.
@@ -97,13 +95,22 @@ export type ReactionEmojiProps = {
97 95
     /**
98 96
      * Id of the reaction.
99 97
      */
100
-    uid: number
98
+    uid: string
101 99
 }
102 100
 
103 101
 export const SOUNDS_THRESHOLDS = [ 1, 4, 10 ];
104 102
 
103
+interface IReactions {
104
+    [key: string]: {
105
+        message: string;
106
+        emoji: string;
107
+        shortcutChar: string;
108
+        soundId: string;
109
+        soundFiles: string[];
110
+    }
111
+}
105 112
 
106
-export const REACTIONS = {
113
+export const REACTIONS: IReactions = {
107 114
     like: {
108 115
         message: ':thumbs_up:',
109 116
         emoji: '👍',
@@ -147,3 +154,12 @@ export const REACTIONS = {
147 154
         soundFiles: SILENCE_SOUND_FILES
148 155
     }
149 156
 };
157
+
158
+export type ReactionThreshold = {
159
+    reaction: string,
160
+    threshold: number
161
+}
162
+
163
+export interface MuteCommandAttributes {
164
+    startReactionsMuted?: string;
165
+}

react/features/reactions/functions.any.js → react/features/reactions/functions.any.ts Wyświetl plik

@@ -1,21 +1,21 @@
1
-// @flow
2
-
3 1
 import { v4 as uuidv4 } from 'uuid';
4 2
 
3
+// @ts-ignore
5 4
 import { getFeatureFlag, REACTIONS_ENABLED } from '../base/flags';
5
+// @ts-ignore
6 6
 import { getLocalParticipant } from '../base/participants';
7
+// @ts-ignore
7 8
 import { extractFqnFromPath } from '../dynamic-branding/functions.any';
8 9
 
9
-import { REACTIONS, SOUNDS_THRESHOLDS } from './constants';
10
+import { ReactionEmojiProps, REACTIONS, ReactionThreshold, SOUNDS_THRESHOLDS } from './constants';
10 11
 import logger from './logger';
11 12
 
12 13
 /**
13 14
  * Returns the queue of reactions.
14 15
  *
15 16
  * @param {Object} state - The state of the application.
16
- * @returns {boolean}
17 17
  */
18
-export function getReactionsQueue(state: Object) {
18
+export function getReactionsQueue(state: any): Array<ReactionEmojiProps> {
19 19
     return state['features/reactions'].queue;
20 20
 }
21 21
 
@@ -23,20 +23,18 @@ export function getReactionsQueue(state: Object) {
23 23
  * Returns chat message from reactions buffer.
24 24
  *
25 25
  * @param {Array} buffer - The reactions buffer.
26
- * @returns {string}
27 26
  */
28
-export function getReactionMessageFromBuffer(buffer: Array<string>) {
29
-    return buffer.map(reaction => REACTIONS[reaction].message).reduce((acc, val) => `${acc}${val}`);
27
+export function getReactionMessageFromBuffer(buffer: Array<string>): string {
28
+    return buffer.map<string>(reaction => REACTIONS[reaction].message).reduce((acc, val) => `${acc}${val}`);
30 29
 }
31 30
 
32 31
 /**
33 32
  * Returns reactions array with uid.
34 33
  *
35 34
  * @param {Array} buffer - The reactions buffer.
36
- * @returns {Array}
37 35
  */
38
-export function getReactionsWithId(buffer: Array<string>) {
39
-    return buffer.map<Object>(reaction => {
36
+export function getReactionsWithId(buffer: Array<string>): Array<ReactionEmojiProps> {
37
+    return buffer.map<ReactionEmojiProps>(reaction => {
40 38
         return {
41 39
             reaction,
42 40
             uid: uuidv4()
@@ -49,9 +47,8 @@ export function getReactionsWithId(buffer: Array<string>) {
49 47
  *
50 48
  * @param {Object} state - The redux state object.
51 49
  * @param {Array} reactions - Reactions array to be sent.
52
- * @returns {void}
53 50
  */
54
-export async function sendReactionsWebhook(state: Object, reactions: Array<?string>) {
51
+export async function sendReactionsWebhook(state: any, reactions: Array<string>) {
55 52
     const { webhookProxyUrl: url } = state['features/base/config'];
56 53
     const { conference } = state['features/base/conference'];
57 54
     const { jwt } = state['features/base/jwt'];
@@ -96,9 +93,8 @@ export async function sendReactionsWebhook(state: Object, reactions: Array<?stri
96 93
  * Returns unique reactions from the reactions buffer.
97 94
  *
98 95
  * @param {Array} reactions - The reactions buffer.
99
- * @returns {Array}
100 96
  */
101
-function getUniqueReactions(reactions: Array<string>) {
97
+function getUniqueReactions(reactions: Array<string>): Array<string> {
102 98
     return [ ...new Set(reactions) ];
103 99
 }
104 100
 
@@ -107,9 +103,8 @@ function getUniqueReactions(reactions: Array<string>) {
107 103
  *
108 104
  * @param {Array} reactions - Array of reactions.
109 105
  * @param {string} reaction - Reaction to get frequency for.
110
- * @returns {number}
111 106
  */
112
-function getReactionFrequency(reactions: Array<string>, reaction: string) {
107
+function getReactionFrequency(reactions: Array<string>, reaction: string): number {
113 108
     return reactions.filter(r => r === reaction).length;
114 109
 }
115 110
 
@@ -117,9 +112,8 @@ function getReactionFrequency(reactions: Array<string>, reaction: string) {
117 112
  * Returns the threshold number for a given frequency.
118 113
  *
119 114
  * @param {number} frequency - Frequency of reaction.
120
- * @returns {number}
121 115
  */
122
-function getSoundThresholdByFrequency(frequency) {
116
+function getSoundThresholdByFrequency(frequency: number): number {
123 117
     for (const i of SOUNDS_THRESHOLDS) {
124 118
         if (frequency <= i) {
125 119
             return i;
@@ -133,12 +127,11 @@ function getSoundThresholdByFrequency(frequency) {
133 127
  * Returns unique reactions with threshold.
134 128
  *
135 129
  * @param {Array} reactions - The reactions buffer.
136
- * @returns {Array}
137 130
  */
138
-export function getReactionsSoundsThresholds(reactions: Array<string>) {
131
+export function getReactionsSoundsThresholds(reactions: Array<string>): Array<ReactionThreshold> {
139 132
     const unique = getUniqueReactions(reactions);
140 133
 
141
-    return unique.map<Object>(reaction => {
134
+    return unique.map<ReactionThreshold>(reaction => {
142 135
         return {
143 136
             reaction,
144 137
             threshold: getSoundThresholdByFrequency(getReactionFrequency(reactions, reaction))
@@ -150,9 +143,8 @@ export function getReactionsSoundsThresholds(reactions: Array<string>) {
150 143
  * Whether or not the reactions are enabled.
151 144
  *
152 145
  * @param {Object} state - The Redux state object.
153
- * @returns {boolean}
154 146
  */
155
-export function isReactionsEnabled(state: Object) {
147
+export function isReactionsEnabled(state: any): boolean {
156 148
     const { disableReactions } = state['features/base/config'];
157 149
 
158 150
     if (navigator.product === 'ReactNative') {

react/features/reactions/functions.web.js → react/features/reactions/functions.web.ts Wyświetl plik

@@ -1,11 +1,8 @@
1
-// @flow
2
-
3 1
 /**
4 2
  * Returns the visibility state of the reactions menu.
5 3
  *
6 4
  * @param {Object} state - The state of the application.
7
- * @returns {boolean}
8 5
  */
9
-export function getReactionsMenuVisibility(state: Object) {
6
+export function getReactionsMenuVisibility(state: any): boolean {
10 7
     return state['features/reactions'].visible;
11 8
 }

react/features/reactions/logger.js → react/features/reactions/logger.ts Wyświetl plik

@@ -1,5 +1,4 @@
1
-// @flow
2
-
1
+// @ts-ignore
3 2
 import { getLogger } from '../base/logging/functions';
4 3
 
5 4
 export default getLogger('features/base/reactions');

react/features/reactions/middleware.js → react/features/reactions/middleware.ts Wyświetl plik

@@ -1,24 +1,31 @@
1
-// @flow
2
-
1
+// @ts-ignore
3 2
 import { batch } from 'react-redux';
4
-
3
+// @ts-ignore
5 4
 import { createReactionSoundsDisabledEvent, sendAnalytics } from '../analytics';
5
+// @ts-ignore
6 6
 import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
7 7
 import {
8 8
     CONFERENCE_JOIN_IN_PROGRESS,
9 9
     SET_START_REACTIONS_MUTED,
10 10
     setStartReactionsMuted
11
+    // @ts-ignore
11 12
 } from '../base/conference';
12 13
 import {
13 14
     getParticipantById,
14 15
     getParticipantCount,
15 16
     isLocalParticipantModerator
17
+    // @ts-ignore
16 18
 } from '../base/participants';
19
+// @ts-ignore
17 20
 import { MiddlewareRegistry } from '../base/redux';
18 21
 import { SETTINGS_UPDATED } from '../base/settings/actionTypes';
22
+// @ts-ignore
19 23
 import { updateSettings } from '../base/settings/actions';
24
+// @ts-ignore
20 25
 import { playSound, registerSound, unregisterSound } from '../base/sounds';
26
+// @ts-ignore
21 27
 import { getDisabledSounds } from '../base/sounds/functions.any';
28
+// @ts-ignore
22 29
 import { NOTIFICATION_TIMEOUT_TYPE, showNotification } from '../notifications';
23 30
 
24 31
 import {
@@ -28,7 +35,6 @@ import {
28 35
     PUSH_REACTIONS,
29 36
     SHOW_SOUNDS_NOTIFICATION
30 37
 } from './actionTypes';
31
-import { displayReactionSoundsNotification } from './actions';
32 38
 import {
33 39
     addReactionsToChat,
34 40
     flushReactionBuffer,
@@ -36,13 +42,15 @@ import {
36 42
     sendReactions,
37 43
     setReactionQueue
38 44
 } from './actions.any';
45
+import { displayReactionSoundsNotification } from './actions.web';
39 46
 import {
40 47
     ENDPOINT_REACTION_NAME,
41 48
     RAISE_HAND_SOUND_ID,
42 49
     REACTIONS,
43 50
     REACTION_SOUND,
44 51
     SOUNDS_THRESHOLDS,
45
-    MUTE_REACTIONS_COMMAND
52
+    MUTE_REACTIONS_COMMAND,
53
+    MuteCommandAttributes
46 54
 } from './constants';
47 55
 import {
48 56
     getReactionMessageFromBuffer,
@@ -52,15 +60,16 @@ import {
52 60
 } from './functions.any';
53 61
 import logger from './logger';
54 62
 import { RAISE_HAND_SOUND_FILE } from './sounds';
63
+import { IStore } from '../app/types';
55 64
 
56 65
 /**
57 66
  * Middleware which intercepts Reactions actions to handle changes to the
58 67
  * visibility timeout of the Reactions.
59 68
  *
60
- * @param {Store} store - The redux store.
69
+ * @param {IStore} store - The redux store.
61 70
  * @returns {Function}
62 71
  */
63
-MiddlewareRegistry.register(store => next => action => {
72
+MiddlewareRegistry.register((store: IStore) => (next: Function) => (action:any) => {
64 73
     const { dispatch, getState } = store;
65 74
 
66 75
     switch (action.type) {
@@ -108,7 +117,7 @@ MiddlewareRegistry.register(store => next => action => {
108 117
         const { conference } = action;
109 118
 
110 119
         conference.addCommandListener(
111
-            MUTE_REACTIONS_COMMAND, ({ attributes }, id) => {
120
+            MUTE_REACTIONS_COMMAND, ({ attributes }: { attributes: MuteCommandAttributes }, id: any) => {
112 121
                 _onMuteReactionsCommand(attributes, id, store);
113 122
             });
114 123
         break;
@@ -232,9 +241,8 @@ MiddlewareRegistry.register(store => next => action => {
232 241
  * @param {Object} store - The redux store. Used to calculate and dispatch
233 242
  * updates.
234 243
  * @private
235
- * @returns {void}
236 244
  */
237
-function _onMuteReactionsCommand(attributes = {}, id, store) {
245
+function _onMuteReactionsCommand(attributes: MuteCommandAttributes = {}, id: string, store: IStore) {
238 246
     const state = store.getState();
239 247
 
240 248
     // We require to know who issued the command because (1) only a
@@ -259,6 +267,7 @@ function _onMuteReactionsCommand(attributes = {}, id, store) {
259 267
     }
260 268
 
261 269
     const oldState = Boolean(state['features/base/conference'].startReactionsMuted);
270
+    // @ts-ignore
262 271
     const newState = attributes.startReactionsMuted === 'true';
263 272
 
264 273
     if (oldState !== newState) {

react/features/reactions/reducer.js → react/features/reactions/reducer.ts Wyświetl plik

@@ -1,5 +1,4 @@
1
-// @flow
2
-
1
+// @ts-ignore
3 2
 import { ReducerRegistry } from '../base/redux';
4 3
 
5 4
 import {
@@ -9,60 +8,70 @@ import {
9 8
     FLUSH_REACTION_BUFFER,
10 9
     SHOW_SOUNDS_NOTIFICATION
11 10
 } from './actionTypes';
11
+import { ReactionEmojiProps } from './constants';
12
+
13
+interface State {
14
+    /**
15
+     * The indicator that determines whether the reactions menu is visible.
16
+     */
17
+    visible: boolean,
18
+    /**
19
+     * An array that contains the reactions buffer to be sent.
20
+     */
21
+    buffer: Array<string>,
22
+    /**
23
+     * A number, non-zero value which identifies the timer created by a call
24
+     * to setTimeout().
25
+     */
26
+    timeoutID: number|null,
27
+    /**
28
+    * The array of reactions to animate.
29
+    */
30
+    queue: Array<ReactionEmojiProps>,
31
+
32
+    /**
33
+     * Whether or not the disable reaction sounds notification was shown.
34
+     */
35
+    notificationDisplayed: boolean
36
+}
37
+
38
+export interface ReactionsAction extends Partial<State> {
39
+    /**
40
+     * The message to be added to the chat.
41
+     */
42
+    message?: string,
43
+    /**
44
+     * The reaction to be added to buffer.
45
+     */
46
+    reaction?: string,
47
+    /**
48
+     * The reactions to be added to the animation queue.
49
+     */
50
+    reactions?: Array<string>,
51
+    /**
52
+     * The action type.
53
+     */
54
+    type: string
55
+}
12 56
 
13 57
 /**
14 58
  * Returns initial state for reactions' part of Redux store.
15 59
  *
16 60
  * @private
17
- * @returns {{
18
- *     visible: boolean,
19
- *     message: string,
20
- *     timeoutID: number,
21
- *     queue: Array,
22
- *     notificationDisplayed: boolean
23
- * }}
24 61
  */
25
-function _getInitialState() {
62
+function _getInitialState(): State {
26 63
     return {
27
-        /**
28
-         * The indicator that determines whether the reactions menu is visible.
29
-         *
30
-         * @type {boolean}
31
-         */
32 64
         visible: false,
33
-
34
-        /**
35
-         * An array that contains the reactions buffer to be sent.
36
-         *
37
-         * @type {Array}
38
-         */
39 65
         buffer: [],
40
-
41
-        /**
42
-         * A number, non-zero value which identifies the timer created by a call
43
-         * to setTimeout().
44
-         *
45
-         * @type {number|null}
46
-         */
47 66
         timeoutID: null,
48
-
49
-        /**
50
-         * The array of reactions to animate.
51
-         *
52
-         * @type {Array}
53
-         */
54 67
         queue: [],
55
-
56
-        /**
57
-         * Whether or not the disable reaction sounds notification was shown.
58
-         */
59 68
         notificationDisplayed: false
60 69
     };
61 70
 }
62 71
 
63 72
 ReducerRegistry.register(
64 73
     'features/reactions',
65
-    (state: Object = _getInitialState(), action: Object) => {
74
+    (state: State = _getInitialState(), action: ReactionsAction) => {
66 75
         switch (action.type) {
67 76
 
68 77
         case TOGGLE_REACTIONS_VISIBLE:
@@ -88,7 +97,7 @@ ReducerRegistry.register(
88 97
         case SET_REACTION_QUEUE: {
89 98
             return {
90 99
                 ...state,
91
-                queue: action.value
100
+                queue: action.queue
92 101
             };
93 102
         }
94 103
 

react/features/reactions/sounds.js → react/features/reactions/sounds.ts Wyświetl plik


Ładowanie…
Anuluj
Zapisz