messagegui: factor out common `checkMessages()` calls

master
Rob Pilling 2024-10-23 22:05:21 +01:00
parent 25495f5731
commit f5b3ad2810
1 changed files with 22 additions and 11 deletions

View File

@ -196,7 +196,7 @@ function showMusicMessage(msg) {
msg.new = false; msg.new = false;
layout = undefined; layout = undefined;
if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0}); if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); else returnToMain();
} }
function updateLabels() { function updateLabels() {
trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13); trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13);
@ -304,7 +304,7 @@ function showMessageSettings(msg) {
menu = Object.assign(menu, { menu = Object.assign(menu, {
/*LANG*/"Delete" : () => { /*LANG*/"Delete" : () => {
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id); MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); returnToMain();
}, },
}); });
@ -315,25 +315,25 @@ function showMessageSettings(msg) {
Bangle.messageIgnore(msg); Bangle.messageIgnore(msg);
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id); MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
} }
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); returnToMain();
}); });
}; };
menu = Object.assign(menu, { menu = Object.assign(menu, {
/*LANG*/"Mark Unread" : () => { /*LANG*/"Mark Unread" : () => {
msg.new = true; msg.new = true;
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); returnToMain();
}, },
/*LANG*/"Mark all read" : () => { /*LANG*/"Mark all read" : () => {
MESSAGES.forEach(msg => msg.new = false); MESSAGES.forEach(msg => msg.new = false);
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); returnToMain();
}, },
/*LANG*/"Delete all messages" : () => { /*LANG*/"Delete all messages" : () => {
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => { E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
if (isYes) { if (isYes) {
MESSAGES = []; MESSAGES = [];
} }
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0}); returnToMain();
}); });
}, },
}); });
@ -349,7 +349,7 @@ function showMessage(msgid, persist) {
clearInterval(updateLabelsInterval); clearInterval(updateLabelsInterval);
updateLabelsInterval=undefined; updateLabelsInterval=undefined;
} }
if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic}); // go home if no message found if (!msg) return returnToClockIfEmpty(); // go home if no message found
if (msg.id=="music") { if (msg.id=="music") {
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
return showMusicMessage(msg); return showMusicMessage(msg);
@ -399,7 +399,7 @@ function showMessage(msgid, persist) {
layout = undefined; layout = undefined;
msg.new = false; // read mail msg.new = false; // read mail
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic}); returnToClockIfEmpty();
} }
var negHandler,posHandler,footer = [ ]; var negHandler,posHandler,footer = [ ];
if (msg.negative) { if (msg.negative) {
@ -407,7 +407,7 @@ function showMessage(msgid, persist) {
msg.new = false; msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,false); Bangle.messageResponse(msg,false);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:settings.showMsgIfUnread,openMusic}); returnToCheckMessages();
}; footer.push({type:"img",src:atob("PhAB4A8AAAAAAAPAfAMAAAAAD4PwHAAAAAA/H4DwAAAAAH78B8AAAAAA/+A/AAAAAAH/Af//////w/gP//////8P4D///////H/Af//////z/4D8AAAAAB+/AfAAAAAA/H4DwAAAAAPg/AcAAAAADwHwDAAAAAA4A8AAAAAAAA=="),col:"#f00",cb:negHandler}); }; footer.push({type:"img",src:atob("PhAB4A8AAAAAAAPAfAMAAAAAD4PwHAAAAAA/H4DwAAAAAH78B8AAAAAA/+A/AAAAAAH/Af//////w/gP//////8P4D///////H/Af//////z/4D8AAAAAB+/AfAAAAAA/H4DwAAAAAPg/AcAAAAADwHwDAAAAAA4A8AAAAAAAA=="),col:"#f00",cb:negHandler});
} }
footer.push({fillx:1}); // push images to left/right footer.push({fillx:1}); // push images to left/right
@ -421,7 +421,7 @@ function showMessage(msgid, persist) {
Bluetooth.println(JSON.stringify(result)); Bluetooth.println(JSON.stringify(result));
replying = false; replying = false;
layout.render(); layout.render();
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:settings.showMsgIfUnread,openMusic}); returnToCheckMessages();
}) })
.catch(() => { .catch(() => {
replying = false; replying = false;
@ -435,7 +435,7 @@ function showMessage(msgid, persist) {
msg.new = false; msg.new = false;
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,true); Bangle.messageResponse(msg,true);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:settings.showMsgIfUnread,openMusic}); returnToCheckMessages();
}; footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler}); }; footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler});
} }
@ -570,6 +570,17 @@ function checkMessages(options) {
}); });
} }
function returnToCheckMessages(clock) {
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:settings.showMsgIfUnread,openMusic});
}
function returnToMain() {
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}
function returnToClockIfEmpty() {
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic});
}
function cancelReloadTimeout() { function cancelReloadTimeout() {
if (!unreadTimeout) return; if (!unreadTimeout) return;