diff 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
line wrap: on
line diff
--- a/src/lib/User.luan	Sat Nov 09 21:41:11 2024 -0700
+++ b/src/lib/User.luan	Sun Nov 10 19:57:14 2024 -0700
@@ -18,6 +18,9 @@
 local run_in_transaction = Db.run_in_transaction or error()
 local Chat = require "site:/lib/Chat.luan"
 local chat_search = Chat.search or error()
+local Utils = require "site:/lib/Utils.luan"
+local list_to_set = Utils.list_to_set or error()
+local set_to_list = Utils.set_to_list or error()
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "User"
 
@@ -79,6 +82,19 @@
 		else error() end
 	end
 
+	function user.chatting_with_ids()
+		local my_id = user.id
+		local user_ids = list_to_set{}
+		local chats = chat_search( "chat_user_ids:"..my_id )
+		for _, chat in ipairs(chats) do
+			for _, user_id in ipairs(chat.user_ids) do
+				user_ids[user_id] = true
+			end
+		end
+		user_ids[my_id] = false
+		return set_to_list(user_ids)
+	end
+
 	return user
 end