diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-04-05 19:36:37 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-04-18 10:06:13 +0200 |
commit | e31c35899acf1c7e18ca54cf70ce3c06ef6a2d9f (patch) | |
tree | d1c2afef75c835c868d0bd3dac64f61c114c4920 | |
parent | 84bcee3d2b695e8fc6158c264ca1774d4f546fef (diff) | |
download | server-e31c35899acf1c7e18ca54cf70ce3c06ef6a2d9f.tar.gz |
Remove chat log pages.
The unread chat badge in the game lists should be enough.
-rw-r--r-- | server.js | 13 | ||||
-rw-r--r-- | views/chat.pug | 93 | ||||
-rw-r--r-- | views/profile.pug | 2 |
3 files changed, 0 insertions, 108 deletions
@@ -657,16 +657,6 @@ app.get('/users', function (req, res) { res.render('user_list.pug', { user: req.user, user_list: rows }) }) -app.get('/chat', must_be_logged_in, function (req, res) { - let chat = SQL_SELECT_USER_CHAT_N.all(req.user.user_id, 12*20) - res.render('chat.pug', { user: req.user, chat: chat, page_size: 12 }) -}) - -app.get('/chat/all', must_be_logged_in, function (req, res) { - let chat = SQL_SELECT_USER_CHAT.all(req.user.user_id) - res.render('chat.pug', { user: req.user, chat: chat, page_size: 0 }) -}) - /* * CONTACTS */ @@ -1099,9 +1089,6 @@ load_rules() const SQL_INSERT_GAME = SQL("INSERT INTO games (owner_id,title_id,scenario,options,is_private,is_random,description) VALUES (?,?,?,?,?,?,?)") const SQL_DELETE_GAME = SQL("DELETE FROM games WHERE game_id=? AND owner_id=?") -const SQL_SELECT_USER_CHAT = SQL("SELECT game_id,unixepoch(time),name,message FROM game_chat_view WHERE game_id IN ( SELECT DISTINCT game_id FROM players WHERE user_id=? ) ORDER BY chat_id DESC").raw() -const SQL_SELECT_USER_CHAT_N = SQL("SELECT game_id,unixepoch(time),name,message FROM game_chat_view WHERE game_id IN ( SELECT DISTINCT game_id FROM players WHERE user_id=? ) ORDER BY chat_id DESC LIMIT ?").raw() - const SQL_SELECT_UNREAD_CHAT_GAMES = SQL("select game_id from unread_chats where user_id = ?").pluck() const SQL_INSERT_UNREAD_CHAT = SQL("insert or ignore into unread_chats (user_id,game_id) values (?,?)") const SQL_DELETE_UNREAD_CHAT = SQL("delete from unread_chats where user_id = ? and game_id = ?") diff --git a/views/chat.pug b/views/chat.pug deleted file mode 100644 index 55a8eb1..0000000 --- a/views/chat.pug +++ /dev/null @@ -1,93 +0,0 @@ -//- vim:ts=4:sw=4: -doctype html -html - head - include head - title Chat Log - style. - table { width: min(60rem,100%); } - td:nth-child(1), td:nth-child(2) { white-space: nowrap; width: 0; } - td:nth-child(3) { white-space: nowrap; width: 8rem; } - #foot { display: inline-block; padding-top: 8px; } - table { border: 1px solid black; } - td { border: none; } - td a { text-decoration: none; color: black; } - tbody tr { background-color: white !important; } - tbody tr.me { background-color: aliceblue !important; } - body - include header - article - h1 Chat Log - if page_size > 0 - p - button(onclick="oldest()") Oldest - button(onclick="back()") ← - button(onclick="next()") → - button(onclick="newest()") Newest - span#foot - p - table - thead - tr - th Game - th Time - th Who - th Message - tbody - if page_size > 0 - p: a(href="/chat/all") All messages - - script. - let chat_data = !{ JSON.stringify(chat).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">") } - let page_size = !{ page_size } - let me = !{ JSON.stringify(user.name) } - let table = document.querySelector("tbody") - let foot = document.querySelector("#foot") - let chat_lines = [] - function add(tr,text,link) { - let td = document.createElement("td") - if (link) { - let a = document.createElement("a") - a.href = link - a.textContent = text - td.appendChild(a) - } else { - td.textContent = text - } - tr.appendChild(td) - } - function format_date(date) { - let t = date.toISOString() - return t.substring(0,10) + " " + t.substring(11,19) - } - for (let [game_id,time,user,message] of chat_data) { - let tr = document.createElement("tr") - if (user === me) tr.className = "me" - add(tr,game_id,"/join/"+game_id) - add(tr,format_date(new Date(time*1000))) - add(tr,user,"/user/"+user) - add(tr,message) - chat_lines.push(tr) - } - function next() { if (page > 0) --page; update(); } - function back() { if (page < page_count-1) ++page; update(); } - function newest() { page=0; update(); } - function oldest() { page=page_count-1; update(); } - let chat_size = chat_lines.length - let page_count = Math.ceil(chat_size / page_size) - let page = 0 - function update() { - table.innerHTML = "" - for (let i = 0; i < page_size; ++i) { - let k = page * page_size + ( page_size - i - 1) - if (k >= 0 && k < chat_size) - table.appendChild(chat_lines[k]) - foot.textContent = `${page_count-page} / ${page_count}` - } - } - if (page_size > 0) { - newest() - } else { - for (let i = chat_size-1; i >= 0; --i) - table.appendChild(chat_lines[i]) - } diff --git a/views/profile.pug b/views/profile.pug index 99c8f16..63d3018 100644 --- a/views/profile.pug +++ b/views/profile.pug @@ -39,8 +39,6 @@ html dt <a href="/webhook">Configure webhook</a> dd= new URL(user.webhook.url).hostname - p <a href="/chat">Chat log</a> - p form(action="/logout" method="post") button(type="submit") Logout |