Mercurial Hosting > chat
comparison src/lib/Chat.luan @ 7:41d35b72c774
chat page
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Tue, 29 Oct 2024 22:11:40 -0600 |
| parents | 2da10ece826f |
| children | 563a5358f2ee |
comparison
equal
deleted
inserted
replaced
| 6:e22a1ba4b2ed | 7:41d35b72c774 |
|---|---|
| 1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
| 2 local error = Luan.error | 2 local error = Luan.error |
| 3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
| 4 local Table = require "luan:Table.luan" | |
| 5 local concat = Table.concat or error() | |
| 6 local is_empty = Table.is_empty or error() | |
| 4 local Time = require "luan:Time.luan" | 7 local Time = require "luan:Time.luan" |
| 5 local time_now = Time.now or error() | 8 local time_now = Time.now or error() |
| 6 local Db = require "site:/lib/Db.luan" | 9 local Db = require "site:/lib/Db.luan" |
| 7 local run_in_transaction = Db.run_in_transaction or error() | 10 local run_in_transaction = Db.run_in_transaction or error() |
| 8 | 11 |
| 42 -- Db.delete("chat_user_ids:"..id) | 45 -- Db.delete("chat_user_ids:"..id) |
| 43 Db.delete("id:"..id) | 46 Db.delete("id:"..id) |
| 44 end ) | 47 end ) |
| 45 end | 48 end |
| 46 | 49 |
| 50 function chat.other_users_email(user) | |
| 51 local User = require "site:/lib/User.luan" | |
| 52 local get_user_by_id = User.get_by_id or error() | |
| 53 | |
| 54 local my_id = user.id | |
| 55 local t = {} | |
| 56 for _, user_id in ipairs(chat.user_ids) do | |
| 57 if user_id ~= my_id then | |
| 58 local other_user = get_user_by_id(user_id) or error() | |
| 59 t[#t+1] = other_user.email | |
| 60 end | |
| 61 end | |
| 62 return concat( t, ", " ) | |
| 63 end | |
| 64 | |
| 47 return chat | 65 return chat |
| 48 end | 66 end |
| 49 | 67 |
| 50 function Chat.search(query,sort,rows) | 68 function Chat.search(query,sort,rows) |
| 51 rows = rows or 1000000 | 69 rows = rows or 1000000 |
| 55 chats[#chats+1] = from_doc(doc) | 73 chats[#chats+1] = from_doc(doc) |
| 56 end | 74 end |
| 57 return chats | 75 return chats |
| 58 end | 76 end |
| 59 | 77 |
| 78 function Chat.get_by_id(id) | |
| 79 local doc = Db.get_document("id:"..id) | |
| 80 return doc and doc.type=="chat" and from_doc(doc) or nil | |
| 81 end | |
| 82 | |
| 60 return Chat | 83 return Chat |
