changeset 4592:38f501dca618

mod_http_muc_log: Find edit relations using XEP-0308
author Kim Alvefur <zash@zash.se>
date Tue, 15 Jun 2021 17:35:56 +0200
parents 327c7cacd89f
children b65a363d32d2
files mod_http_muc_log/mod_http_muc_log.lua mod_http_muc_log/res/http_muc_log.html
diffstat 2 files changed, 25 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mod_http_muc_log/mod_http_muc_log.lua	Tue Jun 15 17:22:33 2021 +0200
+++ b/mod_http_muc_log/mod_http_muc_log.lua	Tue Jun 15 17:35:56 2021 +0200
@@ -330,8 +330,28 @@
 		local nick = select(3, jid_split(item.attr.from));
 		local oob = use_oob and item:get_child("x", "jabber:x:oob");
 
+		local edit = item:find("{urn:xmpp:message-correct:0}replace/@id");
+		if edit then
+			local found = false;
+			for n = i-1, 1, -1 do
+				if not logs[n] then
+					break; -- Probably reached logs[0]
+				elseif logs[n].id == edit and nick == logs[n].nick then
+					found = true;
+					logs[n].edited = key;
+					edit = logs[n].key;
+					break;
+				end
+			end
+			if not found then
+				-- Ignore unresolved edit.
+				edit = nil;
+			end
+		end
+
 		if body or verb or oob then
 			local line = {
+				id = item.attr.id,
 				key = key;
 				datetime = datetime.datetime(when);
 				time = datetime.time(when);
@@ -341,6 +361,7 @@
 				nick = nick;
 				st_name = item.name;
 				st_type = item.attr.type;
+				edit = edit;
 			};
 			if oob then
 				line.oob = {
--- a/mod_http_muc_log/res/http_muc_log.html	Tue Jun 15 17:22:33 2021 +0200
+++ b/mod_http_muc_log/res/http_muc_log.html	Tue Jun 15 17:35:56 2021 +0200
@@ -45,7 +45,8 @@
 .button{display:inline-block}
 .button>a{color:white;background-color:orange;border-radius:4px}
 form{text-align:right}
-li:target{outline:1px gray dotted}
+li.edited{display:none}
+li:target{outline:1px gray dotted;display:inherit}
 @media (prefers-color-scheme: dark) {
 html{color:#eee}
 body{background-color:#161616}
@@ -107,11 +108,11 @@
 </div>
 
 <ol class="chat-logs">{lines#
-<li {item.lang&lang="{item.lang}"} class="{item.st_name} {item.st_type?}" id="{item.key}">
+<li {item.lang&lang="{item.lang}"} class="{item.st_name} {item.st_type?} {item.edited&edited}" id="{item.key}">
 <a class="time" href="#{item.key}"><time id="{item.time}" datetime="{item.datetime}">{item.time}</time></a>
 <b class="nick">{item.nick}</b>
 <em class="verb">{item.verb?}</em>
-<q class="body">{item.body?}</q>
+<q class="body">{item.edited&<del>}{item.body?}{item.edited&</del> <a href="#{item.edited}">&#9999;</a>}{item.edit& <a href="#{item.edit}">&#9999;</a>}</q>
 {item.oob.url&<figure><a rel="nofollow" href="{item.oob.url?}"><img style="max-height:9em;max-width:16em" alt="{item.oob.desc?}" src="{item.oob.url?}"/></a><figcaption>{item.oob.desc?}</figcaption></figure>}
 </li>}
 </ol>