guarantee more space for alerts
This commit is contained in:
parent
c7c3dcead2
commit
30b68945b4
|
@ -56,7 +56,7 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const AlertsGrowHint = len(`{"msgs":[],"count":,"tc":}`) + 1 + 7
|
const AlertsGrowHint = len(`{"msgs":[],"count":,"tc":}`) + 1 + 10
|
||||||
|
|
||||||
// TODO: See if we can json.Marshal instead?
|
// TODO: See if we can json.Marshal instead?
|
||||||
func escapeTextInJson(in string) string {
|
func escapeTextInJson(in string) string {
|
||||||
|
@ -167,7 +167,7 @@ func buildAlertString(msg string, sub []string, path, avatar string, asid int) s
|
||||||
return sb.String()
|
return sb.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
const AlertsGrowHint2 = len(`{"msg":"","sub":[],"path":"","avatar":"","id":}`) + 3 + 3 + 1 + 1 + 1
|
const AlertsGrowHint2 = len(`{"msg":"","sub":[],"path":"","avatar":"","id":}`) + 5 + 3 + 1 + 1 + 1
|
||||||
|
|
||||||
// TODO: Use a string builder?
|
// TODO: Use a string builder?
|
||||||
func buildAlertSb(sb *strings.Builder, msg string, sub []string, path, avatar string, asid int) {
|
func buildAlertSb(sb *strings.Builder, msg string, sub []string, path, avatar string, asid int) {
|
||||||
|
|
|
@ -236,7 +236,7 @@ function runWebSockets(resume = false) {
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if(!noAlerts) {
|
if(!noAlerts) {
|
||||||
var alertMenuList = document.getElementsByClassName("menu_alerts");
|
let alertMenuList = document.getElementsByClassName("menu_alerts");
|
||||||
for(var i=0; i < alertMenuList.length; i++) loadAlerts(alertMenuList[i]);
|
for(var i=0; i < alertMenuList.length; i++) loadAlerts(alertMenuList[i]);
|
||||||
}
|
}
|
||||||
runWebSockets(true);
|
runWebSockets(true);
|
||||||
|
@ -282,14 +282,14 @@ function runWebSockets(resume = false) {
|
||||||
delete alertMapping[key];
|
delete alertMapping[key];
|
||||||
|
|
||||||
// TODO: Add support for other alert feeds like PM Alerts
|
// TODO: Add support for other alert feeds like PM Alerts
|
||||||
var generalAlerts = document.getElementById("general_alerts");
|
let generalAlerts = document.getElementById("general_alerts");
|
||||||
if(alertList.length < 8) loadAlerts(generalAlerts);
|
if(alertList.length < 8) loadAlerts(generalAlerts);
|
||||||
else updateAlertList(generalAlerts);
|
else updateAlertList(generalAlerts);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if("Topics" in data) {
|
} else if("Topics" in data) {
|
||||||
console.log("topic in data");
|
console.log("topic in data");
|
||||||
console.log("data", data);
|
console.log("data",data);
|
||||||
let topic = data.Topics[0];
|
let topic = data.Topics[0];
|
||||||
if(topic === undefined){
|
if(topic === undefined){
|
||||||
console.log("empty topic list");
|
console.log("empty topic list");
|
||||||
|
@ -321,10 +321,10 @@ function runWebSockets(resume = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var messages = event.data.split('\r');
|
let messages = event.data.split('\r');
|
||||||
for(var i=0; i < messages.length; i++) {
|
for(var i=0; i < messages.length; i++) {
|
||||||
let message = messages[i];
|
let message = messages[i];
|
||||||
//console.log("Message: ",message);
|
//console.log("message",message);
|
||||||
let msgblocks = SplitN(message," ",3);
|
let msgblocks = SplitN(message," ",3);
|
||||||
if(msgblocks.length < 3) continue;
|
if(msgblocks.length < 3) continue;
|
||||||
if(message.startsWith("set ")) {
|
if(message.startsWith("set ")) {
|
||||||
|
@ -348,7 +348,7 @@ function runWebSockets(resume = false) {
|
||||||
// We can only get away with this because template_alert has no phrases, otherwise it too would have to be part of the "dance", I miss Go concurrency :(
|
// We can only get away with this because template_alert has no phrases, otherwise it too would have to be part of the "dance", I miss Go concurrency :(
|
||||||
if(!noAlerts) {
|
if(!noAlerts) {
|
||||||
notifyOnScriptW("template_alert", e => {
|
notifyOnScriptW("template_alert", e => {
|
||||||
if(e!=undefined) console.log("failed alert? why?", e)
|
if(e!=undefined) console.log("failed alert? why?",e)
|
||||||
}, () => {
|
}, () => {
|
||||||
if(!Template_alert) throw("template function not found");
|
if(!Template_alert) throw("template function not found");
|
||||||
addInitHook("after_phrases", () => {
|
addInitHook("after_phrases", () => {
|
||||||
|
|
|
@ -175,7 +175,7 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user c.User) c.RouteError
|
||||||
|
|
||||||
var ok bool
|
var ok bool
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
sb.Grow(c.AlertsGrowHint + (len(alerts) * c.AlertsGrowHint2))
|
sb.Grow(c.AlertsGrowHint + (len(alerts) * (c.AlertsGrowHint2 + 1)) - 1)
|
||||||
sb.WriteString(`{"msgs":[`)
|
sb.WriteString(`{"msgs":[`)
|
||||||
for i, alert := range alerts {
|
for i, alert := range alerts {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
|
|
Loading…
Reference in New Issue