Files
vnctalk-prosody/vnctalk/mod_vnc_receipts.lua
T

60 lines
2.3 KiB
Lua

-- Prosody IM
-- Copyright (C) 2008-2017 Matthew Wild
-- Copyright (C) 2008-2017 Waqas Hussain
-- Copyright (C) 2011-2017 Kim Alvefur
-- Copyright (C) 2011-2017 Stefan Sänger
--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
-- store receipts based on mod_mam
--
local um = require "core.usermanager";
local st = require "util.stanza";
local rsm = require "util.rsm";
local jid_bare = require "util.jid".bare;
local jid_split = require "util.jid".split;
local jid_prepped_split = require "util.jid".prepped_split;
local host = module.host;
local is_stanza = st.is_stanza;
local tostring = tostring;
local time_now = os.time;
local m_min = math.min;
local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
local receipt_store = module:open_store("receipts", "archive");
-- Handle messages
local function message_handler(event, c2s)
local origin, stanza = event.origin, event.stanza;
local log = c2s and origin.log or module._log;
local orig_type = stanza.attr.type or "normal";
local orig_from = stanza.attr.from;
local orig_to = stanza.attr.to or orig_from;
-- Stanza without 'to' are treated as if it was to their own bare jid
local received_child = stanza:get_child("received", "urn:xmpp:receipts");
if received_child then
local received_test=tostring(received_child);
local received_id = received_child.attr.id;
local receipt_user = jid_split(orig_to);
local receipt_with = jid_bare(orig_from);
local receiptxml = "<received id=\""..received_id.."\" />";
if jid_bare(orig_from) ~= jid_bare(orig_to) then
-- local receiptok = receipt_store:append(receipt_user, nil, received_id, time_now(), receipt_with);
local receiptok = receipt_store:append(receipt_user, nil, receiptxml, time_now(), receipt_with);
-- log("info", "receipt for id: %s from %s to %s", received_id, jid_bare(orig_from), jid_bare(orig_to));
else
log("debug", "not storing receipt for id: %s from %s to %s", received_id, jid_bare(orig_from), jid_bare(orig_to));
end
else
log("debug", "not stored receipt - no receipt-id in message from %s to %s", jid_bare(orig_from), jid_bare(orig_to));
end
end
-- Stanzas to local clients
module:hook("message/bare", message_handler, 0);
module:hook("message/full", message_handler, 0);