annotate src/delete_chat.js.luan @ 12:9f45d32670ae

server push
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 31 Oct 2024 21:40:57 -0600
parents 563a5358f2ee
children 82b55186a4a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Http = require "luan:http/Http.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local User = require "site:/lib/User.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local current_user = User.current or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Chat = require "site:/lib/Chat.luan"
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local get_chat_by_id = Chat.get_by_id or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 return function()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local chat = Http.request.parameters.chat or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 chat = get_chat_by_id(chat) or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local user = current_user() or error()
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 chat.delete()
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
15 chat.http_push("location = '/chat.html'")
11
563a5358f2ee add delete_chat
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 end