# HG changeset patch # User Matthew Wild # Date 1556826185 -3600 # Node ID 8a93af85f3190c54417da5d595aafdb906443881 # Parent cc4f7361dac76de7f25d888ab123efb2d98ed2ff mod_muc_cloud_notify: Count codepoints instead of bytes Still marked as a 'TODO' in XEP-0372, but Converse.js is counting codepoints, and rough consensus is that this is the easiest approach in the widest range of environments. diff -r cc4f7361dac7 -r 8a93af85f319 mod_muc_cloud_notify/mod_muc_cloud_notify.lua --- a/mod_muc_cloud_notify/mod_muc_cloud_notify.lua Mon Apr 22 04:20:16 2019 +0200 +++ b/mod_muc_cloud_notify/mod_muc_cloud_notify.lua Thu May 02 20:43:05 2019 +0100 @@ -440,6 +440,19 @@ return pushes; end +local function extract_reference(text, i, j) + -- COMPAT w/ pre-Lua 5.3 + local c, pos, p1 = 0, 0, nil; + for char in text:gmatch("([%z\1-\127\194-\244][\128-\191]*)") do + c, pos = c + 1, pos + #char; + if not p1 and i < c then + p1 = pos; + end + if c == j then + return text:sub(p1, pos); + end + end +end -- archive message added local function archive_message_added(event) @@ -451,7 +464,7 @@ for reference in stanza:childtags("reference", "urn:xmpp:reference:0") do if reference.attr['type'] == 'mention' and reference.attr['begin'] and reference.attr['end'] then - local nick = body:sub(tonumber(reference.attr['begin'])+1, tonumber(reference.attr['end'])); + local nick = extract_reference(body, reference.attr['begin'], reference.attr['end']); local jid = room:get_registered_jid(nick); if room._occupants[room.jid..'/'..nick] then