--- a/mod_ogp/mod_ogp.lua Mon Mar 01 17:33:32 2021 +0100
+++ b/mod_ogp/mod_ogp.lua Tue Mar 02 12:04:14 2021 +0100
@@ -5,17 +5,10 @@
local xmlns_fasten = "urn:xmpp:fasten:0";
local xmlns_xhtml = "http://www.w3.org/1999/xhtml";
-local function ogp_handler(event)
- local room, stanza = event.room, st.clone(event.stanza)
- local body = stanza:get_child_text("body")
- if not body then return; end
- local url = body:match(url_pattern)
+local function fetch_ogp_data(room, url, origin_id)
if not url then return; end
- local origin_id = stanza:find("{urn:xmpp:sid:0}origin-id@id")
- if not origin_id then return; end
-
http.request(
url,
nil,
@@ -71,6 +64,20 @@
)
end
+local function ogp_handler(event)
+ local room, stanza = event.room, st.clone(event.stanza)
+ local body = stanza:get_child_text("body")
+
+ if not body then return; end
+
+ local origin_id = stanza:find("{urn:xmpp:sid:0}origin-id@id")
+ if not origin_id then return; end
+
+ for url in body:gmatch(url_pattern) do
+ fetch_ogp_data(room, url, origin_id);
+ end
+end
+
module:hook("muc-occupant-groupchat", ogp_handler)