Mercurial > prosody-modules
comparison mod_muc_cloud_notify/mod_muc_cloud_notify.lua @ 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 | 408f92149774 |
| children | 3b8f4f3b1718 |
comparison
equal
deleted
inserted
replaced
| 3569:cc4f7361dac7 | 3570:8a93af85f319 |
|---|---|
| 438 end | 438 end |
| 439 end | 439 end |
| 440 return pushes; | 440 return pushes; |
| 441 end | 441 end |
| 442 | 442 |
| 443 local function extract_reference(text, i, j) | |
| 444 -- COMPAT w/ pre-Lua 5.3 | |
| 445 local c, pos, p1 = 0, 0, nil; | |
| 446 for char in text:gmatch("([%z\1-\127\194-\244][\128-\191]*)") do | |
| 447 c, pos = c + 1, pos + #char; | |
| 448 if not p1 and i < c then | |
| 449 p1 = pos; | |
| 450 end | |
| 451 if c == j then | |
| 452 return text:sub(p1, pos); | |
| 453 end | |
| 454 end | |
| 455 end | |
| 443 | 456 |
| 444 -- archive message added | 457 -- archive message added |
| 445 local function archive_message_added(event) | 458 local function archive_message_added(event) |
| 446 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id } | 459 -- event is: { origin = origin, stanza = stanza, for_user = store_user, id = id } |
| 447 -- only notify for new mam messages when at least one device is online | 460 -- only notify for new mam messages when at least one device is online |
| 449 local stanza = event.stanza; | 462 local stanza = event.stanza; |
| 450 local body = stanza:get_child_text('body'); | 463 local body = stanza:get_child_text('body'); |
| 451 | 464 |
| 452 for reference in stanza:childtags("reference", "urn:xmpp:reference:0") do | 465 for reference in stanza:childtags("reference", "urn:xmpp:reference:0") do |
| 453 if reference.attr['type'] == 'mention' and reference.attr['begin'] and reference.attr['end'] then | 466 if reference.attr['type'] == 'mention' and reference.attr['begin'] and reference.attr['end'] then |
| 454 local nick = body:sub(tonumber(reference.attr['begin'])+1, tonumber(reference.attr['end'])); | 467 local nick = extract_reference(body, reference.attr['begin'], reference.attr['end']); |
| 455 local jid = room:get_registered_jid(nick); | 468 local jid = room:get_registered_jid(nick); |
| 456 | 469 |
| 457 if room._occupants[room.jid..'/'..nick] then | 470 if room._occupants[room.jid..'/'..nick] then |
| 458 -- We only notify for members not currently in the room | 471 -- We only notify for members not currently in the room |
| 459 module:log("debug", "Not notifying %s, because he's currently in the room", jid); | 472 module:log("debug", "Not notifying %s, because he's currently in the room", jid); |
