X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_message.lua;h=e38b60e60d6e00162933b3f6efc8c1bc48e5a206;hb=ff53626e693ddb540f718f4ff7d7e9d63a3eca08;hp=621d56600953f665d60989d26b77449aba37eec3;hpb=fe6577210307a6a75ee082122774f6d43b5ebd2e;p=prosody.git diff --git a/plugins/mod_message.lua b/plugins/mod_message.lua index 621d5660..e38b60e6 100644 --- a/plugins/mod_message.lua +++ b/plugins/mod_message.lua @@ -1,28 +1,21 @@ +-- 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; +local st = require "util.stanza"; local jid_bare = require "util.jid".bare; +local jid_split = require "util.jid".split; local user_exists = require "core.usermanager".user_exists; local offlinemanager = require "core.offlinemanager"; - -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 t_insert = table.insert; local function process_to_bare(bare, origin, stanza) local user = bare_sessions[bare]; @@ -33,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); @@ -42,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 @@ -82,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");