Mercurial Hosting > chat
diff src/lib/Chat.luan @ 104:46418395c860 default tip
add mute chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 14 Jul 2025 00:49:11 -0600 |
parents | a47036fd0158 |
children |
line wrap: on
line diff
--- 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