# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1639831437 -3600
# Node ID 85c8fcb4192e770324ca45cd52dc85d696a37e4d
# Parent  e662c172ea0f4d07cd9f162fbe34962634695394
mod_c2s: Fire pre-closing event regardless of connected state

With mod_smacks, a session can outlive the connection, so whether the
event is fired should not hinge on whether the session is connected or
not.

Helps mod_smacks remove some state.

diff -r e662c172ea0f -r 85c8fcb4192e plugins/mod_c2s.lua
--- a/plugins/mod_c2s.lua	Sat Dec 18 12:50:53 2021 +0100
+++ b/plugins/mod_c2s.lua	Sat Dec 18 13:43:57 2021 +0100
@@ -186,13 +186,13 @@
 --- Session methods
 local function session_close(session, reason)
 	local log = session.log or log;
+	local close_event_payload = { session = session, reason = reason };
+	module:context(session.host):fire_event("pre-session-close", close_event_payload);
+	reason = close_event_payload.reason;
 	if session.conn then
 		if session.notopen then
 			session:open_stream();
 		end
-		local close_event_payload = { session = session, reason = reason };
-		module:context(session.host):fire_event("pre-session-close", close_event_payload);
-		reason = close_event_payload.reason;
 		if reason then -- nil == no err, initiated by us, false == initiated by client
 			local stream_error = st.stanza("stream:error");
 			if type(reason) == "string" then -- assume stream error