Przeglądaj źródła

feat(MessageHandler): Implement dont show again utility

master
hristoterezov 9 lat temu
rodzic
commit
a8b69d5cd8

+ 10
- 31
modules/UI/UI.js Wyświetl plik

@@ -31,7 +31,6 @@ var messageHandler = UI.messageHandler;
31 31
 var JitsiPopover = require("./util/JitsiPopover");
32 32
 var Feedback = require("./feedback/Feedback");
33 33
 import FollowMe from "../FollowMe";
34
-import jitsiLocalStorage from '../util/JitsiLocalStorage';
35 34
 
36 35
 var eventEmitter = new EventEmitter();
37 36
 UI.eventEmitter = eventEmitter;
@@ -1215,7 +1214,11 @@ UI.showExtensionExternalInstallationDialog = function (url) {
1215 1214
  * @param {JitsiTrackError} cameraError
1216 1215
  */
1217 1216
 UI.showDeviceErrorDialog = function (micError, cameraError) {
1218
-    let localStoragePropName = "doNotShowErrorAgain";
1217
+    let dontShowAgain = {
1218
+        id: "doNotShowWarningAgain",
1219
+        localStorageKey: "doNotShowErrorAgain",
1220
+        textKey: "dialog.doNotShowWarningAgain"
1221
+    };
1219 1222
     let isMicJitsiTrackErrorAndHasName = micError && micError.name &&
1220 1223
         micError instanceof JitsiMeetJS.errorTypes.JitsiTrackError;
1221 1224
     let isCameraJitsiTrackErrorAndHasName = cameraError && cameraError.name &&
@@ -1232,17 +1235,11 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1232 1235
     }
1233 1236
 
1234 1237
     if (micError) {
1235
-        localStoragePropName += "-mic-" + micError.name;
1238
+        dontShowAgain.localStorageKey += "-mic-" + micError.name;
1236 1239
     }
1237 1240
 
1238 1241
     if (cameraError) {
1239
-        localStoragePropName += "-camera-" + cameraError.name;
1240
-    }
1241
-
1242
-    if (showDoNotShowWarning) {
1243
-        if (jitsiLocalStorage.getItem(localStoragePropName) === "true") {
1244
-            return;
1245
-        }
1242
+        dontShowAgain.localStorageKey += "-camera-" + cameraError.name;
1246 1243
     }
1247 1244
 
1248 1245
     let cameraJitsiTrackErrorMsg = cameraError
@@ -1267,12 +1264,6 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1267 1264
         micError.message
1268 1265
             ? `<div>${micError.message}</div>`
1269 1266
             : ``;
1270
-    let doNotShowWarningAgainSection = showDoNotShowWarning
1271
-        ? `<label>
1272
-            <input type='checkbox' id='doNotShowWarningAgain'>
1273
-            <span data-i18n='dialog.doNotShowWarningAgain'></span>
1274
-           </label>`
1275
-        : ``;
1276 1267
     let message = '';
1277 1268
 
1278 1269
     if (micError) {
@@ -1291,8 +1282,6 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1291 1282
             ${additionalCameraErrorMsg}`;
1292 1283
     }
1293 1284
 
1294
-    message = `${message}${doNotShowWarningAgainSection}`;
1295
-
1296 1285
     // To make sure we don't have multiple error dialogs open at the same time,
1297 1286
     // we will just close the previous one if we are going to show a new one.
1298 1287
     deviceErrorDialog && deviceErrorDialog.close();
@@ -1302,24 +1291,14 @@ UI.showDeviceErrorDialog = function (micError, cameraError) {
1302 1291
         message,
1303 1292
         false,
1304 1293
         {Ok: true},
1305
-        function () {
1306
-            let form  = $.prompt.getPrompt();
1307
-
1308
-            if (form) {
1309
-                let input = form.find("#doNotShowWarningAgain");
1310
-
1311
-                if (input.length) {
1312
-                    jitsiLocalStorage.setItem(localStoragePropName,
1313
-                        input.prop("checked"));
1314
-                }
1315
-            }
1316
-        },
1294
+        function () {},
1317 1295
         null,
1318 1296
         function () {
1319 1297
             // Reset dialog reference to null to avoid memory leaks when
1320 1298
             // user closed the dialog manually.
1321 1299
             deviceErrorDialog = null;
1322
-        }
1300
+        },
1301
+        showDoNotShowWarning ? dontShowAgain : undefined
1323 1302
     );
1324 1303
 
1325 1304
     function getTitleKey() {

+ 134
- 10
modules/UI/util/MessageHandler.js Wyświetl plik

@@ -1,6 +1,7 @@
1 1
 /* global $, APP, toastr, Impromptu */
2 2
 
3 3
 import UIUtil from './UIUtil';
4
+import jitsiLocalStorage from '../../util/JitsiLocalStorage';
4 5
 
5 6
 /**
6 7
  * Flag for enable/disable of the notifications.
@@ -20,6 +21,91 @@ let popupEnabled = true;
20 21
  */
21 22
 let twoButtonDialog = null;
22 23
 
24
+/**
25
+ * Generates html for dont show again checkbox.
26
+ * @param {object} options options
27
+ * @param {string} options.id the id of the checkbox.
28
+ * @param {string} options.textKey the key for the text displayed next to
29
+ * checkbox
30
+ * @param {boolean} options.checked if true the checkbox is foing to be checked
31
+ * by default.
32
+ * @returns {string}
33
+ */
34
+function generateDontShowCheckbox(options) {
35
+    if(!isDontShowAgainEnabled(options)) {
36
+        return "";
37
+    }
38
+
39
+    let checked
40
+        = (options.checked === true) ? "checked" : "";
41
+    return `<br />
42
+        <label>
43
+            <input type='checkbox' ${checked} id='${options.id}' />
44
+            <span data-i18n='${options.textKey}'></span>
45
+        </label>`;
46
+}
47
+
48
+/**
49
+ * Checks whether the dont show again checkbox was checked before.
50
+ * @param {object} options - options for dont show again checkbox.
51
+ * @param {string} options.id the id of the checkbox.
52
+ * @param {string} options.localStorageKey the key for the local storage. if
53
+ * not provided options.id will be used.
54
+ * @returns {boolean} true if the dialog mustn't be displayed and
55
+ * false otherwise.
56
+ */
57
+function dontShowTheDialog(options) {
58
+    if(isDontShowAgainEnabled(options)) {
59
+        if(jitsiLocalStorage.getItem(options.localStorageKey || options.id)
60
+            === "true") {
61
+            return true;
62
+        }
63
+    }
64
+    return false;
65
+}
66
+
67
+/**
68
+ * Wraps the submit function to process the dont show again status and store
69
+ * it.
70
+ * @param {object} options - options for dont show again checkbox.
71
+ * @param {string} options.id the id of the checkbox.
72
+ * @param {Array} options.buttonValues The button values that will trigger
73
+ * storing he checkbox value
74
+ * @param {string} options.localStorageKey the key for the local storage. if
75
+ * not provided options.id will be used.
76
+ * @param {Function} submitFunction the submit function to be wrapped
77
+ * @returns {Function} wrapped function
78
+ */
79
+function dontShowAgainSubmitFunctionWrapper(options, submitFunction) {
80
+    if(isDontShowAgainEnabled(options)) {
81
+        return (...args) => {
82
+            console.debug(args, options.buttonValues);
83
+            //args[1] is the value associated with the pressed button
84
+            if(!options.buttonValues || options.buttonValues.length === 0
85
+                || options.buttonValues.indexOf(args[1]) !== -1 ) {
86
+                let checkbox = $(`#${options.id}`);
87
+                if (checkbox.length) {
88
+                    jitsiLocalStorage.setItem(
89
+                        options.localStorageKey || options.id,
90
+                        checkbox.prop("checked"));
91
+                }
92
+            }
93
+            submitFunction(...args);
94
+        };
95
+    } else {
96
+        return submitFunction;
97
+    }
98
+}
99
+
100
+/**
101
+ * Check whether dont show again checkbox is enabled or not.
102
+ * @param {object} options - options for dont show again checkbox.
103
+ * @returns {boolean} true if enabled and false if not.
104
+ */
105
+function isDontShowAgainEnabled(options) {
106
+    return typeof options === "object";
107
+}
108
+
23 109
 var messageHandler = {
24 110
     OK: "dialog.OK",
25 111
     CANCEL: "dialog.Cancel",
@@ -72,6 +158,16 @@ var messageHandler = {
72 158
      *        the dialog is opened
73 159
      * @param defaultButton index of default button which will be activated when
74 160
      *        the user press 'enter'. Indexed from 0.
161
+     * @param {object} dontShowAgain - options for dont show again checkbox.
162
+     * @param {string} dontShowAgain.id the id of the checkbox.
163
+     * @param {string} dontShowAgain.textKey the key for the text displayed
164
+     * next to checkbox
165
+     * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
166
+     * be checked
167
+     * @param {Array} dontShowAgain.buttonValues The button values that will
168
+     * trigger storing the checkbox value
169
+     * @param {string} dontShowAgain.localStorageKey the key for the local
170
+     * storage. if not provided dontShowAgain.id will be used.
75 171
      * @return the prompt that was created, or null
76 172
      */
77 173
     openTwoButtonDialog: function(options) {
@@ -87,12 +183,20 @@ var messageHandler = {
87 183
             size,
88 184
             defaultButton,
89 185
             wrapperClass,
90
-            classes
186
+            classes,
187
+            dontShowAgain
91 188
         } = options;
92 189
 
93 190
         if (!popupEnabled || twoButtonDialog)
94 191
             return null;
95 192
 
193
+        if(dontShowTheDialog(dontShowAgain)) {
194
+            // Maybe we should pass some parameters here? I'm not sure
195
+            // and currently we don't need any parameters.
196
+            submitFunction();
197
+            return null;
198
+        }
199
+
96 200
         var buttons = [];
97 201
 
98 202
         var leftButton = leftButtonKey ?
@@ -108,6 +212,7 @@ var messageHandler = {
108 212
         if (msgKey) {
109 213
             message = APP.translation.generateTranslationHTML(msgKey);
110 214
         }
215
+        message += generateDontShowCheckbox(dontShowAgain);
111 216
         classes = classes || this._getDialogClasses(size);
112 217
         if (wrapperClass) {
113 218
             classes.prompt += ` ${wrapperClass}`;
@@ -122,13 +227,13 @@ var messageHandler = {
122 227
             loaded: loadedFunction,
123 228
             promptspeed: 0,
124 229
             classes,
125
-            submit: function (e, v, m, f) {
126
-                twoButtonDialog = null;
127
-                if (v){
128
-                    if (submitFunction)
230
+            submit: dontShowAgainSubmitFunctionWrapper(dontShowAgain,
231
+                function (e, v, m, f) {
232
+                    twoButtonDialog = null;
233
+                    if (v && submitFunction) {
129 234
                         submitFunction(e, v, m, f);
130
-                }
131
-            },
235
+                    }
236
+                }),
132 237
             close: function (e, v, m, f) {
133 238
                 twoButtonDialog = null;
134 239
                 if (closeFunction) {
@@ -155,12 +260,29 @@ var messageHandler = {
155 260
      * @param loadedFunction function to be called after the prompt is fully
156 261
      *        loaded
157 262
      * @param closeFunction function to be called on dialog close
263
+     * @param {object} dontShowAgain - options for dont show again checkbox.
264
+     * @param {string} dontShowAgain.id the id of the checkbox.
265
+     * @param {string} dontShowAgain.textKey the key for the text displayed
266
+     * next to checkbox
267
+     * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
268
+     * be checked
269
+     * @param {Array} dontShowAgain.buttonValues The button values that will
270
+     * trigger storing the checkbox value
271
+     * @param {string} dontShowAgain.localStorageKey the key for the local
272
+     * storage. if not provided dontShowAgain.id will be used.
158 273
      */
159 274
     openDialog: function (titleKey, msgString, persistent, buttons,
160
-                              submitFunction, loadedFunction, closeFunction) {
275
+        submitFunction, loadedFunction, closeFunction, dontShowAgain) {
161 276
         if (!popupEnabled)
162 277
             return;
163 278
 
279
+        if(dontShowTheDialog(dontShowAgain)) {
280
+            // Maybe we should pass some parameters here? I'm not sure
281
+            // and currently we don't need any parameters.
282
+            submitFunction();
283
+            return;
284
+        }
285
+
164 286
         let args = {
165 287
             title: this._getFormattedTitleString(titleKey),
166 288
             persistent: persistent,
@@ -168,7 +290,8 @@ var messageHandler = {
168 290
             defaultButton: 1,
169 291
             promptspeed: 0,
170 292
             loaded: loadedFunction,
171
-            submit: submitFunction,
293
+            submit: dontShowAgainSubmitFunctionWrapper(
294
+                dontShowAgain, submitFunction),
172 295
             close: closeFunction,
173 296
             classes: this._getDialogClasses()
174 297
         };
@@ -177,7 +300,8 @@ var messageHandler = {
177 300
             args.closeText = '';
178 301
         }
179 302
 
180
-        let dialog = new Impromptu(msgString, args);
303
+        let dialog = new Impromptu(
304
+            msgString + generateDontShowCheckbox(dontShowAgain), args);
181 305
         APP.translation.translateElement(dialog.getPrompt());
182 306
         return dialog;
183 307
     },

+ 8
- 27
modules/UI/videolayout/RemoteVideo.js Wyświetl plik

@@ -6,7 +6,6 @@ import SmallVideo from "./SmallVideo";
6 6
 import UIUtils from "../util/UIUtil";
7 7
 import UIEvents from '../../../service/UI/UIEvents';
8 8
 import JitsiPopover from "../util/JitsiPopover";
9
-import jitsiLocalStorage from '../../util/JitsiLocalStorage';
10 9
 
11 10
 const MUTED_DIALOG_BUTTON_VALUES = {
12 11
     cancel: 0,
@@ -653,36 +652,18 @@ RemoteVideo.createContainer = function (spanId) {
653 652
  * participant.
654 653
  */
655 654
 RemoteVideo.showMuteParticipantDialog = function () {
656
-    //FIXME: don't show again checkbox is implemented very dirty. we should add
657
-    // this functionality to MessageHandler class.
658
-    if (jitsiLocalStorage.getItem(
659
-            "dontShowMuteParticipantDialog") === "true") {
660
-        return Promise.resolve(MUTED_DIALOG_BUTTON_VALUES.muted);
661
-    }
662
-    let msgString =
663
-        `<div data-i18n="dialog.muteParticipantBody"></div>
664
-        <br />
665
-        <label>
666
-            <input type='checkbox' checked id='doNotShowMessageAgain' />
667
-            <span data-i18n='dialog.doNotShowMessageAgain'></span>
668
-        </label>`;
669 655
     return new Promise(resolve => {
670 656
         APP.UI.messageHandler.openTwoButtonDialog({
671 657
             titleKey : "dialog.muteParticipantTitle",
672
-            msgString,
673
-            leftButtonKey: 'dialog.muteParticipantButton',
674
-            submitFunction: () => {
675
-                let form  = $.prompt.getPrompt();
676
-                if (form) {
677
-                    let input = form.find("#doNotShowMessageAgain");
678
-                    if (input.length) {
679
-                        jitsiLocalStorage.setItem(
680
-                            "dontShowMuteParticipantDialog",
681
-                            input.prop("checked"));
682
-                    }
683
-                }
684
-                resolve(MUTED_DIALOG_BUTTON_VALUES.muted);
658
+            msgString: "<div data-i18n='dialog.muteParticipantBody'></div>",
659
+            leftButtonKey: "dialog.muteParticipantButton",
660
+            dontShowAgain: {
661
+                id: "dontShowMuteParticipantDialog",
662
+                textKey: "dialog.doNotShowMessageAgain",
663
+                checked: true,
664
+                buttonValues: [true]
685 665
             },
666
+            submitFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.muted),
686 667
             closeFunction: () => resolve(MUTED_DIALOG_BUTTON_VALUES.cancel)
687 668
         });
688 669
     });

Ładowanie…
Anuluj
Zapisz