Mercurial > prosody-hg
comparison plugins/muc/subject.lib.lua @ 8929:415b2e9d8ba8
MUC: Record timestamp of subject changes and stamp delay tag later
Thanks whoever mentioned this. Can't find who it was now.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 26 Jun 2018 02:24:56 +0200 |
| parents | d41f8ce67c8e |
| children | 2e45b1b47918 |
comparison
equal
deleted
inserted
replaced
| 8928:d41f8ce67c8e | 8929:415b2e9d8ba8 |
|---|---|
| 6 -- This project is MIT/X11 licensed. Please see the | 6 -- This project is MIT/X11 licensed. Please see the |
| 7 -- COPYING file in the source package for more information. | 7 -- COPYING file in the source package for more information. |
| 8 -- | 8 -- |
| 9 | 9 |
| 10 local st = require "util.stanza"; | 10 local st = require "util.stanza"; |
| 11 local dt = require "util.datetime"; | |
| 11 | 12 |
| 12 local muc_util = module:require "muc/util"; | 13 local muc_util = module:require "muc/util"; |
| 13 local valid_roles = muc_util.valid_roles; | 14 local valid_roles = muc_util.valid_roles; |
| 14 | 15 |
| 15 local function create_subject_message(subject, from) | 16 local function create_subject_message(subject, from) |
| 54 local function get_subject(room) | 55 local function get_subject(room) |
| 55 -- a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject) | 56 -- a <message/> stanza from the room JID (or from the occupant JID of the entity that set the subject) |
| 56 return room._data.subject, room._data.subject_from or room.jid; | 57 return room._data.subject, room._data.subject_from or room.jid; |
| 57 end | 58 end |
| 58 | 59 |
| 59 local function send_subject(room, to) | 60 local function send_subject(room, to, time) |
| 60 local msg = create_subject_message(get_subject(room)); | 61 local msg = create_subject_message(get_subject(room)); |
| 61 msg.attr.to = to; | 62 msg.attr.to = to; |
| 63 if time then | |
| 64 msg:tag("delay", { | |
| 65 xmlns = "urn:xmpp:delay", | |
| 66 from = room.jid, | |
| 67 stamp = dt.datetime(time); | |
| 68 }):up(); | |
| 69 end | |
| 62 room:route_stanza(msg); | 70 room:route_stanza(msg); |
| 63 end | 71 end |
| 64 | 72 |
| 65 local function set_subject(room, subject, from) | 73 local function set_subject(room, subject, from) |
| 66 if subject == "" then subject = nil; end | 74 if subject == "" then subject = nil; end |
| 67 local old_subject, old_from = get_subject(room); | 75 local old_subject, old_from = get_subject(room); |
| 68 if old_subject == subject and old_from == from then return false; end | 76 if old_subject == subject and old_from == from then return false; end |
| 69 room._data.subject_from = from; | 77 room._data.subject_from = from; |
| 70 room._data.subject = subject; | 78 room._data.subject = subject; |
| 79 room._data.subject_time = os.time(); | |
| 71 local msg = create_subject_message(subject, from); | 80 local msg = create_subject_message(subject, from); |
| 72 room:broadcast_message(msg); | 81 room:broadcast_message(msg); |
| 73 return true; | 82 return true; |
| 74 end | 83 end |
| 75 | 84 |
| 76 -- Send subject to joining user | 85 -- Send subject to joining user |
| 77 module:hook("muc-occupant-session-new", function(event) | 86 module:hook("muc-occupant-session-new", function(event) |
| 78 send_subject(event.room, event.stanza.attr.from); | 87 send_subject(event.room, event.stanza.attr.from, event.room._data.subject_time); |
| 79 end, 20); | 88 end, 20); |
| 80 | 89 |
| 81 -- Prosody has made the decision that messages with <subject/> are exclusively subject changes | 90 -- Prosody has made the decision that messages with <subject/> are exclusively subject changes |
| 82 -- e.g. body will be ignored; even if the subject change was not allowed | 91 -- e.g. body will be ignored; even if the subject change was not allowed |
| 83 module:hook("muc-occupant-groupchat", function(event) | 92 module:hook("muc-occupant-groupchat", function(event) |
