comparison mod_muc_badge/mod_muc_badge.lua @ 4982:8a4b17e2e984

mod_muc_badge: If room has no title use localpart of room's jid (fixes #1767) Without this patch Prosody shows an HTTP 500 error (Lua 5.1) or a "nil" label in the SVG badge (Lua 5.2) if room has no title set.
author Citronalco <geierb@geierb.de>
date Tue, 02 Aug 2022 23:45:00 +0200
parents 4d1f6d47c889
children
comparison
equal deleted inserted replaced
4981:f0fe95f9e21c 4982:8a4b17e2e984
21 -- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 -- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 22
23 module:depends"http"; 23 module:depends"http";
24 24
25 local jid_prep = require "util.jid".prep; 25 local jid_prep = require "util.jid".prep;
26 local jid_split = require "util.jid".split;
26 27
27 -- Support both old and new MUC code 28 -- Support both old and new MUC code
28 local mod_muc = module:depends"muc"; 29 local mod_muc = module:depends"muc";
29 local rooms = rawget(mod_muc, "rooms"); 30 local rooms = rawget(mod_muc, "rooms");
30 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or 31 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
74 75
75 local count = 0; 76 local count = 0;
76 for _ in pairs(room._occupants) do 77 for _ in pairs(room._occupants) do
77 count = count + 1; 78 count = count + 1;
78 end 79 end
79 local badge_label = (" %s "):format(room:get_name()); 80 local badge_label = (" %s "):format(room:get_name() or jid_split(jid));
80 local badge_count = (" %s "):format(string.format(number, count)); 81 local badge_count = (" %s "):format(string.format(number, count));
81 82
82 local response = event.response; 83 local response = event.response;
83 response.headers.content_type = "image/svg+xml"; 84 response.headers.content_type = "image/svg+xml";
84 local svg = [[<?xml version="1.0"?>]] .. 85 local svg = [[<?xml version="1.0"?>]] ..