Annotate

plugins/groupchat.lua @ 473:b2198cd64c5a

disco: Add support for extended disco forms
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Mar 2023 11:12:01 +0000
parent 435:cf31a5ef8a9b
child 490:6b2f31da9610
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
250
a5ac643a7fd6 added local verse var to all plugins
mva <mva@mva.name>
parents: 231
diff changeset
1 local verse = require "verse";
418
40b8cc364274 verse.plugins.groupchat: Fix import of util.events
Kim Alvefur <zash@zash.se>
parents: 380
diff changeset
2 local events = require "util.events";
301
ffa55bc9396f plugins.groupchat: Import util.jid here too.
Kim Alvefur <zash@zash.se>
parents: 256
diff changeset
3 local jid = require "util.jid";
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local room_mt = {};
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 room_mt.__index = room_mt;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local xmlns_delay = "urn:xmpp:delay";
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local xmlns_muc = "http://jabber.org/protocol/muc";
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 function verse.plugins.groupchat(stream)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 stream:add_plugin("presence")
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 stream.rooms = {};
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 349
diff changeset
14
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 stream:hook("stanza", function (stanza)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local room_jid = jid.bare(stanza.attr.from);
187
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
17 if not room_jid then return end
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
18 local room = stream.rooms[room_jid]
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
19 if not room and stanza.attr.to and room_jid then
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
20 room = stream.rooms[stanza.attr.to.." "..room_jid]
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
21 end
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
22 if room and room.opts.source and stanza.attr.to ~= room.opts.source then return end
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 if room then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 local nick = select(3, jid.split(stanza.attr.from));
231
9712693ae40a plugins.groupchat: Use stanza:get_child_text()
Kim Alvefur <zash@zash.se>
parents: 215
diff changeset
25 local body = stanza:get_child_text("body");
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local delay = stanza:get_child("delay", xmlns_delay);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 local event = {
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 room_jid = room_jid;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 room = room;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 sender = room.occupants[nick];
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 nick = nick;
231
9712693ae40a plugins.groupchat: Use stanza:get_child_text()
Kim Alvefur <zash@zash.se>
parents: 215
diff changeset
32 body = body;
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 stanza = stanza;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 delay = (delay and delay.attr.stamp);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 };
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 local ret = room:event(stanza.name, event);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 return ret or (stanza.name == "message") or nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end, 500);
380
0891b4e27766 Discard trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 349
diff changeset
40
435
cf31a5ef8a9b verse.plugins.groupchat: Add support for MUC passwords https://xmpp.org/extensions/xep-0045.html#example-27
Seve Ferrer <seve@delape.net>
parents: 418
diff changeset
41 function stream:join_room(jid, nick, opts, password)
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 if not nick then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 return false, "no nickname supplied"
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 end
187
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
45 opts = opts or {};
349
dfcc5a0f5c79 plugins.groupchat: Use verse.eventable (room objects were missing :unhook() )
Matthew Wild <mwild1@gmail.com>
parents: 301
diff changeset
46 local room = setmetatable(verse.eventable{
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 stream = stream, jid = jid, nick = nick,
185
4f897d0e01c4 plugins.groupchat: Trying to get subject to behave properly
Kim Alvefur <zash@zash.se>
parents: 184
diff changeset
48 subject = nil,
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 occupants = {},
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
50 opts = opts,
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 }, room_mt);
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
52 if opts.source then
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
53 self.rooms[opts.source.." "..jid] = room;
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
54 else
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
55 self.rooms[jid] = room;
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
56 end
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 local occupants = room.occupants;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 room:hook("presence", function (presence)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 local nick = presence.nick or nick;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 if not occupants[nick] and presence.stanza.attr.type ~= "unavailable" then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 occupants[nick] = {
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 nick = nick;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 jid = presence.stanza.attr.from;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 presence = presence.stanza;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 };
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 local x = presence.stanza:get_child("x", xmlns_muc .. "#user");
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 if x then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 local x_item = x:get_child("item");
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 if x_item and x_item.attr then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 occupants[nick].real_jid = x_item.attr.jid;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 occupants[nick].affiliation = x_item.attr.affiliation;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 occupants[nick].role = x_item.attr.role;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 --TODO Check for status 100?
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 if nick == room.nick then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 room.stream:event("groupchat/joined", room);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 else
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 room:event("occupant-joined", occupants[nick]);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 elseif occupants[nick] and presence.stanza.attr.type == "unavailable" then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 if nick == room.nick then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 room.stream:event("groupchat/left", room);
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
84 if room.opts.source then
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
85 self.rooms[room.opts.source.." "..jid] = nil;
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
86 else
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
87 self.rooms[jid] = nil;
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
88 end
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 else
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 occupants[nick].presence = presence.stanza;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 room:event("occupant-left", occupants[nick]);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 occupants[nick] = nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 end);
215
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
96 room:hook("message", function(event)
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
97 local subject = event.stanza:get_child_text("subject");
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
98 if not subject then return end
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
99 subject = #subject > 0 and subject or nil;
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
100 if subject ~= room.subject then
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
101 local old_subject = room.subject;
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
102 room.subject = subject;
f86e0b0a0be3 plugins.groupchat: Improve room subject handling, add event
Kim Alvefur <zash@zash.se>
parents: 207
diff changeset
103 return room:event("subject-changed", { from = old_subject, to = subject, by = event.sender, event = event });
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 end
207
78f59d7b1ef7 plugins.groupchat: Bump topic change handling up a bit
Kim Alvefur <zash@zash.se>
parents: 197
diff changeset
105 end, 2000);
197
7e98cf2c1d8d plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents: 189
diff changeset
106 local join_st = verse.presence():tag("x",{xmlns = xmlns_muc}):reset();
435
cf31a5ef8a9b verse.plugins.groupchat: Add support for MUC passwords https://xmpp.org/extensions/xep-0045.html#example-27
Seve Ferrer <seve@delape.net>
parents: 418
diff changeset
107 if password then
cf31a5ef8a9b verse.plugins.groupchat: Add support for MUC passwords https://xmpp.org/extensions/xep-0045.html#example-27
Seve Ferrer <seve@delape.net>
parents: 418
diff changeset
108 join_st:get_child("x", xmlns_muc):tag("password"):text(password):reset();
cf31a5ef8a9b verse.plugins.groupchat: Add support for MUC passwords https://xmpp.org/extensions/xep-0045.html#example-27
Seve Ferrer <seve@delape.net>
parents: 418
diff changeset
109 end
184
8173e57522bf plugins.groupchat: Fix a missing `st.` and send join stanza regardless of return value from pre-join event.
Kim Alvefur <zash@zash.se>
parents: 182
diff changeset
110 self:event("pre-groupchat/joining", join_st);
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
111 room:send(join_st)
184
8173e57522bf plugins.groupchat: Fix a missing `st.` and send join stanza regardless of return value from pre-join event.
Kim Alvefur <zash@zash.se>
parents: 182
diff changeset
112 self:event("groupchat/joining", room);
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 return room;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 stream:hook("presence-out", function(presence)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 if not presence.attr.to then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118 for _, room in pairs(stream.rooms) do
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 room:send(presence);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121 presence.attr.to = nil;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 end);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 function room_mt:send(stanza)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 if stanza.name == "message" and not stanza.attr.type then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128 stanza.attr.type = "groupchat";
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 end
187
7ad218bd5fde plugins.groupchat: Fix prev commit.
Kim Alvefur <zash@zash.se>
parents: 186
diff changeset
130 if stanza.name == "presence" then
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
131 stanza.attr.to = self.jid .."/"..self.nick;
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
132 end
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 if stanza.attr.type == "groupchat" or not stanza.attr.to then
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 stanza.attr.to = self.jid;
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 end
186
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
136 if self.opts.source then
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
137 stanza.attr.from = self.opts.source
bb34b8bc00ae plugins.groupchat: Extra options. Route join presence through the room. Option to stamp from attr on outgoing stanzas (useful for components).
Kim Alvefur <zash@zash.se>
parents: 185
diff changeset
138 end
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 self.stream:send(stanza);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 function room_mt:send_message(text)
197
7e98cf2c1d8d plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents: 189
diff changeset
143 self:send(verse.message():tag("body"):text(text));
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 function room_mt:set_subject(text)
197
7e98cf2c1d8d plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents: 189
diff changeset
147 self:send(verse.message():tag("subject"):text(text));
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 function room_mt:leave(message)
189
033f1bd7420d plugins.groupchat: Fix self reference when leaving rooms
Kim Alvefur <zash@zash.se>
parents: 187
diff changeset
151 self.stream:event("groupchat/leaving", self);
252
7b36e4038377 verse.plugins.groupchat: Make last commit (7802a048) more concise
Matthew Wild <mwild1@gmail.com>
parents: 251
diff changeset
152 local presence = verse.presence({type="unavailable"});
251
e44ddcd84234 fixed sending of leave message
mva <mva@mva.name>
parents: 250
diff changeset
153 if message then
252
7b36e4038377 verse.plugins.groupchat: Make last commit (7802a048) more concise
Matthew Wild <mwild1@gmail.com>
parents: 251
diff changeset
154 presence:tag("status"):text(message);
256
cca89844cda7 plugins.groupchat: Fix missing 'end' in last commit
Matthew Wild <mwild1@gmail.com>
parents: 252
diff changeset
155 end
251
e44ddcd84234 fixed sending of leave message
mva <mva@mva.name>
parents: 250
diff changeset
156 self:send(presence);
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 function room_mt:admin_set(nick, what, value, reason)
197
7e98cf2c1d8d plugins.*: Use verse.stanza() & co instead of require util.stanza
Kim Alvefur <zash@zash.se>
parents: 189
diff changeset
160 self:send(verse.iq({type="set"})
182
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 :query(xmlns_muc .. "#admin")
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162 :tag("item", {nick = nick, [what] = value})
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 :tag("reason"):text(reason or ""));
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 function room_mt:set_role(nick, role, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 self:admin_set(nick, "role", role, reason);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 function room_mt:set_affiliation(nick, affiliation, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171 self:admin_set(nick, "affiliation", affiliation, reason);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 function room_mt:kick(nick, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 self:set_role(nick, "none", reason);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 end
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 function room_mt:ban(nick, reason)
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179 self:set_affiliation(nick, "outcast", reason);
51c0baa2bd19 plugins.groupchat: Adapt from Riddim
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 end