Fossil SCM
Added a toggle to play the audio alert (or not) for one's own messages (default=off) and added docs describing each configurable setting.
Commit
8534eb75e17db41bdb4a6030801fd4077066b3da1b1edc2a3e4c9ab8a926a10b
Parent
87c29eee983cb01…
1 file changed
+39
-5
+39
-5
| --- src/fossil.page.chat.js | ||
| +++ src/fossil.page.chat.js | ||
| @@ -374,19 +374,46 @@ | ||
| 374 | 374 | addListener: function(setting, f){ |
| 375 | 375 | F.page.addEventListener('chat-setting', function(ev){ |
| 376 | 376 | if(ev.detail.key===setting) f(ev.detail); |
| 377 | 377 | }, false); |
| 378 | 378 | }, |
| 379 | + /* Default values of settings. These are used for intializing | |
| 380 | + the setting event listeners and config view UI. */ | |
| 379 | 381 | defaults:{ |
| 382 | + /* When on, inbound images are displayed inlined, else as a | |
| 383 | + link to download the image. */ | |
| 380 | 384 | "images-inline": !!F.config.chat.imagesInline, |
| 385 | + /* When on, ctrl-enter sends messages, else enter and | |
| 386 | + ctrl-enter both send them. */ | |
| 381 | 387 | "edit-ctrl-send": false, |
| 388 | + /* When on, the edit field starts as a single line and | |
| 389 | + expands as the user types, and the relevant buttons are | |
| 390 | + laid out in a compact form. When off, the edit field and | |
| 391 | + buttons are larger. */ | |
| 382 | 392 | "edit-compact-mode": true, |
| 393 | + /* When on, sets the font-family on messages and the edit | |
| 394 | + field to monospace. */ | |
| 383 | 395 | "monospace-messages": true, |
| 396 | + /* When on, non-chat UI elements (page header/footer) are | |
| 397 | + hidden */ | |
| 384 | 398 | "chat-only-mode": false, |
| 399 | + /* When set to a URI, it is assumed to be an audio file, | |
| 400 | + which gets played when new messages arrive. When true, | |
| 401 | + the first entry in the audio file selection list will be | |
| 402 | + used. */ | |
| 385 | 403 | "audible-alert": true, |
| 404 | + /* When on, show the list of "active" users - those from | |
| 405 | + whom we have messages in the currently-loaded history | |
| 406 | + (noting that deletions are also messages). */ | |
| 386 | 407 | "active-user-list": false, |
| 387 | - "active-user-list-timestamps": false | |
| 408 | + /* When on, the [active-user-list] setting includes the | |
| 409 | + timestamp of each user's most recent message. */ | |
| 410 | + "active-user-list-timestamps": false, | |
| 411 | + /* When on, the [audible-alert] is played for one's own | |
| 412 | + messages, else it is only played for other users' | |
| 413 | + messages. */ | |
| 414 | + "alert-own-messages": false | |
| 388 | 415 | } |
| 389 | 416 | }, |
| 390 | 417 | /** Plays a new-message notification sound IF the audible-alert |
| 391 | 418 | setting is true, else this is a no-op. Returns this. |
| 392 | 419 | */ |
| @@ -395,11 +422,11 @@ | ||
| 395 | 422 | try{ |
| 396 | 423 | if(!f.audio) f.audio = new Audio(f.uri); |
| 397 | 424 | f.audio.currentTime = 0; |
| 398 | 425 | f.audio.play(); |
| 399 | 426 | }catch(e){ |
| 400 | - console.error("Audio playblack failed.",e); | |
| 427 | + console.error("Audio playblack failed.", f.uri, e); | |
| 401 | 428 | } |
| 402 | 429 | } |
| 403 | 430 | return this; |
| 404 | 431 | }, |
| 405 | 432 | /** |
| @@ -1387,11 +1414,11 @@ | ||
| 1387 | 1414 | if(true===Chat.settings.getBool('audible-alert')){ |
| 1388 | 1415 | /* This setting used to be a plain bool. If we encounter |
| 1389 | 1416 | such a setting, take the first sound in the list. */ |
| 1390 | 1417 | selectSound.selectedIndex = firstSoundIndex; |
| 1391 | 1418 | }else{ |
| 1392 | - selectSound.value = Chat.settings.get('audible-alert',''); | |
| 1419 | + selectSound.value = Chat.settings.get('audible-alert','<none>'); | |
| 1393 | 1420 | if(selectSound.selectedIndex<0){ |
| 1394 | 1421 | /* Missing file - removed after this setting was |
| 1395 | 1422 | applied. Fall back to the first sound in the list. */ |
| 1396 | 1423 | selectSound.selectedIndex = firstSoundIndex; |
| 1397 | 1424 | } |
| @@ -1406,10 +1433,17 @@ | ||
| 1406 | 1433 | F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 1407 | 1434 | if(v) setTimeout(()=>Chat.playNewMessageSound(), 0); |
| 1408 | 1435 | } |
| 1409 | 1436 | }); |
| 1410 | 1437 | }/*audio notification config*/ |
| 1438 | + settingsOps.push({ | |
| 1439 | + label: "Play notification for your own messages.", | |
| 1440 | + hint: "When enabled, the audio notification will be played for all messages, "+ | |
| 1441 | + "including your own. When disabled only messages from other users "+ | |
| 1442 | + "will trigger a notification.", | |
| 1443 | + boolValue: 'alert-own-messages' | |
| 1444 | + }); | |
| 1411 | 1445 | /** |
| 1412 | 1446 | Build UI for config options... |
| 1413 | 1447 | */ |
| 1414 | 1448 | settingsOps.forEach(function f(op){ |
| 1415 | 1449 | const line = D.addClass(D.div(), 'menu-entry'); |
| @@ -1601,12 +1635,12 @@ | ||
| 1601 | 1635 | /* A record deletion notice. */ |
| 1602 | 1636 | Chat.deleteMessageElem(m.mdel); |
| 1603 | 1637 | return; |
| 1604 | 1638 | } |
| 1605 | 1639 | if(!Chat._isBatchLoading |
| 1606 | - && Chat.me!==m.xfrom | |
| 1607 | - && Chat.playNewMessageSound){ | |
| 1640 | + && (Chat.me!==m.xfrom | |
| 1641 | + || Chat.settings.getBool('alert-own-messages'))){ | |
| 1608 | 1642 | Chat.playNewMessageSound(); |
| 1609 | 1643 | } |
| 1610 | 1644 | const row = new Chat.MessageWidget(m); |
| 1611 | 1645 | Chat.injectMessageElem(row.e.body,atEnd); |
| 1612 | 1646 | if(m.isError){ |
| 1613 | 1647 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -374,19 +374,46 @@ | |
| 374 | addListener: function(setting, f){ |
| 375 | F.page.addEventListener('chat-setting', function(ev){ |
| 376 | if(ev.detail.key===setting) f(ev.detail); |
| 377 | }, false); |
| 378 | }, |
| 379 | defaults:{ |
| 380 | "images-inline": !!F.config.chat.imagesInline, |
| 381 | "edit-ctrl-send": false, |
| 382 | "edit-compact-mode": true, |
| 383 | "monospace-messages": true, |
| 384 | "chat-only-mode": false, |
| 385 | "audible-alert": true, |
| 386 | "active-user-list": false, |
| 387 | "active-user-list-timestamps": false |
| 388 | } |
| 389 | }, |
| 390 | /** Plays a new-message notification sound IF the audible-alert |
| 391 | setting is true, else this is a no-op. Returns this. |
| 392 | */ |
| @@ -395,11 +422,11 @@ | |
| 395 | try{ |
| 396 | if(!f.audio) f.audio = new Audio(f.uri); |
| 397 | f.audio.currentTime = 0; |
| 398 | f.audio.play(); |
| 399 | }catch(e){ |
| 400 | console.error("Audio playblack failed.",e); |
| 401 | } |
| 402 | } |
| 403 | return this; |
| 404 | }, |
| 405 | /** |
| @@ -1387,11 +1414,11 @@ | |
| 1387 | if(true===Chat.settings.getBool('audible-alert')){ |
| 1388 | /* This setting used to be a plain bool. If we encounter |
| 1389 | such a setting, take the first sound in the list. */ |
| 1390 | selectSound.selectedIndex = firstSoundIndex; |
| 1391 | }else{ |
| 1392 | selectSound.value = Chat.settings.get('audible-alert',''); |
| 1393 | if(selectSound.selectedIndex<0){ |
| 1394 | /* Missing file - removed after this setting was |
| 1395 | applied. Fall back to the first sound in the list. */ |
| 1396 | selectSound.selectedIndex = firstSoundIndex; |
| 1397 | } |
| @@ -1406,10 +1433,17 @@ | |
| 1406 | F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 1407 | if(v) setTimeout(()=>Chat.playNewMessageSound(), 0); |
| 1408 | } |
| 1409 | }); |
| 1410 | }/*audio notification config*/ |
| 1411 | /** |
| 1412 | Build UI for config options... |
| 1413 | */ |
| 1414 | settingsOps.forEach(function f(op){ |
| 1415 | const line = D.addClass(D.div(), 'menu-entry'); |
| @@ -1601,12 +1635,12 @@ | |
| 1601 | /* A record deletion notice. */ |
| 1602 | Chat.deleteMessageElem(m.mdel); |
| 1603 | return; |
| 1604 | } |
| 1605 | if(!Chat._isBatchLoading |
| 1606 | && Chat.me!==m.xfrom |
| 1607 | && Chat.playNewMessageSound){ |
| 1608 | Chat.playNewMessageSound(); |
| 1609 | } |
| 1610 | const row = new Chat.MessageWidget(m); |
| 1611 | Chat.injectMessageElem(row.e.body,atEnd); |
| 1612 | if(m.isError){ |
| 1613 |
| --- src/fossil.page.chat.js | |
| +++ src/fossil.page.chat.js | |
| @@ -374,19 +374,46 @@ | |
| 374 | addListener: function(setting, f){ |
| 375 | F.page.addEventListener('chat-setting', function(ev){ |
| 376 | if(ev.detail.key===setting) f(ev.detail); |
| 377 | }, false); |
| 378 | }, |
| 379 | /* Default values of settings. These are used for intializing |
| 380 | the setting event listeners and config view UI. */ |
| 381 | defaults:{ |
| 382 | /* When on, inbound images are displayed inlined, else as a |
| 383 | link to download the image. */ |
| 384 | "images-inline": !!F.config.chat.imagesInline, |
| 385 | /* When on, ctrl-enter sends messages, else enter and |
| 386 | ctrl-enter both send them. */ |
| 387 | "edit-ctrl-send": false, |
| 388 | /* When on, the edit field starts as a single line and |
| 389 | expands as the user types, and the relevant buttons are |
| 390 | laid out in a compact form. When off, the edit field and |
| 391 | buttons are larger. */ |
| 392 | "edit-compact-mode": true, |
| 393 | /* When on, sets the font-family on messages and the edit |
| 394 | field to monospace. */ |
| 395 | "monospace-messages": true, |
| 396 | /* When on, non-chat UI elements (page header/footer) are |
| 397 | hidden */ |
| 398 | "chat-only-mode": false, |
| 399 | /* When set to a URI, it is assumed to be an audio file, |
| 400 | which gets played when new messages arrive. When true, |
| 401 | the first entry in the audio file selection list will be |
| 402 | used. */ |
| 403 | "audible-alert": true, |
| 404 | /* When on, show the list of "active" users - those from |
| 405 | whom we have messages in the currently-loaded history |
| 406 | (noting that deletions are also messages). */ |
| 407 | "active-user-list": false, |
| 408 | /* When on, the [active-user-list] setting includes the |
| 409 | timestamp of each user's most recent message. */ |
| 410 | "active-user-list-timestamps": false, |
| 411 | /* When on, the [audible-alert] is played for one's own |
| 412 | messages, else it is only played for other users' |
| 413 | messages. */ |
| 414 | "alert-own-messages": false |
| 415 | } |
| 416 | }, |
| 417 | /** Plays a new-message notification sound IF the audible-alert |
| 418 | setting is true, else this is a no-op. Returns this. |
| 419 | */ |
| @@ -395,11 +422,11 @@ | |
| 422 | try{ |
| 423 | if(!f.audio) f.audio = new Audio(f.uri); |
| 424 | f.audio.currentTime = 0; |
| 425 | f.audio.play(); |
| 426 | }catch(e){ |
| 427 | console.error("Audio playblack failed.", f.uri, e); |
| 428 | } |
| 429 | } |
| 430 | return this; |
| 431 | }, |
| 432 | /** |
| @@ -1387,11 +1414,11 @@ | |
| 1414 | if(true===Chat.settings.getBool('audible-alert')){ |
| 1415 | /* This setting used to be a plain bool. If we encounter |
| 1416 | such a setting, take the first sound in the list. */ |
| 1417 | selectSound.selectedIndex = firstSoundIndex; |
| 1418 | }else{ |
| 1419 | selectSound.value = Chat.settings.get('audible-alert','<none>'); |
| 1420 | if(selectSound.selectedIndex<0){ |
| 1421 | /* Missing file - removed after this setting was |
| 1422 | applied. Fall back to the first sound in the list. */ |
| 1423 | selectSound.selectedIndex = firstSoundIndex; |
| 1424 | } |
| @@ -1406,10 +1433,17 @@ | |
| 1433 | F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+"."); |
| 1434 | if(v) setTimeout(()=>Chat.playNewMessageSound(), 0); |
| 1435 | } |
| 1436 | }); |
| 1437 | }/*audio notification config*/ |
| 1438 | settingsOps.push({ |
| 1439 | label: "Play notification for your own messages.", |
| 1440 | hint: "When enabled, the audio notification will be played for all messages, "+ |
| 1441 | "including your own. When disabled only messages from other users "+ |
| 1442 | "will trigger a notification.", |
| 1443 | boolValue: 'alert-own-messages' |
| 1444 | }); |
| 1445 | /** |
| 1446 | Build UI for config options... |
| 1447 | */ |
| 1448 | settingsOps.forEach(function f(op){ |
| 1449 | const line = D.addClass(D.div(), 'menu-entry'); |
| @@ -1601,12 +1635,12 @@ | |
| 1635 | /* A record deletion notice. */ |
| 1636 | Chat.deleteMessageElem(m.mdel); |
| 1637 | return; |
| 1638 | } |
| 1639 | if(!Chat._isBatchLoading |
| 1640 | && (Chat.me!==m.xfrom |
| 1641 | || Chat.settings.getBool('alert-own-messages'))){ |
| 1642 | Chat.playNewMessageSound(); |
| 1643 | } |
| 1644 | const row = new Chat.MessageWidget(m); |
| 1645 | Chat.injectMessageElem(row.e.body,atEnd); |
| 1646 | if(m.isError){ |
| 1647 |