Mercurial Hosting > chat
comparison src/delete_old.js.luan @ 107:ed1418c95488
delete old messages
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Wed, 03 Sep 2025 12:36:57 -0600 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 106:15cf43dd144c | 107:ed1418c95488 |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | |
| 2 local error = Luan.error | |
| 3 local range = Luan.range or error() | |
| 4 local Io = require "luan:Io.luan" | |
| 5 local Http = require "luan:http/Http.luan" | |
| 6 local User = require "site:/lib/User.luan" | |
| 7 local current_user = User.current or error() | |
| 8 local Chat = require "site:/lib/Chat.luan" | |
| 9 local get_chat_by_id = Chat.get_by_id or error() | |
| 10 local Shared = require "site:/lib/Shared.luan" | |
| 11 local http_push_to_users = Shared.http_push_to_users or error() | |
| 12 local Utils = require "site:/lib/Utils.luan" | |
| 13 local is_in_list = Utils.is_in_list or error() | |
| 14 local Post = require "site:/lib/Post.luan" | |
| 15 local post_search = Post.search or error() | |
| 16 local Logging = require "luan:logging/Logging.luan" | |
| 17 local logger = Logging.logger "delete_old.js" | |
| 18 | |
| 19 | |
| 20 local function delete_old(chat) | |
| 21 local posts = post_search( "post_chat_id:"..chat.id, "id" ) | |
| 22 for i in range( 1, #posts // 2 ) do | |
| 23 posts[i].delete() | |
| 24 end | |
| 25 end | |
| 26 | |
| 27 return function() | |
| 28 local chat = Http.request.parameters.chat or error() | |
| 29 chat = get_chat_by_id(chat) or error() | |
| 30 local user_ids = chat.user_ids | |
| 31 local user = current_user() or error() | |
| 32 is_in_list( user.id, user_ids ) or error() | |
| 33 delete_old(chat) | |
| 34 local js = "location.reload()" | |
| 35 chat.http_push(js) | |
| 36 end |
