Mercurial Hosting > chat
comparison src/lib/User.luan @ 33:e2b7f6393dab
add online
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 10 Nov 2024 19:57:14 -0700 |
| parents | f4708943f29e |
| children | 7ea33179592a |
comparison
equal
deleted
inserted
replaced
| 32:0f40501b0b56 | 33:e2b7f6393dab |
|---|---|
| 16 local Http = require "luan:http/Http.luan" | 16 local Http = require "luan:http/Http.luan" |
| 17 local Db = require "site:/lib/Db.luan" | 17 local Db = require "site:/lib/Db.luan" |
| 18 local run_in_transaction = Db.run_in_transaction or error() | 18 local run_in_transaction = Db.run_in_transaction or error() |
| 19 local Chat = require "site:/lib/Chat.luan" | 19 local Chat = require "site:/lib/Chat.luan" |
| 20 local chat_search = Chat.search or error() | 20 local chat_search = Chat.search or error() |
| 21 local Utils = require "site:/lib/Utils.luan" | |
| 22 local list_to_set = Utils.list_to_set or error() | |
| 23 local set_to_list = Utils.set_to_list or error() | |
| 21 local Logging = require "luan:logging/Logging.luan" | 24 local Logging = require "luan:logging/Logging.luan" |
| 22 local logger = Logging.logger "User" | 25 local logger = Logging.logger "User" |
| 23 | 26 |
| 24 | 27 |
| 25 local User = {} | 28 local User = {} |
| 75 if n == 0 then | 78 if n == 0 then |
| 76 return 0 | 79 return 0 |
| 77 elseif n == 1 then | 80 elseif n == 1 then |
| 78 return chats[1].updated | 81 return chats[1].updated |
| 79 else error() end | 82 else error() end |
| 83 end | |
| 84 | |
| 85 function user.chatting_with_ids() | |
| 86 local my_id = user.id | |
| 87 local user_ids = list_to_set{} | |
| 88 local chats = chat_search( "chat_user_ids:"..my_id ) | |
| 89 for _, chat in ipairs(chats) do | |
| 90 for _, user_id in ipairs(chat.user_ids) do | |
| 91 user_ids[user_id] = true | |
| 92 end | |
| 93 end | |
| 94 user_ids[my_id] = false | |
| 95 return set_to_list(user_ids) | |
| 80 end | 96 end |
| 81 | 97 |
| 82 return user | 98 return user |
| 83 end | 99 end |
| 84 | 100 |
