Fossil SCM

Add the /Admin/Chat page. Add settings to configure the initial history load size of /chat, and to configure purging of historical messages.

drh 2020-12-23 20:58 trunk
Commit 15bc20f29db30502a3ddf5a34f3f5e9f04fa932f409c0c5f362b68a7c430594a
+30 -1
--- src/chat.c
+++ src/chat.c
@@ -40,10 +40,38 @@
4040
*/
4141
#include "config.h"
4242
#include <assert.h>
4343
#include "chat.h"
4444
45
+/* Settings that can be used to control chat */
46
+/*
47
+** SETTING: chat-initial-history width=10 default=50
48
+**
49
+** If this setting has an integer value of N, then when /chat first
50
+** starts up it initializes the screen with the N most recent chat
51
+** messages. If N is zero, then all chat messages are loaded.
52
+*/
53
+/*
54
+** SETTING: chat-keep-count width=10 default=50
55
+**
56
+** When /chat is cleaning up older messages, it will always keep
57
+** the most recent chat-keep-count messages, even if some of those
58
+** messages are older than the discard threshold. If this value
59
+** is zero, then /chat is free to delete all historic messages once
60
+** they are old enough.
61
+*/
62
+/*
63
+** SETTING: chat-keep-days width=10 default=7
64
+**
65
+** The /chat subsystem will try to discard messages that are older then
66
+** chat-keep-days. The value of chat-keep-days can be a floating point
67
+** number. So, for example, if you only want to keep chat messages for
68
+** 12 hours, set this value to 0.5.
69
+**
70
+** A value of 0.0 or less means that messages are retained forever.
71
+*/
72
+
4573
/*
4674
** WEBPAGE: chat
4775
**
4876
** Start up a browser-based chat session.
4977
*/
@@ -91,11 +119,11 @@
91119
@ align-self: flex-start;
92120
@ margin-right: 0.5em;
93121
@ flex: 0 1 auto;
94122
@ }
95123
@ #chat-input-file {
96
- @ border: 1px solid rgba(0,0,0,0);/*to avoid UI shift during drop-targeting*/
124
+ @ border:1px solid rgba(0,0,0,0);/*avoid UI shift during drop-targeting*/
97125
@ border-radius: 0.25em;
98126
@ }
99127
@ #chat-input-file > input {
100128
@ flex: 1 0 auto;
101129
@ }
@@ -137,10 +165,11 @@
137165
@ <span id='message-inject-point'></span>
138166
139167
builtin_fossil_js_bundle_or("popupwidget", NULL);
140168
/* Always in-line the javascript for the chat page */
141169
@ <script nonce="%h(style_nonce())">/* chat.c:%d(__LINE__) */
170
+ @ window.fossilChatInitSize = %d(db_get_int("chat-initial-history",50));
142171
@ window.addEventListener('load', function(){
143172
/* We need an onload handler to ensure that window.fossil is
144173
loaded first. */
145174
cgi_append_content(builtin_text("chat.js"),-1);
146175
@ }, false);
147176
--- src/chat.c
+++ src/chat.c
@@ -40,10 +40,38 @@
40 */
41 #include "config.h"
42 #include <assert.h>
43 #include "chat.h"
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45 /*
46 ** WEBPAGE: chat
47 **
48 ** Start up a browser-based chat session.
49 */
@@ -91,11 +119,11 @@
91 @ align-self: flex-start;
92 @ margin-right: 0.5em;
93 @ flex: 0 1 auto;
94 @ }
95 @ #chat-input-file {
96 @ border: 1px solid rgba(0,0,0,0);/*to avoid UI shift during drop-targeting*/
97 @ border-radius: 0.25em;
98 @ }
99 @ #chat-input-file > input {
100 @ flex: 1 0 auto;
101 @ }
@@ -137,10 +165,11 @@
137 @ <span id='message-inject-point'></span>
138
139 builtin_fossil_js_bundle_or("popupwidget", NULL);
140 /* Always in-line the javascript for the chat page */
141 @ <script nonce="%h(style_nonce())">/* chat.c:%d(__LINE__) */
 
142 @ window.addEventListener('load', function(){
143 /* We need an onload handler to ensure that window.fossil is
144 loaded first. */
145 cgi_append_content(builtin_text("chat.js"),-1);
146 @ }, false);
147
--- src/chat.c
+++ src/chat.c
@@ -40,10 +40,38 @@
40 */
41 #include "config.h"
42 #include <assert.h>
43 #include "chat.h"
44
45 /* Settings that can be used to control chat */
46 /*
47 ** SETTING: chat-initial-history width=10 default=50
48 **
49 ** If this setting has an integer value of N, then when /chat first
50 ** starts up it initializes the screen with the N most recent chat
51 ** messages. If N is zero, then all chat messages are loaded.
52 */
53 /*
54 ** SETTING: chat-keep-count width=10 default=50
55 **
56 ** When /chat is cleaning up older messages, it will always keep
57 ** the most recent chat-keep-count messages, even if some of those
58 ** messages are older than the discard threshold. If this value
59 ** is zero, then /chat is free to delete all historic messages once
60 ** they are old enough.
61 */
62 /*
63 ** SETTING: chat-keep-days width=10 default=7
64 **
65 ** The /chat subsystem will try to discard messages that are older then
66 ** chat-keep-days. The value of chat-keep-days can be a floating point
67 ** number. So, for example, if you only want to keep chat messages for
68 ** 12 hours, set this value to 0.5.
69 **
70 ** A value of 0.0 or less means that messages are retained forever.
71 */
72
73 /*
74 ** WEBPAGE: chat
75 **
76 ** Start up a browser-based chat session.
77 */
@@ -91,11 +119,11 @@
119 @ align-self: flex-start;
120 @ margin-right: 0.5em;
121 @ flex: 0 1 auto;
122 @ }
123 @ #chat-input-file {
124 @ border:1px solid rgba(0,0,0,0);/*avoid UI shift during drop-targeting*/
125 @ border-radius: 0.25em;
126 @ }
127 @ #chat-input-file > input {
128 @ flex: 1 0 auto;
129 @ }
@@ -137,10 +165,11 @@
165 @ <span id='message-inject-point'></span>
166
167 builtin_fossil_js_bundle_or("popupwidget", NULL);
168 /* Always in-line the javascript for the chat page */
169 @ <script nonce="%h(style_nonce())">/* chat.c:%d(__LINE__) */
170 @ window.fossilChatInitSize = %d(db_get_int("chat-initial-history",50));
171 @ window.addEventListener('load', function(){
172 /* We need an onload handler to ensure that window.fossil is
173 loaded first. */
174 cgi_append_content(builtin_text("chat.js"),-1);
175 @ }, false);
176
--- src/chat.js
+++ src/chat.js
@@ -1,8 +1,9 @@
11
(function(){
22
const form = document.querySelector('#chat-form');
33
let mxMsg = -50;
4
+ if( window.fossilChatInitSize ) mxMsg = -window.fossilChatInitSize;
45
const F = window.fossil, D = F.dom;
56
const _me = F.user.name;
67
/* State for paste and drag/drop */
78
const BlobXferState = {
89
dropDetails: document.querySelector('#chat-drop-details'),
910
--- src/chat.js
+++ src/chat.js
@@ -1,8 +1,9 @@
1 (function(){
2 const form = document.querySelector('#chat-form');
3 let mxMsg = -50;
 
4 const F = window.fossil, D = F.dom;
5 const _me = F.user.name;
6 /* State for paste and drag/drop */
7 const BlobXferState = {
8 dropDetails: document.querySelector('#chat-drop-details'),
9
--- src/chat.js
+++ src/chat.js
@@ -1,8 +1,9 @@
1 (function(){
2 const form = document.querySelector('#chat-form');
3 let mxMsg = -50;
4 if( window.fossilChatInitSize ) mxMsg = -window.fossilChatInitSize;
5 const F = window.fossil, D = F.dom;
6 const _me = F.user.name;
7 /* State for paste and drag/drop */
8 const BlobXferState = {
9 dropDetails: document.querySelector('#chat-drop-details'),
10
+47
--- src/setup.c
+++ src/setup.c
@@ -124,10 +124,12 @@
124124
" on the same server");
125125
setup_menu_entry("Tickets", "tktsetup",
126126
"Configure the trouble-ticketing system for this repository");
127127
setup_menu_entry("Wiki", "setup_wiki",
128128
"Configure the wiki for this repository");
129
+ setup_menu_entry("Chat", "setup_chat",
130
+ "Configure the chatroom");
129131
}
130132
setup_menu_entry("Search","srchsetup",
131133
"Configure the built-in search engine");
132134
setup_menu_entry("URL Aliases", "waliassetup",
133135
"Configure URL aliases");
@@ -1111,10 +1113,55 @@
11111113
@ users to inject dangerous HTML, CSS and JavaScript code into your wiki.</p>
11121114
@ <p>This should <strong>only</strong> be enabled when wiki editing is limited
11131115
@ to trusted users. It should <strong>not</strong> be used on a publicly
11141116
@ editable wiki.</p>
11151117
@ (Property: "wiki-use-html")
1118
+ @ <hr />
1119
+ @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1120
+ @ </div></form>
1121
+ db_end_transaction(0);
1122
+ style_finish_page();
1123
+}
1124
+
1125
+/*
1126
+** WEBPAGE: setup_chat
1127
+**
1128
+** The "Admin/Chat" page. Requires Setup privilege.
1129
+*/
1130
+void setup_chat(void){
1131
+ login_check_credentials();
1132
+ if( !g.perm.Setup ){
1133
+ login_needed(0);
1134
+ return;
1135
+ }
1136
+
1137
+ style_set_current_feature("setup");
1138
+ style_header("Chat Configuration");
1139
+ db_begin_transaction();
1140
+ @ <form action="%R/setup_chat" method="post"><div>
1141
+ login_insert_csrf_secret();
1142
+ @ <input type="submit" name="submit" value="Apply Changes" /></p>
1143
+ @ <hr />
1144
+ entry_attribute("Initial Chat History Size", 10,
1145
+ "chat-initial-history", "chatih", "50", 0);
1146
+ @ <p>When /chat first starts up, it preloads up to this many historical
1147
+ @ messages.
1148
+ @ (Property: "chat-initial-history")</p>
1149
+ @ <hr />
1150
+ entry_attribute("Minimum Number Of Historical Messages To Retain", 10,
1151
+ "chat-keep-count", "chatkc", "50", 0);
1152
+ @ <p>The chat subsystem purges older messages. But it will always retain
1153
+ @ the N most recent messages where N is the value of this setting.
1154
+ @ (Property: "chat-keep-count")</p>
1155
+ @ <hr />
1156
+ entry_attribute("Maximum Message Age In Days", 10,
1157
+ "chat-keep-days", "chatkd", "7", 0);
1158
+ @ <p>Chat message are removed after N days, where N is the value of
1159
+ @ this setting. N may be fractional. So, for example, to only keep
1160
+ @ an historical record of chat messages for 12 hours, set this value
1161
+ @ to 0.5.
1162
+ @ (Property: "chat-keep-days")</p>
11161163
@ <hr />
11171164
@ <p><input type="submit" name="submit" value="Apply Changes" /></p>
11181165
@ </div></form>
11191166
db_end_transaction(0);
11201167
style_finish_page();
11211168
--- src/setup.c
+++ src/setup.c
@@ -124,10 +124,12 @@
124 " on the same server");
125 setup_menu_entry("Tickets", "tktsetup",
126 "Configure the trouble-ticketing system for this repository");
127 setup_menu_entry("Wiki", "setup_wiki",
128 "Configure the wiki for this repository");
 
 
129 }
130 setup_menu_entry("Search","srchsetup",
131 "Configure the built-in search engine");
132 setup_menu_entry("URL Aliases", "waliassetup",
133 "Configure URL aliases");
@@ -1111,10 +1113,55 @@
1111 @ users to inject dangerous HTML, CSS and JavaScript code into your wiki.</p>
1112 @ <p>This should <strong>only</strong> be enabled when wiki editing is limited
1113 @ to trusted users. It should <strong>not</strong> be used on a publicly
1114 @ editable wiki.</p>
1115 @ (Property: "wiki-use-html")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1116 @ <hr />
1117 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1118 @ </div></form>
1119 db_end_transaction(0);
1120 style_finish_page();
1121
--- src/setup.c
+++ src/setup.c
@@ -124,10 +124,12 @@
124 " on the same server");
125 setup_menu_entry("Tickets", "tktsetup",
126 "Configure the trouble-ticketing system for this repository");
127 setup_menu_entry("Wiki", "setup_wiki",
128 "Configure the wiki for this repository");
129 setup_menu_entry("Chat", "setup_chat",
130 "Configure the chatroom");
131 }
132 setup_menu_entry("Search","srchsetup",
133 "Configure the built-in search engine");
134 setup_menu_entry("URL Aliases", "waliassetup",
135 "Configure URL aliases");
@@ -1111,10 +1113,55 @@
1113 @ users to inject dangerous HTML, CSS and JavaScript code into your wiki.</p>
1114 @ <p>This should <strong>only</strong> be enabled when wiki editing is limited
1115 @ to trusted users. It should <strong>not</strong> be used on a publicly
1116 @ editable wiki.</p>
1117 @ (Property: "wiki-use-html")
1118 @ <hr />
1119 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1120 @ </div></form>
1121 db_end_transaction(0);
1122 style_finish_page();
1123 }
1124
1125 /*
1126 ** WEBPAGE: setup_chat
1127 **
1128 ** The "Admin/Chat" page. Requires Setup privilege.
1129 */
1130 void setup_chat(void){
1131 login_check_credentials();
1132 if( !g.perm.Setup ){
1133 login_needed(0);
1134 return;
1135 }
1136
1137 style_set_current_feature("setup");
1138 style_header("Chat Configuration");
1139 db_begin_transaction();
1140 @ <form action="%R/setup_chat" method="post"><div>
1141 login_insert_csrf_secret();
1142 @ <input type="submit" name="submit" value="Apply Changes" /></p>
1143 @ <hr />
1144 entry_attribute("Initial Chat History Size", 10,
1145 "chat-initial-history", "chatih", "50", 0);
1146 @ <p>When /chat first starts up, it preloads up to this many historical
1147 @ messages.
1148 @ (Property: "chat-initial-history")</p>
1149 @ <hr />
1150 entry_attribute("Minimum Number Of Historical Messages To Retain", 10,
1151 "chat-keep-count", "chatkc", "50", 0);
1152 @ <p>The chat subsystem purges older messages. But it will always retain
1153 @ the N most recent messages where N is the value of this setting.
1154 @ (Property: "chat-keep-count")</p>
1155 @ <hr />
1156 entry_attribute("Maximum Message Age In Days", 10,
1157 "chat-keep-days", "chatkd", "7", 0);
1158 @ <p>Chat message are removed after N days, where N is the value of
1159 @ this setting. N may be fractional. So, for example, to only keep
1160 @ an historical record of chat messages for 12 hours, set this value
1161 @ to 0.5.
1162 @ (Property: "chat-keep-days")</p>
1163 @ <hr />
1164 @ <p><input type="submit" name="submit" value="Apply Changes" /></p>
1165 @ </div></form>
1166 db_end_transaction(0);
1167 style_finish_page();
1168

Keyboard Shortcuts

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