Comparison

mod_http_muc_log/mod_http_muc_log.lua @ 3593:0b670831ace3

mod_http_muc_log: Correctly build absolute URLs Handles case of http_path being "/", where :http_url() ends with a slash, so there would be two slashes.
author Kim Alvefur <zash@zash.se>
date Mon, 13 May 2019 10:50:00 +0200
parent 3592:61a9c087730a
child 3594:b66111f75e4b
comparison
equal deleted inserted replaced
3592:61a9c087730a 3593:0b670831ace3
57 link.path = url.build_path(path); 57 link.path = url.build_path(path);
58 return url.build(link); 58 return url.build(link);
59 end 59 end
60 end 60 end
61 61
62 local function get_absolute_link(room, date)
63 local link = url.parse(module:http_url());
64 local path = url.parse_path(link.path);
65 if room then
66 table.insert(path, room);
67 if date then
68 table.insert(path, date)
69 path.is_directory = false;
70 else
71 path.is_directory = true;
72 end
73 end
74 link.path = url.build_path(path)
75 return url.build(link)
76 end
77
62 -- Whether room can be joined by anyone 78 -- Whether room can be joined by anyone
63 local function open_room(room) -- : boolean 79 local function open_room(room) -- : boolean
64 if type(room) == "string" then 80 if type(room) == "string" then
65 room = get_room(room); 81 room = get_room(room);
66 -- assumed to be a room object otherwise 82 -- assumed to be a room object otherwise
82 98
83 module:hook("muc-disco#info", function (event) 99 module:hook("muc-disco#info", function (event)
84 local room = event.room; 100 local room = event.room;
85 if open_room(room) then 101 if open_room(room) then
86 table.insert(event.form, { name = "muc#roominfo_logs", type="text-single" }); 102 table.insert(event.form, { name = "muc#roominfo_logs", type="text-single" });
87 event.formdata["muc#roominfo_logs"] = module:http_url() .. "/" .. get_link(jid_split(event.room.jid), nil); 103 event.formdata["muc#roominfo_logs"] = get_absolute_link(jid_split(event.room.jid), nil);
88 end 104 end
89 end); 105 end);
90 106
91 local function sort_Y(a,b) return a.year > b.year end 107 local function sort_Y(a,b) return a.year > b.year end
92 local function sort_m(a,b) return a.n > b.n end 108 local function sort_m(a,b) return a.n > b.n end