mark read
This commit is contained in:
parent
70d66c876d
commit
6ef2f57a84
@ -28,4 +28,16 @@ function mail.save()
|
|||||||
minetest.log("error","[mail] Save failed - messages may be lost!")
|
minetest.log("error","[mail] Save failed - messages may be lost!")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- save periodically
|
||||||
|
local timer = 0
|
||||||
|
minetest.register_globalstep(function(dtime)
|
||||||
|
timer = timer + dtime
|
||||||
|
if timer < 30 then return end
|
||||||
|
timer=0
|
||||||
|
|
||||||
|
mail.save()
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +17,15 @@ api.deleteMail = function(index){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api.markRead = function(index){
|
||||||
|
return m.request({
|
||||||
|
method: "POST",
|
||||||
|
url: "api/markread",
|
||||||
|
data: { index: index },
|
||||||
|
headers: { "authorization": webmail.token }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
api.verifyToken = function(){
|
api.verifyToken = function(){
|
||||||
return m.request({
|
return m.request({
|
||||||
url: "api/verify",
|
url: "api/verify",
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
return m("div", "Loading...");
|
return m("div", "Loading...");
|
||||||
|
|
||||||
var id = m.route.param("id");
|
var id = m.route.param("id");
|
||||||
var mail = webmail.mails[id-1];
|
var mail = webmail.service.readMail(id);
|
||||||
|
|
||||||
console.log(mail);//XXX
|
console.log(mail);//XXX
|
||||||
|
|
||||||
|
@ -20,17 +20,22 @@
|
|||||||
timeStr = time_m.format("YYYY-MM-DD HH:mm:ss") + " (" + durationStr + ")";
|
timeStr = time_m.format("YYYY-MM-DD HH:mm:ss") + " (" + durationStr + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
return m("tr", [
|
var rowClass = vnode.attrs.row.unread ? "table-primary" : "";
|
||||||
|
|
||||||
|
return m("tr", {class: rowClass}, [
|
||||||
m("td", vnode.attrs.row.sender),
|
m("td", vnode.attrs.row.sender),
|
||||||
m("td", vnode.attrs.row.subject),
|
m("td", vnode.attrs.row.subject),
|
||||||
m("td", timeStr),
|
m("td", timeStr),
|
||||||
m("td", vnode.attrs.row.unread),
|
|
||||||
m("td", [
|
m("td", [
|
||||||
m("div", { class: "btn-group" }, [
|
m("div", { class: "btn-group" }, [
|
||||||
m("button[type=button]", { class: "btn btn-primary", onclick: openMail }, "Open"),
|
m("button[type=button]", { class: "btn btn-primary", onclick: openMail },[
|
||||||
m("button[type=button]", { class: "btn btn-secondary" }, "Mark unread"),
|
m("i", {class:"fa fa-envelope-open"}),
|
||||||
m("button[type=button]", { class: "btn btn-secondary" }, "Mark read"),
|
"Open"
|
||||||
m("button[type=button]", { class: "btn btn-danger", onclick: deleteMail }, "Remove")
|
]),
|
||||||
|
m("button[type=button]", { class: "btn btn-danger", onclick: deleteMail },[
|
||||||
|
m("i", {class:"fa fa-trash"}),
|
||||||
|
"Remove"
|
||||||
|
])
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
]);
|
]);
|
||||||
@ -47,7 +52,6 @@
|
|||||||
m("th", "Sender"),
|
m("th", "Sender"),
|
||||||
m("th", "Subject"),
|
m("th", "Subject"),
|
||||||
m("th", "Sent"),
|
m("th", "Sent"),
|
||||||
m("th", "Status"),
|
|
||||||
m("th", "Action")
|
m("th", "Action")
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
@ -4,12 +4,16 @@
|
|||||||
function NavLinks(){
|
function NavLinks(){
|
||||||
return m("ul", {class:"navbar-nav"}, [
|
return m("ul", {class:"navbar-nav"}, [
|
||||||
m("a", {class:"nav-link", href:"#!/login"}, "Login"),
|
m("a", {class:"nav-link", href:"#!/login"}, "Login"),
|
||||||
m("a", {class:"nav-link", href:"#!/messages"}, "Messages")
|
m("a", {class:"nav-link", href:"#!/messages"}, [
|
||||||
|
"Messages",
|
||||||
|
m("span", {class: "badge badge-light"}, webmail.service.countUnread())
|
||||||
|
])
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function NavBarContent(){
|
function NavBarContent(){
|
||||||
return [
|
return [
|
||||||
|
m("i", {class:"fa fa-envelope"}),
|
||||||
m("a", {class:"navbar-brand", href:"#"}, "Minetest webmail"),
|
m("a", {class:"navbar-brand", href:"#"}, "Minetest webmail"),
|
||||||
m("div", {class:"navbar-collapse"}, NavLinks())
|
m("div", {class:"navbar-collapse"}, NavLinks())
|
||||||
];
|
];
|
||||||
|
@ -62,7 +62,31 @@ service.fetchMails = function(){
|
|||||||
webmail.mails = result;
|
webmail.mails = result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
service.countUnread = function(){
|
||||||
|
var count = 0;
|
||||||
|
if (webmail.mails && webmail.mails.length){
|
||||||
|
webmail.mails.forEach(function(mail){
|
||||||
|
if (mail.unread)
|
||||||
|
count++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
service.readMail = function(index){
|
||||||
|
if (webmail.mails && webmail.mails.length){
|
||||||
|
//mark as read with api
|
||||||
|
webmail.api.markRead(index);
|
||||||
|
|
||||||
|
//mark read locally
|
||||||
|
var mail = webmail.mails[index-1];
|
||||||
|
mail.unread = false;
|
||||||
|
|
||||||
|
return mail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
service.deleteMail = function(index){
|
service.deleteMail = function(index){
|
||||||
|
@ -2,3 +2,4 @@ require("./minetest/index");
|
|||||||
require("./login");
|
require("./login");
|
||||||
require("./verify");
|
require("./verify");
|
||||||
require("./inbox");
|
require("./inbox");
|
||||||
|
require("./markread");
|
||||||
|
17
webmail/src/api/markread.js
Normal file
17
webmail/src/api/markread.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
const app = require("../app");
|
||||||
|
const tokencheck = require("./tokencheck");
|
||||||
|
|
||||||
|
const bodyParser = require('body-parser');
|
||||||
|
const jsonParser = bodyParser.json();
|
||||||
|
|
||||||
|
const markmessage = require("../promise/markmessage");
|
||||||
|
|
||||||
|
app.post('/api/markread', jsonParser, function(req, res){
|
||||||
|
|
||||||
|
var payload = tokencheck(req, res);
|
||||||
|
if (payload && req.body.index) {
|
||||||
|
markmessage(payload.username, req.body.index);
|
||||||
|
}
|
||||||
|
res.status(200).end();
|
||||||
|
});
|
14
webmail/src/promise/markmessage.js
Normal file
14
webmail/src/promise/markmessage.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
const events = require("../events");
|
||||||
|
|
||||||
|
module.exports = (playername, index) => new Promise(function(resolve, reject){
|
||||||
|
|
||||||
|
events.emit("channel-send", {
|
||||||
|
type: "mark-mail-read",
|
||||||
|
playername: playername,
|
||||||
|
index: +index
|
||||||
|
});
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user