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
const goBack = function(timedOut) {
console.log("previousActive = ", previousActive);
switch (previousActive) {
case "alarm": return showAlarm();
case "call": return showCall();
@ -44,6 +45,8 @@ const goBack = function(timedOut) {
case "music": return showMusic();
default:
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);
cleanup = _cleanup;
Bangle.showClock();
@ -52,7 +55,7 @@ const goBack = function(timedOut) {
const setListener = function(event, callback) {
if (!event || !callback) return;
console.log("setListener");
// console.log("setListener");
events[event] = callback;
Bangle.on(event, callback);
};
@ -112,7 +115,7 @@ events.saveMessages = function() {
E.on("kill", events.saveMessages);
const newMessage = (type, msg) => {
console.log("new message");
// console.log("new message");
if (type === "text" && active === "message") {
require("messages").apply(msg, Bangle.MESSAGES);
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
const checkForNewMessages = function(idleTime) {
console.log("checkForNewMessages");
// console.log("checkForNewMessages");
idleTime = idleTime ?? 3000; // how much time without interaction before we are considered idle
console.log("idleTime = ", idleTime);
// console.log("idleTime = ", idleTime);
idle = false;
if (timeouts.idleTimer) clearTimeout(timeouts.idleTimer);
timeouts.idleTimer = setTimeout(() => {
console.log("update messages");
// console.log("update messages");
if (haveNewMessage) {
console.log("call showText()");
// console.log("call showText()");
haveNewMessage = false;
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
let messageList = showAll ? Bangle.MESSAGES : Bangle.MESSAGES.filter(m => m.new || m.show);
if (!messageList.length) {
console.log("No messages")
// console.log("No messages")
return;
}
// Bangle.setLocked(false); // TODO make as option
@ -223,14 +226,14 @@ const showText = function(showAll) {
const removeMessage = function() {
const removeAndReset = () => {
let id = msgBoxes[messageNum].id;
Bangle.MESSAGES.filter(m => m.id !== id);
let id = msgBoxes[messageNum].msg.id;
Bangle.MESSAGES = Bangle.MESSAGES.filter(m => m.id !== id); // remove from Bangle.MESSAGES
msgBoxes.splice(messageNum, 1); // remove from msgBoxes
if (!msgBoxes.length) {
Bangle.setUI();
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
refresh();
msgBoxes[messageNum].draw();
@ -388,8 +391,8 @@ const showText = function(showAll) {
if (e.b === 0) {
firstTouch = true;
}
console.log("top of handler: first touch = ", firstTouch);
// console.log("top of handler: e = ", e);
// console.log("top of handler: first touch = ", firstTouch);
// // console.log("top of handler: e = ", e);
if (switching) return; // don't respond to touch while we are animating
if (firstTouch && e.b === 1) {
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
if (idx >= 0) delete Bangle.MESSAGES[idx].new;
msgBoxes[messageNum].clearNew();
console.log("do tests");
console.log("dy, dx", e.dy, e.dx);
console.log("e", e);
// console.log("do tests");
// console.log("dy, dx", e.dy, e.dx);
// console.log("e", e);
if (Math.abs(e.dy) > Math.abs(e.dx)) {
firstTouch = false;
console.log("up down");
// console.log("up down");
if (e.dy > 0 && msgBoxes[messageNum].top) {
mode = "prev";
} 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)) {
firstTouch = false;
console.log("left right");
// console.log("left right");
if (e.dx < 0) {
mode = "left";
} else {
@ -434,10 +437,10 @@ const showText = function(showAll) {
};
const nextHandler = function(e) {
console.log("nextHandler");
console.log(e);
// console.log("nextHandler");
// console.log(e);
if (e.b == 0) {
console.log("firstTouch = ", firstTouch);
// console.log("firstTouch = ", firstTouch);
checkForNewMessages();
// firstTouch = true;
}