Changeset

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 3484:ce89fabb1f02
children 3486:887ce59cf396
files mod_http_muc_log/http_muc_log.html mod_http_muc_log/mod_http_muc_log.lua
diffstat 2 files changed, 39 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_muc_log/http_muc_log.html	Wed Mar 13 21:15:21 2019 +0000
+++ b/mod_http_muc_log/http_muc_log.html	Wed Mar 13 22:47:08 2019 +0100
@@ -38,6 +38,7 @@
 .body::before,.body::after{content:"";}
 .presence .verb{font-style:normal;color:#30c030;}
 .unavailable .verb{color:#c03030;}
+form{text-align:right}
 </style>
 </head>
 <body>
@@ -45,7 +46,7 @@
 <h1 title="xmpp:{jid?}">{title}</h1>
 <nav>
 <a href="xmpp:{jid?}?join">Join using a client</a>{links#
-<a class="{item.rel?}" href="{item.href}" rel="{item.rel?}">{item.text}</a>}
+<a class="{item.rel?}" href="{item.href}{hide_presence&?p=h}" rel="{item.rel?}">{item.text}</a>}
 </nav>
 </header>
 <hr>
@@ -53,7 +54,7 @@
 <nav>
 <dl class="room-list">
 {rooms#
-<dt class="name"><a href="{item.href}">{item.name}</a></dt>
+<dt class="name"><a href="{item.href}{hide_presence&?p=h}">{item.name}</a></dt>
 <dd class="description">{item.description?}</dd>}
 </dl>
 {years#
@@ -62,11 +63,24 @@
 <table id="{item.month}-{item.year}">
 <caption>{item.month}</caption>
 <tr><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th><th>Sun</th></tr>{item.weeks#
-<tr>{item.days#<td>{item.href&<a href="{item.href}">}{item.day?&nbsp;}{item.href&</a>}</td>}</tr>}
+<tr>{item.days#<td>{item.href&<a href="{item.href}{hide_presence&?p=h}">}{item.day?&nbsp;}{item.href&</a>}</td>}</tr>}
 </table>
 }
 }
 </nav>
+
+<div>
+<form>
+<label>
+<input name="p" value="h" type="checkbox"{hide_presence& checked}>
+<span>Hide joins and parts</span>
+</label>
+<noscript>
+<button type="submit">Apply</button>
+</noscript>
+</form>
+</div>
+
 <ol class="chat-logs">{lines#
 <li class="{item.st_name} {item.st_type?}" id="{item.key}">
 <a class="time" href="#{item.key}"><time datetime="{item.datetime}">{item.time}</time></a>
@@ -79,7 +93,7 @@
 <hr>
 <footer>
 <nav>{links#
-<a class="{item.rel?}" href="{item.href}" rel="{item.rel?}">{item.text}</a>}
+<a class="{item.rel?}" href="{item.href}{hide_presence&?p=h}" rel="{item.rel?}">{item.text}</a>}
 </nav>
 <br>
 <div class="powered-by">Prosody</div>
@@ -99,6 +113,9 @@
 tag.setAttribute("title", date.toString());
 }
 }
+document.forms[0].elements.p.addEventListener("change", function() {
+document.forms[0].submit();
+});
 })();
 </script>
 </body>
--- a/mod_http_muc_log/mod_http_muc_log.lua	Wed Mar 13 21:15:21 2019 +0000
+++ b/mod_http_muc_log/mod_http_muc_log.lua	Wed Mar 13 22:47:08 2019 +0100
@@ -5,6 +5,7 @@
 local it = require"util.iterators";
 local url = require"socket.url";
 local os_time, os_date = os.time, os.date;
+local httplib = require "util.http";
 local render = require"util.interpolation".new("%b{}", require"util.stanza".xml_escape);
 
 local archive = module:open_store("muc_log", "archive");
@@ -109,9 +110,19 @@
 
 local lazy = module:get_option_boolean(module.name .. "_lazy_calendar", true);
 
+local function hide_presence(request)
+	if request.url.query then
+		local data = httplib.formdecode(request.url.query);
+		if data then
+			return data.p == "h"
+		end
+	end
+	return false;
+end
+
 -- Produce the calendar view
 local function years_page(event, path)
-	local response = event.response;
+	local request, response = event.request, event.response;
 
 	local room = nodeprep(path:match("^(.*)/$"));
 	local is_open = open_room(room);
@@ -204,6 +215,7 @@
 	return render(template, {
 		title = get_room(room):get_name();
 		jid = get_room(room).jid;
+		hide_presence = hide_presence(request);
 		years = years;
 		links = {
 			{ href = "../", rel = "up", text = "Room list" },
@@ -213,7 +225,7 @@
 
 -- Produce the chat log view
 local function logs_page(event, path)
-	local response = event.response;
+	local request, response = event.request, event.response;
 
 	-- FIXME In the year, 105105, if MUC is still alive,
 	-- if Prosody can survive... Enjoy this Y10k bug
@@ -234,6 +246,7 @@
 	local iter, err = archive:find(room, {
 		["start"] = day_start;
 		["end"]   = day_start + 86399;
+		["with"]  = hide_presence(request) and "message<groupchat" or nil;
 	});
 	if not iter then
 		module:log("warn", "Could not search archive: %s", err or "no error");
@@ -304,6 +317,7 @@
 	return render(template, {
 		title = ("%s - %s"):format(get_room(room):get_name(), date);
 		jid = get_room(room).jid;
+		hide_presence = hide_presence(request);
 		lines = logs;
 		links = {
 			{ href = "./", rel = "up", text = "Calendar" },
@@ -314,7 +328,7 @@
 end
 
 local function list_rooms(event)
-	local response = event.response;
+	local request, response = event.request, event.response;
 	local room_list, i = {}, 1;
 	for room in each_room() do
 		if not (room.get_hidden or room.is_hidden)(room) then
@@ -330,6 +344,7 @@
 	return render(template, {
 		title = module:get_option_string("name", "Prosody Chatrooms");
 		jid = module.host;
+		hide_presence = hide_presence(request);
 		rooms = room_list;
 	});
 end