X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_message.lua;h=e38b60e60d6e00162933b3f6efc8c1bc48e5a206;hb=2368b4db6a01deba5be837a8791be3286a0d2dc6;hp=048a578dc1b2c9cbbdb8d9cd49e35bf609ab2c96;hpb=2367551c76847bb3e999d3931c2116dc4ea1e161;p=prosody.git diff --git a/plugins/mod_message.lua b/plugins/mod_message.lua index 048a578d..e38b60e6 100644 --- a/plugins/mod_message.lua +++ b/plugins/mod_message.lua @@ -1,3 +1,11 @@ +-- Prosody IM +-- Copyright (C) 2008-2010 Matthew Wild +-- Copyright (C) 2008-2010 Waqas Hussain +-- +-- This project is MIT/X11 licensed. Please see the +-- COPYING file in the source package for more information. +-- + local full_sessions = full_sessions; local bare_sessions = bare_sessions; @@ -9,24 +17,6 @@ local user_exists = require "core.usermanager".user_exists; local offlinemanager = require "core.offlinemanager"; local t_insert = table.insert; -local function select_top_resources(user) - local priority = 0; - local recipients = {}; - for _, session in pairs(user.sessions) do -- find resource with greatest priority - if session.presence then - -- TODO check active privacy list for session - local p = session.priority; - if p > priority then - priority = p; - recipients = {session}; - elseif p == priority then - t_insert(recipients, session); - end - end - end - return recipients; -end - local function process_to_bare(bare, origin, stanza) local user = bare_sessions[bare]; @@ -36,7 +26,7 @@ local function process_to_bare(bare, origin, stanza) elseif t == "groupchat" then origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); elseif t == "headline" then - if user then + if user and stanza.attr.to == bare then for _, session in pairs(user.sessions) do if session.presence and session.priority >= 0 then session.send(stanza); @@ -45,8 +35,8 @@ local function process_to_bare(bare, origin, stanza) end -- current policy is to discard headlines if no recipient is available else -- chat or normal message if user then -- some resources are connected - local recipients = select_top_resources(user); - if #recipients > 0 then + local recipients = user.top_resources; + if recipients then for i=1,#recipients do recipients[i].send(stanza); end @@ -85,3 +75,5 @@ module:hook("message/bare", function(data) return process_to_bare(stanza.attr.to or (origin.username..'@'..origin.host), origin, stanza); end); + +module:add_feature("msgoffline");