mod_muc: The default room name is the room node
[prosody.git] / plugins / mod_muc.lua
index 0a4a7b71e12a72e59d14b547c66c319a12ee8b15..6af5df7c750dbc9db2b8695d780eb05a00614026 100644 (file)
@@ -1,4 +1,4 @@
--- Prosody IM v0.3
+-- Prosody IM v0.4
 -- Copyright (C) 2008-2009 Matthew Wild
 -- Copyright (C) 2008-2009 Waqas Hussain
 -- 
@@ -259,7 +259,7 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
                                        end
                                else -- possible rejoin
                                        log("debug", "%s had connection replaced", current_nick);
-                                       handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}):tag('status'):text('Replaced by new connection')); -- send unavailable
+                                       handle_to_occupant(origin, st.presence({type='unavailable', from=from, to=to}):tag('status'):text('Replaced by new connection'):up()); -- send unavailable
                                        handle_to_occupant(origin, stanza); -- resend available
                                end
                        else -- enter room
@@ -274,6 +274,7 @@ function handle_to_occupant(origin, stanza) -- PM, vCards, etc
                                        log("debug", "%s joining as %s", from, to);
                                        local data;
                                        if not rooms:get(room) and not rooms_info:get(room) then -- new room
+                                               rooms_info:set(room, 'name', (jid_split(room)));
                                                data = {affiliation='owner', role='moderator', jid=from, sessions={[from]=get_filtered_presence(stanza)}};
                                        end
                                        if not data then -- new occupant
@@ -369,6 +370,16 @@ function handle_to_room(origin, stanza) -- presence changes and groupchat messag
                elseif type ~= "error" and type ~= "result" then
                        origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
                end
+       elseif stanza.name == "message" and not stanza.attr.type and #stanza.tags == 1 and jid_nick:get(stanza.attr.from, stanza.attr.to)
+               and stanza.tags[1].name == "x" and stanza.tags[1].attr.xmlns == "http://jabber.org/protocol/muc#user" and #stanza.tags[1].tags == 1
+               and stanza.tags[1].tags[1].name == "invite" and stanza.tags[1].tags[1].attr.to then
+               local _from, _to = stanza.attr.from, stanza.attr.to;
+               local _invitee = stanza.tags[1].tags[1].attr.to;
+               stanza.attr.from, stanza.attr.to = _to, _invitee;
+               stanza.tags[1].tags[1].attr.from, stanza.tags[1].tags[1].attr.to = _from, nil;
+               core_route_stanza(component, stanza);
+               stanza.tags[1].tags[1].attr.from, stanza.tags[1].tags[1].attr.to = nil, _invitee;
+               stanza.attr.from, stanza.attr.to = _from, _to;
        else
                if type == "error" or type == "result" then return; end
                origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));