comparison plugins/mod_groups.lua @ 6054:7a5ddbaf758d

Merge 0.9->0.10
author Matthew Wild <mwild1@gmail.com>
date Wed, 02 Apr 2014 17:41:38 +0100
parents bd0ff8ae98a8
children fccf340f4e1e
comparison
equal deleted inserted replaced
6053:2f93a04564b2 6054:7a5ddbaf758d
1 -- Prosody IM 1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild 2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain 3 -- Copyright (C) 2008-2010 Waqas Hussain
4 -- 4 --
5 -- This project is MIT/X11 licensed. Please see the 5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 9
15 local jid, datamanager = require "util.jid", require "util.datamanager"; 15 local jid, datamanager = require "util.jid", require "util.datamanager";
16 local jid_prep = jid.prep; 16 local jid_prep = jid.prep;
17 17
18 local module_host = module:get_host(); 18 local module_host = module:get_host();
19 19
20 function inject_roster_contacts(username, host, roster) 20 function inject_roster_contacts(event)
21 local username, host= event.username, event.host;
21 --module:log("debug", "Injecting group members to roster"); 22 --module:log("debug", "Injecting group members to roster");
22 local bare_jid = username.."@"..host; 23 local bare_jid = username.."@"..host;
23 if not members[bare_jid] and not members[false] then return; end -- Not a member of any groups 24 if not members[bare_jid] and not members[false] then return; end -- Not a member of any groups
24 25
26 local roster = event.roster;
25 local function import_jids_to_roster(group_name) 27 local function import_jids_to_roster(group_name)
26 for jid in pairs(groups[group_name]) do 28 for jid in pairs(groups[group_name]) do
27 -- Add them to roster 29 -- Add them to roster
28 --module:log("debug", "processing jid %s in group %s", tostring(jid), tostring(group_name)); 30 --module:log("debug", "processing jid %s in group %s", tostring(jid), tostring(group_name));
29 if jid ~= bare_jid then 31 if jid ~= bare_jid then
46 for _, group_name in ipairs(members[bare_jid]) do 48 for _, group_name in ipairs(members[bare_jid]) do
47 --module:log("debug", "Importing group %s", group_name); 49 --module:log("debug", "Importing group %s", group_name);
48 import_jids_to_roster(group_name); 50 import_jids_to_roster(group_name);
49 end 51 end
50 end 52 end
51 53
52 -- Import public groups 54 -- Import public groups
53 if members[false] then 55 if members[false] then
54 for _, group_name in ipairs(members[false]) do 56 for _, group_name in ipairs(members[false]) do
55 --module:log("debug", "Importing group %s", group_name); 57 --module:log("debug", "Importing group %s", group_name);
56 import_jids_to_roster(group_name); 58 import_jids_to_roster(group_name);
57 end 59 end
58 end 60 end
59 61
60 if roster[false] then 62 if roster[false] then
61 roster[false].version = true; 63 roster[false].version = true;
62 end 64 end
63 end 65 end
64 66
80 end 82 end
81 83
82 function module.load() 84 function module.load()
83 groups_file = module:get_option_string("groups_file"); 85 groups_file = module:get_option_string("groups_file");
84 if not groups_file then return; end 86 if not groups_file then return; end
85 87
86 module:hook("roster-load", inject_roster_contacts); 88 module:hook("roster-load", inject_roster_contacts);
87 datamanager.add_callback(remove_virtual_contacts); 89 datamanager.add_callback(remove_virtual_contacts);
88 90
89 groups = { default = {} }; 91 groups = { default = {} };
90 members = { }; 92 members = { };
91 local curr_group = "default"; 93 local curr_group = "default";
92 for line in io.lines(groups_file) do 94 for line in io.lines(groups_file) do
93 if line:match("^%s*%[.-%]%s*$") then 95 if line:match("^%s*%[.-%]%s*$") then