-function broadcast_presence(type, from, room, code, newnick)
- local data = rooms:get(room, from);
- local stanza = st.presence({type=type, from=from})
- :tag("x", {xmlns='http://jabber.org/protocol/muc#user'})
- :tag("item", {affiliation=data.affiliation, role=data.role, nick = newnick}):up();
- if code then
- stanza:tag("status", {code=code}):up();
- end
- local me;
- local r = rooms:get(room);
- if r then
- for occupant, o_data in pairs(r) do
- if occupant ~= from then
- stanza.attr.to = o_data.jid;
- core_route_stanza(component, stanza);
- else
- me = o_data.jid;
- end
- end
- end
- if me then
- stanza:tag("status", {code='110'});
- stanza.attr.to = me;
- core_route_stanza(component, stanza);
- end
-end
-function broadcast_message(from, room, subject, body)
- local stanza = st.message({type='groupchat', from=from});
- if subject then stanza:tag('subject'):text(subject):up(); end
- if body then stanza:tag('body'):text(body):up(); end
- local r = rooms:get(room);
- if r then
- for occupant, o_data in pairs(r) do
- stanza.attr.to = o_data.jid;
- core_route_stanza(component, stanza);
- end
- if not subject and body then -- add to history
- local history = rooms_info:get(room, 'history');
- if not history then history = {}; rooms_info:set(room, 'history', history); end
- -- stanza = st.deserialize(st.preserialize(stanza));
- stanza:tag("delay", {xmlns = "urn:xmpp:delay", from = muc_domain, stamp = datetime.datetime()}):up(); -- XEP-0203
- stanza:tag("x", {xmlns = "jabber:x:delay", from = muc_domain, stamp = datetime.legacy()}):up(); -- XEP-0091 (deprecated)
- t_insert(history, st.preserialize(stanza));
- while #history > history_length do t_remove(history, 1) end
- end
- end
-end