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?
|
||||
func escapeTextInJson(in string) string {
|
||||
|
@ -167,7 +167,7 @@ func buildAlertString(msg string, sub []string, path, avatar string, asid int) s
|
|||
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?
|
||||
func buildAlertSb(sb *strings.Builder, msg string, sub []string, path, avatar string, asid int) {
|
||||
|
|
|
@ -236,7 +236,7 @@ function runWebSockets(resume = false) {
|
|||
|
||||
setTimeout(() => {
|
||||
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]);
|
||||
}
|
||||
runWebSockets(true);
|
||||
|
@ -282,7 +282,7 @@ function runWebSockets(resume = false) {
|
|||
delete alertMapping[key];
|
||||
|
||||
// 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);
|
||||
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++) {
|
||||
let message = messages[i];
|
||||
//console.log("Message: ",message);
|
||||
//console.log("message",message);
|
||||
let msgblocks = SplitN(message," ",3);
|
||||
if(msgblocks.length < 3) continue;
|
||||
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 sb strings.Builder
|
||||
sb.Grow(c.AlertsGrowHint + (len(alerts) * c.AlertsGrowHint2))
|
||||
sb.Grow(c.AlertsGrowHint + (len(alerts) * (c.AlertsGrowHint2 + 1)) - 1)
|
||||
sb.WriteString(`{"msgs":[`)
|
||||
for i, alert := range alerts {
|
||||
if i != 0 {
|
||||
|
|
Loading…
Reference in New Issue