comparison mod_http_muc_log/mod_http_muc_log.lua @ 3485:181561d0aae5

mod_http_muc_log: Add functionality for hiding joins and parts For Guus
author Kim Alvefur <zash@zash.se>
date Wed, 13 Mar 2019 22:47:08 +0100
parents 97b8b07ae1d1
children 887ce59cf396
comparison
equal deleted inserted replaced
3484:ce89fabb1f02 3485:181561d0aae5
3 local jid_split = require"util.jid".split; 3 local jid_split = require"util.jid".split;
4 local nodeprep = require"util.encodings".stringprep.nodeprep; 4 local nodeprep = require"util.encodings".stringprep.nodeprep;
5 local it = require"util.iterators"; 5 local it = require"util.iterators";
6 local url = require"socket.url"; 6 local url = require"socket.url";
7 local os_time, os_date = os.time, os.date; 7 local os_time, os_date = os.time, os.date;
8 local httplib = require "util.http";
8 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape); 9 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape);
9 10
10 local archive = module:open_store("muc_log", "archive"); 11 local archive = module:open_store("muc_log", "archive");
11 12
12 -- Support both old and new MUC code 13 -- Support both old and new MUC code
107 return iter(); 108 return iter();
108 end 109 end
109 110
110 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true); 111 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true);
111 112
113 local function hide_presence(request)
114 if request.url.query then
115 local data = httplib.formdecode(request.url.query);
116 if data then
117 return data.p == "h"
118 end
119 end
120 return false;
121 end
122
112 -- Produce the calendar view 123 -- Produce the calendar view
113 local function years_page(event, path) 124 local function years_page(event, path)
114 local response = event.response; 125 local request, response = event.request, event.response;
115 126
116 local room = nodeprep(path:match("^(.*)/$")); 127 local room = nodeprep(path:match("^(.*)/$"));
117 local is_open = open_room(room); 128 local is_open = open_room(room);
118 if is_open == nil then 129 if is_open == nil then
119 return -- implicit 404 130 return -- implicit 404
202 213
203 response.headers.content_type = "text/html; charset=utf-8"; 214 response.headers.content_type = "text/html; charset=utf-8";
204 return render(template, { 215 return render(template, {
205 title = get_room(room):get_name(); 216 title = get_room(room):get_name();
206 jid = get_room(room).jid; 217 jid = get_room(room).jid;
218 hide_presence = hide_presence(request);
207 years = years; 219 years = years;
208 links = { 220 links = {
209 { href = "../", rel = "up", text = "Room list" }, 221 { href = "../", rel = "up", text = "Room list" },
210 }; 222 };
211 }); 223 });
212 end 224 end
213 225
214 -- Produce the chat log view 226 -- Produce the chat log view
215 local function logs_page(event, path) 227 local function logs_page(event, path)
216 local response = event.response; 228 local request, response = event.request, event.response;
217 229
218 -- FIXME In the year, 105105, if MUC is still alive, 230 -- FIXME In the year, 105105, if MUC is still alive,
219 -- if Prosody can survive... Enjoy this Y10k bug 231 -- if Prosody can survive... Enjoy this Y10k bug
220 local room, date = path:match("^(.-)/(%d%d%d%d%-%d%d%-%d%d)$"); 232 local room, date = path:match("^(.-)/(%d%d%d%d%-%d%d%-%d%d)$");
221 room = nodeprep(room); 233 room = nodeprep(room);
232 244
233 local logs, i = {}, 1; 245 local logs, i = {}, 1;
234 local iter, err = archive:find(room, { 246 local iter, err = archive:find(room, {
235 ["start"] = day_start; 247 ["start"] = day_start;
236 ["end"] = day_start + 86399; 248 ["end"] = day_start + 86399;
249 ["with"] = hide_presence(request) and "message<groupchat" or nil;
237 }); 250 });
238 if not iter then 251 if not iter then
239 module:log("warn", "Could not search archive: %s", err or "no error"); 252 module:log("warn", "Could not search archive: %s", err or "no error");
240 return 500; 253 return 500;
241 end 254 end
302 315
303 response.headers.content_type = "text/html; charset=utf-8"; 316 response.headers.content_type = "text/html; charset=utf-8";
304 return render(template, { 317 return render(template, {
305 title = ("%s - %s"):format(get_room(room):get_name(), date); 318 title = ("%s - %s"):format(get_room(room):get_name(), date);
306 jid = get_room(room).jid; 319 jid = get_room(room).jid;
320 hide_presence = hide_presence(request);
307 lines = logs; 321 lines = logs;
308 links = { 322 links = {
309 { href = "./", rel = "up", text = "Calendar" }, 323 { href = "./", rel = "up", text = "Calendar" },
310 { href = prev_when, rel = "prev", text = prev_when}, 324 { href = prev_when, rel = "prev", text = prev_when},
311 { href = next_when, rel = "next", text = next_when}, 325 { href = next_when, rel = "next", text = next_when},
312 }; 326 };
313 }); 327 });
314 end 328 end
315 329
316 local function list_rooms(event) 330 local function list_rooms(event)
317 local response = event.response; 331 local request, response = event.request, event.response;
318 local room_list, i = {}, 1; 332 local room_list, i = {}, 1;
319 for room in each_room() do 333 for room in each_room() do
320 if not (room.get_hidden or room.is_hidden)(room) then 334 if not (room.get_hidden or room.is_hidden)(room) then
321 room_list[i], i = { 335 room_list[i], i = {
322 href = get_link(jid_split(room.jid), nil); 336 href = get_link(jid_split(room.jid), nil);
328 342
329 response.headers.content_type = "text/html; charset=utf-8"; 343 response.headers.content_type = "text/html; charset=utf-8";
330 return render(template, { 344 return render(template, {
331 title = module:get_option_string("name", "Prosody Chatrooms"); 345 title = module:get_option_string("name", "Prosody Chatrooms");
332 jid = module.host; 346 jid = module.host;
347 hide_presence = hide_presence(request);
333 rooms = room_list; 348 rooms = room_list;
334 }); 349 });
335 end 350 end
336 351
337 module:provides("http", { 352 module:provides("http", {