Comparison

mod_http_muc_log/mod_http_muc_log.lua @ 5679:c20b77e5e032

mod_http_muc_log: Correctly handle changed or retracted reactions Since per XEP-0444 each reaction should overwrite all previous reactions on a particular message from a particular occupant. Previously repeated reactions would be counted again and retractions were not handled.
author Kim Alvefur <zash@zash.se>
date Tue, 19 Sep 2023 13:22:00 +0200
parent 5597:b681948a01f1
child 5851:0ee77be396b9
comparison
equal deleted inserted replaced
5678:1cae6133e315 5679:c20b77e5e032
405 if reactions then 405 if reactions then
406 -- COMPAT Movim uses an @to attribute instead of the correct @id 406 -- COMPAT Movim uses an @to attribute instead of the correct @id
407 local target_id = reactions.attr.id or reactions.attr.to; 407 local target_id = reactions.attr.id or reactions.attr.to;
408 for n = i - 1, 1, -1 do 408 for n = i - 1, 1, -1 do
409 if logs[n].archive_id == target_id then 409 if logs[n].archive_id == target_id then
410 local react_map = logs[n].reactions; -- { string : integer } 410 local react_map = logs[n].reactions; -- [occupant_id][emoji]boolean
411 if not react_map then 411 if not react_map then
412 react_map = {}; 412 react_map = {};
413 logs[n].reactions = react_map; 413 logs[n].reactions = react_map;
414 end 414 end
415 local reacts = {};
415 for reaction_tag in reactions:childtags("reaction") do 416 for reaction_tag in reactions:childtags("reaction") do
416 -- FIXME This doesn't replace previous reactions by the same user
417 -- on the same message.
418 local reaction_text = reaction_tag:get_text() or "�"; 417 local reaction_text = reaction_tag:get_text() or "�";
419 react_map[reaction_text] = (react_map[reaction_text] or 0) + 1; 418 reacts[reaction_text] = true;
420 end 419 end
420 react_map[occupant_id] = reacts;
421 break 421 break
422 end 422 end
423 end 423 end
424 end 424 end
425 425
456 first = first or archive_id; 456 first = first or archive_id;
457 last = archive_id; 457 last = archive_id;
458 end 458 end
459 if i == 1 and not lazy then return end -- No items 459 if i == 1 and not lazy then return end -- No items
460 460
461 -- collapse reactions[occupant-id][reaction]boolean into reactions[reaction]integer
462 for n = 1, #logs do
463 local reactions = logs[n].reactions;
464 if reactions then
465 local collated = {};
466 for _, reacts in pairs(reactions) do
467 for reaction_text in pairs(reacts) do
468 collated[reaction_text] = (collated[reaction_text] or 0) + 1;
469 end
470 end
471 logs[n].reactions = collated;
472 end
473 end
474
461 local next_when, prev_when = "", ""; 475 local next_when, prev_when = "", "";
462 local date_list = archive.dates and archive:dates(room); 476 local date_list = archive.dates and archive:dates(room);
463 if date_list then 477 if date_list then
464 for j = 1, #date_list do 478 for j = 1, #date_list do
465 if date_list[j] == date then 479 if date_list[j] == date then