Changeset

12867:2defb0fc2be9

mod_admin_shell: Factor out room retrieval into common function Justification: See diffstat
author Kim Alvefur <zash@zash.se>
date Sun, 29 Jan 2023 17:55:56 +0100
parents 12866:54aea2622459
children 12868:d5cb86b84d12
files plugins/mod_admin_shell.lua
diffstat 1 files changed, 18 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_shell.lua	Sun Jan 29 17:53:21 2023 +0100
+++ b/plugins/mod_admin_shell.lua	Sun Jan 29 17:55:56 2023 +0100
@@ -1349,6 +1349,18 @@
 	return room_name, host;
 end
 
+local function get_muc(room_jid)
+	local room_name, host = check_muc(room_jid);
+	if not room_name then
+		return room_name, host;
+	end
+	local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
+	if not room_obj then
+		return nil, "No such room: "..room_jid;
+	end
+	return room_obj;
+end
+
 function def_env.muc:create(room_jid, config)
 	local room_name, host = check_muc(room_jid);
 	if not room_name then
@@ -1361,13 +1373,9 @@
 end
 
 function def_env.muc:room(room_jid)
-	local room_name, host = check_muc(room_jid);
-	if not room_name then
-		return room_name, host;
-	end
-	local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
+	local room_obj, err = get_muc(room_jid);
 	if not room_obj then
-		return nil, "No such room: "..room_jid;
+		return room_obj, err;
 	end
 	return setmetatable({ room = room_obj }, console_room_mt);
 end
@@ -1387,13 +1395,9 @@
 end
 
 function def_env.muc:occupants(room_jid, filter)
-	local room_name, host = check_muc(room_jid);
-	if not room_name then
-		return room_name, host;
-	end
-	local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
+	local room_obj, err = get_muc(room_jid);
 	if not room_obj then
-		return nil, "No such room: " .. room_jid;
+		return room_obj, err;
 	end
 
 	local print = self.session.print;
@@ -1415,13 +1419,9 @@
 end
 
 function def_env.muc:affiliations(room_jid, filter)
-	local room_name, host = check_muc(room_jid);
-	if not room_name then
-		return room_name, host;
-	end
-	local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid);
+	local room_obj, err = get_muc(room_jid);
 	if not room_obj then
-		return nil, "No such room: " .. room_jid;
+		return room_obj, err;
 	end
 
 	local print = self.session.print;