From d3db6ff3baeb1e8b4e8ff442b000c594d22b2645 Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Sun, 8 Jul 2018 04:17:54 +0200
Subject: MUC/password: Set room password on creation if included in join
 stanza

This fixes room creation/joining from Gajim if a password has been set.

Otherwise the muc-occupant-pre-join event hook determines that the given
password differs from the unset password and joining is rejected, which
seems unhelpful.
---
 plugins/muc/password.lib.lua | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'plugins')

diff --git a/plugins/muc/password.lib.lua b/plugins/muc/password.lib.lua
index 7edab767..fb603d88 100644
--- a/plugins/muc/password.lib.lua
+++ b/plugins/muc/password.lib.lua
@@ -65,6 +65,14 @@ module:hook("muc-invite", function(event)
 	end
 end);
 
+module:hook("muc-room-pre-create", function (event)
+	local stanza, room = event.stanza, event.room;
+	local muc_x = stanza:get_child("x", "http://jabber.org/protocol/muc");
+	if not muc_x then return end
+	local password = muc_x:get_child_text("password", "http://jabber.org/protocol/muc");
+	set_password(room, password);
+end);
+
 return {
 	get = get_password;
 	set = set_password;
-- 
cgit v1.2.3