fix removing messages not working

master
Bryan 2024-08-02 19:16:02 -06:00
parent dc6777b989
commit 4976ce0df3
1 changed files with 23 additions and 20 deletions

View File

@ -36,6 +36,7 @@ let timeouts = {};
let cleanup = function() {}; // we don't want cleanup function to do anything until we actually need it let cleanup = function() {}; // we don't want cleanup function to do anything until we actually need it
const goBack = function(timedOut) { const goBack = function(timedOut) {
console.log("previousActive = ", previousActive);
switch (previousActive) { switch (previousActive) {
case "alarm": return showAlarm(); case "alarm": return showAlarm();
case "call": return showCall(); case "call": return showCall();
@ -44,6 +45,8 @@ const goBack = function(timedOut) {
case "music": return showMusic(); case "music": return showMusic();
default: default:
if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;}); if (!timedOut) Bangle.MESSAGES.forEach((m) => {if (!m.new) m.show = false;});
console.log("write messages");
console.log("Bangle.MESSAGES", Bangle.MESSAGES);
require("messages").write(Bangle.MESSAGES); require("messages").write(Bangle.MESSAGES);
cleanup = _cleanup; cleanup = _cleanup;
Bangle.showClock(); Bangle.showClock();
@ -52,7 +55,7 @@ const goBack = function(timedOut) {
const setListener = function(event, callback) { const setListener = function(event, callback) {
if (!event || !callback) return; if (!event || !callback) return;
console.log("setListener"); // console.log("setListener");
events[event] = callback; events[event] = callback;
Bangle.on(event, callback); Bangle.on(event, callback);
}; };
@ -112,7 +115,7 @@ events.saveMessages = function() {
E.on("kill", events.saveMessages); E.on("kill", events.saveMessages);
const newMessage = (type, msg) => { const newMessage = (type, msg) => {
console.log("new message"); // console.log("new message");
if (type === "text" && active === "message") { if (type === "text" && active === "message") {
require("messages").apply(msg, Bangle.MESSAGES); require("messages").apply(msg, Bangle.MESSAGES);
if (idle) showText(Bangle.MESSAGES); // we are idle so show new messages right away if (idle) showText(Bangle.MESSAGES); // we are idle so show new messages right away
@ -124,15 +127,15 @@ setListener("message", newMessage);
// Check for new messages, wait until there is no interaction for `idleTime` ms // Check for new messages, wait until there is no interaction for `idleTime` ms
const checkForNewMessages = function(idleTime) { const checkForNewMessages = function(idleTime) {
console.log("checkForNewMessages"); // console.log("checkForNewMessages");
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle
console.log("idleTime = ", idleTime); // console.log("idleTime = ", idleTime);
idle = false; idle = false;
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer); if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer);
timeouts.idleTimer = setTimeout(() => { timeouts.idleTimer = setTimeout(() => {
console.log("update messages"); // console.log("update messages");
if (haveNewMessage) { if (haveNewMessage) {
console.log("call showText()"); // console.log("call showText()");
haveNewMessage = false; haveNewMessage = false;
showText(Bangle.MESSAGES); showText(Bangle.MESSAGES);
} }
@ -165,7 +168,7 @@ const showText = function(showAll) {
// TODO we might have to append array of (m.show && !m.new) to array of m.new so that all new messages are at the beginning of list // TODO we might have to append array of (m.show && !m.new) to array of m.new so that all new messages are at the beginning of list
let messageList = showAll ? Bangle.MESSAGES : Bangle.MESSAGES.filter(m => m.new || m.show); let messageList = showAll ? Bangle.MESSAGES : Bangle.MESSAGES.filter(m => m.new || m.show);
if (!messageList.length) { if (!messageList.length) {
console.log("No messages") // console.log("No messages")
return; return;
} }
// Bangle.setLocked(false); // TODO make as option // Bangle.setLocked(false); // TODO make as option
@ -223,14 +226,14 @@ const showText = function(showAll) {
const removeMessage = function() { const removeMessage = function() {
const removeAndReset = () => { const removeAndReset = () => {
let id = msgBoxes[messageNum].id; let id = msgBoxes[messageNum].msg.id;
Bangle.MESSAGES.filter(m => m.id !== id); Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id !== id); // remove from Bangle.MESSAGES
msgBoxes.splice(messageNum, 1); // remove from msgBoxes msgBoxes.splice(messageNum, 1); // remove from msgBoxes
if (!msgBoxes.length) { if (!msgBoxes.length) {
Bangle.setUI(); Bangle.setUI();
return goBack(); // no more messages return goBack(); // no more messages
} }
if (messageNum == msgBoxes.length) messageNum--; // we removed the last message, go to previous message if (messageNum === msgBoxes.length) messageNum--; // we removed the last message, go to previous message
// otherwise messageNum is automatically the index of the next message now // otherwise messageNum is automatically the index of the next message now
refresh(); refresh();
msgBoxes[messageNum].draw(); msgBoxes[messageNum].draw();
@ -388,8 +391,8 @@ const showText = function(showAll) {
if (e.b === 0) { if (e.b === 0) {
firstTouch = true; firstTouch = true;
} }
console.log("top of handler: first touch = ", firstTouch); // console.log("top of handler: first touch = ", firstTouch);
// console.log("top of handler: e = ", e); // // console.log("top of handler: e = ", e);
if (switching) return; // don't respond to touch while we are animating if (switching) return; // don't respond to touch while we are animating
if (firstTouch && e.b === 1) { if (firstTouch && e.b === 1) {
if (buzzing) { if (buzzing) {
@ -400,12 +403,12 @@ const showText = function(showAll) {
let idx = Bangle.MESSAGES.findIndex(m => m.id === msgBoxes[messageNum].msg.id); // TODO maybe we don't to do this check every time let idx = Bangle.MESSAGES.findIndex(m => m.id === msgBoxes[messageNum].msg.id); // TODO maybe we don't to do this check every time
if (idx >= 0) delete Bangle.MESSAGES[idx].new; if (idx >= 0) delete Bangle.MESSAGES[idx].new;
msgBoxes[messageNum].clearNew(); msgBoxes[messageNum].clearNew();
console.log("do tests"); // console.log("do tests");
console.log("dy, dx", e.dy, e.dx); // console.log("dy, dx", e.dy, e.dx);
console.log("e", e); // console.log("e", e);
if (Math.abs(e.dy) > Math.abs(e.dx)) { if (Math.abs(e.dy) > Math.abs(e.dx)) {
firstTouch = false; firstTouch = false;
console.log("up down"); // console.log("up down");
if (e.dy > 0 && msgBoxes[messageNum].top) { if (e.dy > 0 && msgBoxes[messageNum].top) {
mode = "prev"; mode = "prev";
} else if (msgBoxes[messageNum].bottom) { // e.dy will be < 0 here } else if (msgBoxes[messageNum].bottom) { // e.dy will be < 0 here
@ -415,7 +418,7 @@ const showText = function(showAll) {
} }
} else if (Math.abs(e.dx) > Math.abs(e.dy)) { } else if (Math.abs(e.dx) > Math.abs(e.dy)) {
firstTouch = false; firstTouch = false;
console.log("left right"); // console.log("left right");
if (e.dx < 0) { if (e.dx < 0) {
mode = "left"; mode = "left";
} else { } else {
@ -434,10 +437,10 @@ const showText = function(showAll) {
}; };
const nextHandler = function(e) { const nextHandler = function(e) {
console.log("nextHandler"); // console.log("nextHandler");
console.log(e); // console.log(e);
if (e.b == 0) { if (e.b == 0) {
console.log("firstTouch = ", firstTouch); // console.log("firstTouch = ", firstTouch);
checkForNewMessages(); checkForNewMessages();
// firstTouch = true; // firstTouch = true;
} }