3
0
mirror of https://github.com/britzl/monarch.git synced 2025-06-27 02:17:53 +02:00

Fix message mock to properly deal with indexing of URLs

This commit is contained in:
Björn Ritzl 2020-05-10 22:50:31 +02:00
parent b37cb1ba79
commit 504ac9223a

View File

@ -8,9 +8,25 @@ local recipients = {}
local history = {}
local function url_to_key(url)
if type(url) == "string" then
url = msg.url(url)
end
local ok, err = pcall(function() return url.socket end)
if not ok then
return url
end
if url.socket then
return hash_to_hex(url.socket or hash("")) .. hash_to_hex(url.path or hash("")) .. hash_to_hex(url.fragment or hash(""))
else
return url
end
end
local function get_recipient(url)
recipients[url] = recipients[url] or {}
return recipients[url]
local key = url_to_key(url)
recipients[key] = recipients[key] or {}
return recipients[key]
end
local function post(url, message_id, message)