# HG changeset patch # User JC Brand # Date 1614683054 -3600 # Node ID 21698b960bd6acd1e4ce1f8c95a290970e21cb7c # Parent e453eaf1589e586aabf5a0b8c2d6a3d92c361072 mod_ogp: Add the ability to detect and process multiple URLs in a body diff -r e453eaf1589e -r 21698b960bd6 mod_ogp/mod_ogp.lua --- 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)