rename avatar to img to save a few bytes in alerts

This commit is contained in:
Azareal 2020-03-12 13:29:19 +10:00
parent 61688a0c6d
commit 17c8f7604a
2 changed files with 10 additions and 10 deletions

View File

@ -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":}`) + 5 + 3 + 1 + 1 + 1
const AlertsGrowHint2 = len(`{"msg":"","sub":[],"path":"","img":"","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) {
@ -185,7 +185,7 @@ func buildAlertSb(sb *strings.Builder, msg string, sub []string, path, avatar st
}
sb.WriteString(`],"path":"`)
sb.WriteString(escapeTextInJson(path))
sb.WriteString(`","avatar":"`)
sb.WriteString(`","img":"`)
sb.WriteString(escapeTextInJson(avatar))
sb.WriteString(`","id":`)
sb.WriteString(strconv.Itoa(asid))
@ -289,7 +289,7 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user *
sb.WriteString(escapeTextInJson(area))
sb.WriteString(`"],"path":"`)
sb.WriteString(escapeTextInJson(url))
sb.WriteString(`","avatar":"`)
sb.WriteString(`","img":"`)
sb.WriteString(escapeTextInJson(a.Actor.Avatar))
sb.WriteString(`","id":`)
sb.WriteString(strconv.Itoa(a.ASID))
@ -298,7 +298,7 @@ func BuildAlertSb(sb *strings.Builder, a *Alert, user User /* The current user *
return nil
}
//var AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","avatar":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1
//var AlertsGrowHint3 = len(`{"msg":"._","sub":["",""],"path":"","img":"","id":}`) + 3 + 2 + 2 + 2 + 2 + 1
func AddActivityAndNotifyAll(a Alert) error {
id, err := Activity.Add(a)

View File

@ -58,7 +58,7 @@ function bindToAlerts() {
});
}
function addAlert(msg, notice = false) {
function addAlert(msg, notice=false) {
var mmsg = msg.msg;
if(mmsg[0]==".") mmsg = phraseBox["alerts"]["alerts"+mmsg];
if("sub" in msg) {
@ -68,7 +68,7 @@ function addAlert(msg, notice = false) {
let aItem = Template_alert({
ASID: msg.id,
Path: msg.path,
Avatar: msg.avatar || "",
Avatar: msg.img || "",
Message: mmsg
})
//alertMapping[msg.id] = aItem;
@ -83,7 +83,7 @@ function addAlert(msg, notice = false) {
if(Notification.permission === "granted") {
var n = new Notification("Something Happened",{
body: mmsg,
icon: msg.avatar,
icon: msg.img,
});
setTimeout(n.close.bind(n), 8000);
}
@ -130,7 +130,7 @@ function setAlertError(menuAlerts,msg) {
var alertsInitted = false;
var lastTc = 0;
function loadAlerts(menuAlerts, eTc = false) {
function loadAlerts(menuAlerts, eTc=false) {
if(!alertsInitted) return;
let tc = "";
if(eTc && lastTc != 0) tc = "&t=" + lastTc + "&c=" + alertCount;
@ -138,7 +138,7 @@ function loadAlerts(menuAlerts, eTc = false) {
type:'get',
dataType:'json',
url:'/api/?m=alerts' + tc,
success: (data) => {
success: data => {
if("errmsg" in data) {
setAlertError(menuAlerts,data.errmsg)
return;
@ -207,7 +207,7 @@ function wsAlertEvent(data) {
updateAlertList(generalAlerts/*, alist*/);
}
function runWebSockets(resume = false) {
function runWebSockets(resume=false) {
let s = "";
if(window.location.protocol == "https:") s = "s";
conn = new WebSocket("ws"+s+"://" + document.location.host + "/ws/");