Mercurial > prosody-modules
changeset 3570:8a93af85f319
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.
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 02 May 2019 20:43:05 +0100 |
parents | cc4f7361dac7 |
children | f5ea0b886c7c |
files | mod_muc_cloud_notify/mod_muc_cloud_notify.lua |
diffstat | 1 files changed, 14 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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