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.

stephan 2021-10-02 04:57 chat-input-rework
Commit 8534eb75e17db41bdb4a6030801fd4077066b3da1b1edc2a3e4c9ab8a926a10b
1 file changed +39 -5
--- src/fossil.page.chat.js
+++ src/fossil.page.chat.js
@@ -374,19 +374,46 @@
374374
addListener: function(setting, f){
375375
F.page.addEventListener('chat-setting', function(ev){
376376
if(ev.detail.key===setting) f(ev.detail);
377377
}, false);
378378
},
379
+ /* Default values of settings. These are used for intializing
380
+ the setting event listeners and config view UI. */
379381
defaults:{
382
+ /* When on, inbound images are displayed inlined, else as a
383
+ link to download the image. */
380384
"images-inline": !!F.config.chat.imagesInline,
385
+ /* When on, ctrl-enter sends messages, else enter and
386
+ ctrl-enter both send them. */
381387
"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. */
382392
"edit-compact-mode": true,
393
+ /* When on, sets the font-family on messages and the edit
394
+ field to monospace. */
383395
"monospace-messages": true,
396
+ /* When on, non-chat UI elements (page header/footer) are
397
+ hidden */
384398
"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. */
385403
"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). */
386407
"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
388415
}
389416
},
390417
/** Plays a new-message notification sound IF the audible-alert
391418
setting is true, else this is a no-op. Returns this.
392419
*/
@@ -395,11 +422,11 @@
395422
try{
396423
if(!f.audio) f.audio = new Audio(f.uri);
397424
f.audio.currentTime = 0;
398425
f.audio.play();
399426
}catch(e){
400
- console.error("Audio playblack failed.",e);
427
+ console.error("Audio playblack failed.", f.uri, e);
401428
}
402429
}
403430
return this;
404431
},
405432
/**
@@ -1387,11 +1414,11 @@
13871414
if(true===Chat.settings.getBool('audible-alert')){
13881415
/* This setting used to be a plain bool. If we encounter
13891416
such a setting, take the first sound in the list. */
13901417
selectSound.selectedIndex = firstSoundIndex;
13911418
}else{
1392
- selectSound.value = Chat.settings.get('audible-alert','');
1419
+ selectSound.value = Chat.settings.get('audible-alert','<none>');
13931420
if(selectSound.selectedIndex<0){
13941421
/* Missing file - removed after this setting was
13951422
applied. Fall back to the first sound in the list. */
13961423
selectSound.selectedIndex = firstSoundIndex;
13971424
}
@@ -1406,10 +1433,17 @@
14061433
F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+".");
14071434
if(v) setTimeout(()=>Chat.playNewMessageSound(), 0);
14081435
}
14091436
});
14101437
}/*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
+ });
14111445
/**
14121446
Build UI for config options...
14131447
*/
14141448
settingsOps.forEach(function f(op){
14151449
const line = D.addClass(D.div(), 'menu-entry');
@@ -1601,12 +1635,12 @@
16011635
/* A record deletion notice. */
16021636
Chat.deleteMessageElem(m.mdel);
16031637
return;
16041638
}
16051639
if(!Chat._isBatchLoading
1606
- && Chat.me!==m.xfrom
1607
- && Chat.playNewMessageSound){
1640
+ && (Chat.me!==m.xfrom
1641
+ || Chat.settings.getBool('alert-own-messages'))){
16081642
Chat.playNewMessageSound();
16091643
}
16101644
const row = new Chat.MessageWidget(m);
16111645
Chat.injectMessageElem(row.e.body,atEnd);
16121646
if(m.isError){
16131647
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button