Mercurial Hosting > chat
changeset 104:46418395c860 default tip
add mute chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 14 Jul 2025 00:49:11 -0600 |
parents | 3ea9783cee39 |
children | |
files | src/chat.js src/get_chat.js.luan src/index.html.luan src/lib/Chat.luan src/lib/Notify.luan src/open_mute.js.luan src/save_mute.js.luan |
diffstat | 7 files changed, 91 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
diff -r 3ea9783cee39 -r 46418395c860 src/chat.js --- a/src/chat.js Sun Jul 13 14:38:52 2025 -0600 +++ b/src/chat.js Mon Jul 14 00:49:11 2025 -0600 @@ -171,6 +171,23 @@ } } +function openMute() { + ajax(`open_mute.js?chat=${currentChatId}`); +} + +function doOpenMute(muted) { + let dialog = document.querySelector('dialog[mute]'); + let checkbox = dialog.querySelector('input'); + checkbox.checked = muted; + openModal(dialog); +} + +function saveMute(el) { + let muted = document.querySelector('dialog[mute] input').checked; + closeModal(el); + ajax(`save_mute.js?chat=${currentChatId}&muted=${muted}`); +} + function active() { let url = 'active.js'; if( currentChatId )
diff -r 3ea9783cee39 -r 46418395c860 src/get_chat.js.luan --- a/src/get_chat.js.luan Sun Jul 13 14:38:52 2025 -0600 +++ b/src/get_chat.js.luan Mon Jul 14 00:49:11 2025 -0600 @@ -61,6 +61,7 @@ <img onclick="clickMenu(this)" src="/images/menu.svg"> <div> <span onclick="openPeople()">People in Chat</span> + <span onclick="openMute()">Mute Chat</span> <span onclick="openAddToChat()">Add Someone to Chat</span> <span onclick="deleteChat()">Delete Chat</span> </div>
diff -r 3ea9783cee39 -r 46418395c860 src/index.html.luan --- a/src/index.html.luan Sun Jul 13 14:38:52 2025 -0600 +++ b/src/index.html.luan Mon Jul 14 00:49:11 2025 -0600 @@ -125,6 +125,16 @@ </div> </form> </dialog> + <dialog mute> + <h2>Mute Chat</h2> + <p> + <label clickable><input type=checkbox name=mute> Mute notification</label> + </p> + <div buttons> + <button type=button onclick="closeModal(this)">Cancel</button> + <button onclick="saveMute(this)">Save</button> + </div> + </dialog> <input type="file" required onchange="loadedFile(this)"> <script> 'use strict';
diff -r 3ea9783cee39 -r 46418395c860 src/lib/Chat.luan --- a/src/lib/Chat.luan Sun Jul 13 14:38:52 2025 -0600 +++ b/src/lib/Chat.luan Mon Jul 14 00:49:11 2025 -0600 @@ -11,6 +11,9 @@ local run_in_transaction = Db.run_in_transaction or error() local Utils = require "site:/lib/Utils.luan" local base_url = Utils.base_url or error() +local set_to_list = Utils.set_to_list or error() +local list_to_set = Utils.list_to_set or error() +local to_list = Utils.to_list or error() local Chat = {} @@ -22,6 +25,7 @@ user_ids = doc.chat_user_ids updated = doc.chat_updated key = doc.chat_key + mute_ids = list_to_set(to_list(doc.mute_ids)) } end @@ -32,6 +36,7 @@ chat_user_ids = chat.user_ids or error() chat_updated = chat.updated or error() chat_key = chat.key or error() + mute_ids = set_to_list(chat.mute_ids) } end @@ -44,6 +49,7 @@ function Chat.new(chat) chat.updated = chat.updated or time_now() chat.key = chat.key or get_chat_key(chat.user_ids) + chat.mute_ids = chat.mute_ids or list_to_set{} function chat.save() local doc = to_doc(chat) @@ -51,6 +57,10 @@ chat.id = doc.id end + function chat.reload() + return Chat.get_by_id(chat.id) or error(chat.id) + end + function chat.delete() run_in_transaction( function() local id = chat.id
diff -r 3ea9783cee39 -r 46418395c860 src/lib/Notify.luan --- a/src/lib/Notify.luan Sun Jul 13 14:38:52 2025 -0600 +++ b/src/lib/Notify.luan Mon Jul 14 00:49:11 2025 -0600 @@ -38,11 +38,15 @@ local users = {} local fns = {} - function fns.add(user_ids) + function fns.add(user_ids,mute_ids) local now = time_now() for _, user_id in ipairs(user_ids) do local user = get_user_by_id(user_id) - if users[user_id] == nil and user.notify_email ~= nil and (user.multi_notify or not user.was_notified) then + if users[user_id] == nil \ + and user.notify_email ~= nil \ + and not mute_ids[user_id] \ + and (user.multi_notify or not user.was_notified) \ + then users[user_id] = now -- logger.info("add "..user_id) end @@ -88,7 +92,7 @@ function Notify.add(chat) Thread.run(function() - glob.add(chat.user_ids) + glob.add(chat.user_ids,chat.mute_ids) end) end
diff -r 3ea9783cee39 -r 46418395c860 src/open_mute.js.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/open_mute.js.luan Mon Jul 14 00:49:11 2025 -0600 @@ -0,0 +1,20 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Parsers = require "luan:Parsers.luan" +local json_string = Parsers.json_string or error() +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local Chat = require "site:/lib/Chat.luan" +local get_chat_by_id = Chat.get_by_id or error() +local User = require "site:/lib/User.luan" +local current_user = User.current or error() + +return function() + local chat = Http.request.parameters.chat or error() + chat = get_chat_by_id(chat) or error() + local user = current_user() or error() + Io.stdout = Http.response.text_writer() +%> + doOpenMute(<%=chat.mute_ids[user.id]%>); +<% +end
diff -r 3ea9783cee39 -r 46418395c860 src/save_mute.js.luan --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/save_mute.js.luan Mon Jul 14 00:49:11 2025 -0600 @@ -0,0 +1,26 @@ +local Luan = require "luan:Luan.luan" +local error = Luan.error +local Io = require "luan:Io.luan" +local Http = require "luan:http/Http.luan" +local Chat = require "site:/lib/Chat.luan" +local get_chat_by_id = Chat.get_by_id or error() +local Db = require "site:/lib/Db.luan" +local run_in_transaction = Db.run_in_transaction or error() +local Chat = require "site:/lib/Chat.luan" +local get_chat_by_id = Chat.get_by_id or error() +local User = require "site:/lib/User.luan" +local current_user = User.current or error() + + +return function() + local chat = Http.request.parameters.chat or error() + local muted = Http.request.parameters.muted or error() + chat = get_chat_by_id(chat) or error() + local user_ids = chat.user_ids + local user = current_user() or error() + run_in_transaction( function() + chat = chat.reload() + chat.mute_ids[user.id] = muted=="true" + chat.save() + end ) +end