summaryrefslogtreecommitdiff
path: root/modules/mod_csi_on_away.lua
blob: 90a76a08325c8896ba340819e9123da0317e4a3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
local st = require "util.stanza";


-- Make sure we only load this module when CSI itself is deployed
module:depends("csi");


local function on_presence(event)
	if not event.origin.username then
		return nil;
	end

	local child = event.stanza:get_child("show");

	if child and child:get_text() == "away" then
		module:log("debug", "User is now away, simulating CSI.");
		module:fire_event("csi-client-inactive", event);
	else
		module:log("debug", "User is no longer away, ending simulated CSI.");
		module:fire_event("csi-client-active", event);
	end
end


-- outgoing
module:hook("pre-presence/bare", on_presence);
module:hook("pre-presence/full", on_presence);
module:hook("pre-presence/host", on_presence);