mod_muc: Extracted history broadcast into its own function

Fri, 08 May 2009 01:14:01 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Fri, 08 May 2009 01:14:01 +0500
changeset 1138
0310a0f5ce3a
parent 1137
4a39a6d503d0
child 1139
ed4d43c3eaf2

mod_muc: Extracted history broadcast into its own function

plugins/mod_muc.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_muc.lua	Fri May 08 01:09:07 2009 +0500
+++ b/plugins/mod_muc.lua	Fri May 08 01:14:01 2009 +0500
@@ -205,6 +205,19 @@
 		end
 	end
 end
+function broadcast_history(room, to)
+	local history = rooms_info:get(room, 'history'); -- send discussion history
+	if history then
+		for _, msg in ipairs(history) do
+			msg = st.deserialize(msg);
+			msg.attr.to=to;
+			core_route_stanza(component, msg);
+		end
+	end
+	if rooms_info:get(room, 'subject') then
+		core_route_stanza(component, st.message({type='groupchat', from=room, to=to}):tag("subject"):text(rooms_info:get(room, 'subject')));
+	end
+end
 
 function handle_to_occupant(origin, stanza) -- PM, vCards, etc
 	local from, to = stanza.attr.from, stanza.attr.to;
@@ -298,17 +311,7 @@
 					end
 					pr.attr.from = to;
 					broadcast_presence_stanza(room, pr);
-					local history = rooms_info:get(room, 'history'); -- send discussion history
-					if history then
-						for _, msg in ipairs(history) do
-							msg = st.deserialize(msg);
-							msg.attr.to=from;
-							core_route_stanza(component, msg);
-						end
-					end
-					if rooms_info:get(room, 'subject') then
-						core_route_stanza(component, st.message({type='groupchat', from=room, to=from}):tag("subject"):text(rooms_info:get(room, 'subject')));
-					end
+					broadcast_history(room, from);
 				end
 			end
 		elseif type ~= 'result' then -- bad type

mercurial