Skip to content

Commit a5930b1

Browse files
authored
Merge pull request #3513 from WhelanB/messagegui
Add support for reply lib to messagegui app
2 parents c8cd53b + 81fdfc9 commit a5930b1

File tree

6 files changed

+67
-15
lines changed

6 files changed

+67
-15
lines changed

apps/messagegui/ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,4 @@
106106
0.77: Messages can now use international fonts if they are installed
107107
0.78: Fix: When user taps on a new message, clear the unread timeout
108108
0.79: Fix: Reset the unread timeout each time a new message is shown. When the message is read from user input, do not set an unread timeout.
109+
0.80: Add ability to reply to messages if a reply library is installed and the message can be replied to

apps/messagegui/app.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ require("messages").pushMessage({"t":"add","id":"call","src":"Phone","title":"Bo
2424
var Layout = require("Layout");
2525
var layout; // global var containing the layout for the currently displayed message
2626
var settings = require('Storage').readJSON("messages.settings.json", true) || {};
27+
var reply;
28+
try { reply = require("reply"); } catch (e) {}
2729
var fontSmall = "6x8";
2830
var fontMedium = g.getFonts().includes("6x15")?"6x15":"6x8:2";
2931
var fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2";
@@ -45,6 +47,7 @@ if (Graphics.prototype.setFontIntl) {
4547

4648
var active; // active screen (undefined/"list"/"music"/"map"/"message"/"scroller"/"settings")
4749
var openMusic = false; // go back to music screen after we handle something else?
50+
var replying = false; // If we're replying to a message, don't interrupt
4851
// hack for 2v10 firmware's lack of ':size' font handling
4952
try {
5053
g.setFont("6x8:2");
@@ -267,11 +270,31 @@ function showMessageSettings(msg) {
267270
/*LANG*/"View Message" : () => {
268271
showMessageScroller(msg);
269272
},
273+
};
274+
275+
if (msg.reply && reply) {
276+
menu[/*LANG*/"Reply"] = () => {
277+
replying = true;
278+
reply.reply({msg: msg})
279+
.then(result => {
280+
Bluetooth.println(JSON.stringify(result));
281+
replying = false;
282+
showMessage(msg.id);
283+
})
284+
.catch(() => {
285+
replying = false;
286+
showMessage(msg.id);
287+
});
288+
};
289+
}
290+
291+
menu = Object.assign(menu, {
270292
/*LANG*/"Delete" : () => {
271293
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
272294
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
273295
},
274-
};
296+
});
297+
275298
if (Bangle.messageIgnore && msg.src)
276299
menu[/*LANG*/"Ignore"] = () => {
277300
E.showPrompt(/*LANG*/"Ignore all messages from "+E.toJS(msg.src)+"?", {title:/*LANG*/"Ignore"}).then(isYes => {
@@ -305,6 +328,7 @@ function showMessageSettings(msg) {
305328
}
306329

307330
function showMessage(msgid, persist) {
331+
if (replying) { return; }
308332
if(!persist) resetReloadTimeout();
309333
let idx = MESSAGES.findIndex(m=>m.id==msgid);
310334
var msg = MESSAGES[idx];
@@ -374,15 +398,32 @@ function showMessage(msgid, persist) {
374398
}; 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});
375399
}
376400
footer.push({fillx:1}); // push images to left/right
377-
if (msg.positive) {
401+
if (msg.reply && reply) {
402+
posHandler = ()=>{
403+
replying = true;
404+
msg.new = false;
405+
cancelReloadTimeout(); // don't auto-reload to clock now
406+
reply.reply({msg: msg})
407+
.then(result => {
408+
Bluetooth.println(JSON.stringify(result));
409+
replying = false;
410+
layout.render();
411+
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
412+
})
413+
.catch(() => {
414+
replying = false;
415+
layout.render();
416+
showMessage(msg.id);
417+
});
418+
}; footer.push({type:"img",src:atob("QRABAAAAAAAH//+AAAAABgP//8AAAAADgf//4AAAAAHg4ABwAAAAAPh8APgAAAAAfj+B////////geHv///////hf+f///////GPw///////8cGBwAAAAAPx/gDgAAAAAfD/gHAAAAAA8DngOAAAAABwDHP8AAAAADACGf4AAAAAAAAM/w=="),col:"#0f0", cb:posHandler});
419+
}
420+
else if (msg.positive) {
378421
posHandler = ()=>{
379422
msg.new = false;
380423
cancelReloadTimeout(); // don't auto-reload to clock now
381424
Bangle.messageResponse(msg,true);
382425
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
383-
};
384-
footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler});
385-
426+
}; footer.push({type:"img",src:atob("QRABAAAAAAAAAAOAAAAABgAAA8AAAAADgAAD4AAAAAHgAAPgAAAAAPgAA+AAAAAAfgAD4///////gAPh///////gA+D///////AD4H//////8cPgAAAAAAPw8+AAAAAAAfB/4AAAAAAA8B/gAAAAAABwB+AAAAAAADAB4AAAAAAAAABgAA=="),col:"#0f0",cb:posHandler});
386427
}
387428

388429
layout = new Layout({ type:"v", c: [

apps/messagegui/metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"id": "messagegui",
33
"name": "Message UI",
44
"shortName": "Messages",
5-
"version": "0.79",
5+
"version": "0.80",
66
"description": "Default app to display notifications from iOS and Gadgetbridge/Android",
77
"icon": "app.png",
88
"type": "app",
99
"tags": "tool,system",
1010
"supports": ["BANGLEJS","BANGLEJS2"],
11-
"dependencies" : { "messageicons":"module" },
11+
"dependencies" : { "messageicons":"module", "reply": "module" },
1212
"provides_modules": ["messagegui"],
1313
"default": true,
1414
"readme": "README.md",

apps/reply/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
0.01: New Library!
1+
0.01: New Library!
2+
0.02: Minor bug fixes

apps/reply/lib.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ exports.reply = function (options) {
66
keyboard = null;
77
}
88

9-
function constructReply(msg, replyText, resolve) {
9+
function constructReply(msg, replyText, resolve, reject) {
10+
if (!replyText) {
11+
reject("");
12+
return;
13+
}
14+
1015
var responseMessage = {msg: replyText};
1116
if (msg.id) {
1217
responseMessage = { t: "notify", id: msg.id, n: "REPLY", msg: replyText };
@@ -29,7 +34,10 @@ exports.reply = function (options) {
2934
}, // options
3035
/*LANG*/ "Compose": function () {
3136
keyboard.input().then((result) => {
32-
constructReply(options.msg ?? {}, result, resolve);
37+
if (result)
38+
constructReply(options.msg ?? {}, result, resolve, reject);
39+
else
40+
E.showMenu(menu);
3341
});
3442
},
3543
};
@@ -40,7 +48,7 @@ exports.reply = function (options) {
4048
) || [];
4149
replies.forEach((reply) => {
4250
menu = Object.defineProperty(menu, reply.text, {
43-
value: () => constructReply(options.msg ?? {}, reply.text, resolve),
51+
value: () => constructReply(options.msg ?? {}, reply.text, resolve, reject),
4452
});
4553
});
4654
if (!keyboard) delete menu[/*LANG*/ "Compose"];
@@ -60,10 +68,11 @@ exports.reply = function (options) {
6068
);
6169
} else {
6270
keyboard.input().then((result) => {
63-
constructReply(options.msg.id, result, resolve);
71+
constructReply(options.msg, result, resolve, reject);
6472
});
6573
}
74+
} else{
75+
E.showMenu(menu);
6676
}
67-
E.showMenu(menu);
6877
});
69-
};
78+
};

apps/reply/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ "id": "reply",
22
"name": "Reply Library",
3-
"version": "0.01",
3+
"version": "0.02",
44
"description": "A library for replying to text messages via predefined responses or keyboard",
55
"icon": "app.png",
66
"type": "module",

0 commit comments

Comments
 (0)