add getDM endpoint

This commit is contained in:
Mystikfluu 2022-08-14 00:22:12 +02:00
parent 829c34c220
commit 18a080f349
2 changed files with 22 additions and 9 deletions

View File

@ -325,6 +325,7 @@ async function mainNoti(user) {
}
document.addEventListener("visibilitychange", function() {
//cansendNoti = document.visibilityState !== 'visible'
if (document.visibilityState === 'visible') {
cansendNoti = false
} else {
@ -360,14 +361,7 @@ function createChannel(channelname,tab) {
channelp.addEventListener("click",async function(){
switchChannel(channelname)
main()
let settings = await (await fetch("/api/settings")).json()
console.log(settings)
if(settings != "null") {
if(settings.ACCR == false) {
unreply()
}
}
unreply()
})
tab.appendChild(channelp)
}

View File

@ -32,11 +32,30 @@ module.exports = {
"dms_user_name","dms_receiver"
]
let uriencusername = encodeURIComponent(res.locals.username)
let sql = `select ${columns.join(",")} from ipost.dms where ((dms_receiver = ?) or (dms_user_name = ?)) group by dms_receiver,dms_user_name;`
con.query(sql, [encodeURIComponent(res.locals.username),encodeURIComponent(res.locals.username)], function (err, result) {
con.query(sql, [uriencusername,uriencusername], function (err, result) {
if (err) throw err;
res.json(result)
});
})
//
router.get("/api/dms/getDM", async function(req,res) {
res.set("Access-Control-Allow-Origin","*")
let arg = req.query.id
let uriencusername = encodeURIComponent(res.locals.username)
let sql = `select dms_user_name,dms_text,dms_time,dms_special_text,dms_id,dms_from_bot,dms_reply_id,dms_receiver_name from ipost.dms where dms_id=? and (dms_user_name=? or dms_receiver_name=?);`
con.query(sql, [arg,uriencusername,uriencusername], function (err, result) {
if (err) throw err;
if(result[0]) {
res.set('Cache-Control', 'public, max-age=2592000'); //cache it for one month-ish
res.json(result[0])
} else {
res.json({"error":"there is no such dm!"})
}
});
})
}
}