Software /
code /
prosody-modules
Comparison
mod_http_muc_log/mod_http_muc_log.lua @ 5581:df483d9056f5
mod_http_muc_log: Hide joins and parts by default
Now both ?p=s(how) and ?p=h(ide) are understood and propagated trough
links, with unset being being hide.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 28 Jun 2023 21:47:22 +0200 |
parent | 5118:7bce75e74f86 |
child | 5597:b681948a01f1 |
comparison
equal
deleted
inserted
replaced
5580:feadbd481285 | 5581:df483d9056f5 |
---|---|
126 | 126 |
127 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true); | 127 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true); |
128 | 128 |
129 local presence_logged = module:get_option_boolean("muc_log_presences", false); | 129 local presence_logged = module:get_option_boolean("muc_log_presences", false); |
130 | 130 |
131 local function hide_presence(request) | 131 local function show_presence(request) --> boolean|nil |
132 -- boolean -> yes or no | |
133 -- nil -> dunno | |
132 if not presence_logged then | 134 if not presence_logged then |
133 return false; | 135 -- No presence stored, skip |
136 return nil; | |
134 end | 137 end |
135 if request.url.query then | 138 if request.url.query then |
136 local data = httplib.formdecode(request.url.query); | 139 local data = httplib.formdecode(request.url.query); |
137 if data then | 140 if type(data) == "table" then |
138 return data.p == "h" | 141 if data.p == "s" or data.p == "h" then |
139 end | 142 return data.p == "s"; |
140 end | 143 end |
141 return false; | 144 end |
145 end | |
146 end | |
147 | |
148 local function presence_with(request) | |
149 local show = show_presence(request); | |
150 if show == true then | |
151 return nil; -- no filter, everything | |
152 elseif show == false or show == nil then | |
153 -- only messages | |
154 return "message<groupchat"; | |
155 end | |
156 end | |
157 | |
158 local function presence_query(request) -- > ?p=[sh] | |
159 local show = show_presence(request); | |
160 if show == true then | |
161 return { p = "s" } | |
162 elseif show == false then | |
163 return { p = "h" } | |
164 else | |
165 return nil; | |
166 end | |
142 end | 167 end |
143 | 168 |
144 local function get_dates(room) --> { integer, ... } | 169 local function get_dates(room) --> { integer, ... } |
145 local date_list = archive.dates and archive:dates(room); | 170 local date_list = archive.dates and archive:dates(room); |
146 if date_list then | 171 if date_list then |
252 return render(template, { | 277 return render(template, { |
253 static = "../@static"; | 278 static = "../@static"; |
254 room = room_obj._data; | 279 room = room_obj._data; |
255 jid = room_obj.jid; | 280 jid = room_obj.jid; |
256 jid_node = jid_split(room_obj.jid); | 281 jid_node = jid_split(room_obj.jid); |
257 hide_presence = hide_presence(request); | 282 q = presence_query(request); |
283 show_presence = show_presence(request); | |
258 presence_available = presence_logged; | 284 presence_available = presence_logged; |
259 dates = date_list; | 285 dates = date_list; |
260 links = { | 286 links = { |
261 { href = "../", rel = "up", text = "Room list" }, | 287 { href = "../", rel = "up", text = "Room list" }, |
262 { href = "latest", rel = "last", text = "Latest" }, | 288 { href = "latest", rel = "last", text = "Latest" }, |
298 | 324 |
299 local logs, i = {}, 1; | 325 local logs, i = {}, 1; |
300 local iter, err = archive:find(room, { | 326 local iter, err = archive:find(room, { |
301 ["start"] = day_start; | 327 ["start"] = day_start; |
302 ["end"] = day_start + 86399; | 328 ["end"] = day_start + 86399; |
303 ["with"] = hide_presence(request) and "message<groupchat" or nil; | 329 ["with"] = presence_with(request); |
304 }); | 330 }); |
305 if not iter then | 331 if not iter then |
306 module:log("warn", "Could not search archive: %s", err or "no error"); | 332 module:log("warn", "Could not search archive: %s", err or "no error"); |
307 return 500; | 333 return 500; |
308 end | 334 end |
473 static = "../@static"; | 499 static = "../@static"; |
474 date = date; | 500 date = date; |
475 room = room_obj._data; | 501 room = room_obj._data; |
476 jid = room_obj.jid; | 502 jid = room_obj.jid; |
477 jid_node = jid_split(room_obj.jid); | 503 jid_node = jid_split(room_obj.jid); |
478 hide_presence = hide_presence(request); | 504 q = presence_query(request); |
505 show_presence = show_presence(request); | |
479 presence_available = presence_logged; | 506 presence_available = presence_logged; |
480 lang = room_obj.get_language and room_obj:get_language(); | 507 lang = room_obj.get_language and room_obj:get_language(); |
481 lines = logs; | 508 lines = logs; |
482 links = links; | 509 links = links; |
483 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug | 510 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug |
522 response.headers.content_type = "text/html; charset=utf-8"; | 549 response.headers.content_type = "text/html; charset=utf-8"; |
523 return render(template, { | 550 return render(template, { |
524 static = "./@static"; | 551 static = "./@static"; |
525 title = module:get_option_string("name", "Prosody Chatrooms"); | 552 title = module:get_option_string("name", "Prosody Chatrooms"); |
526 jid = module.host; | 553 jid = module.host; |
527 hide_presence = hide_presence(request); | 554 q = presence_query(request); |
555 show_presence = show_presence(request); | |
528 presence_available = presence_logged; | 556 presence_available = presence_logged; |
529 rooms = room_list; | 557 rooms = room_list; |
530 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug | 558 dates = {}; -- COMPAT util.interpolation {nil|func#...} bug |
531 }); | 559 }); |
532 end | 560 end |