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,7 +282,7 @@ 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);
|
||||||
});
|
});
|
||||||
|
@ -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 ")) {
|
||||||
|
|
|
@ -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