Software / code / prosody
Comparison
plugins/mod_groups.lua @ 5776:bd0ff8ae98a8
Remove all trailing whitespace
| author | Florian Zeitz <florob@babelmonkeys.de> |
|---|---|
| date | Fri, 09 Aug 2013 17:48:21 +0200 |
| parent | 5747:23076ee191d3 |
| child | 7128:fccf340f4e1e |
comparison
equal
deleted
inserted
replaced
| 5775:a6c2b8933507 | 5776:bd0ff8ae98a8 |
|---|---|
| 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 |
| 20 function inject_roster_contacts(event) | 20 function inject_roster_contacts(event) |
| 21 local username, host= event.username, event.host; | 21 local username, host= event.username, event.host; |
| 22 --module:log("debug", "Injecting group members to roster"); | 22 --module:log("debug", "Injecting group members to roster"); |
| 23 local bare_jid = username.."@"..host; | 23 local bare_jid = username.."@"..host; |
| 24 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 |
| 25 | 25 |
| 26 local roster = event.roster; | 26 local roster = event.roster; |
| 27 local function import_jids_to_roster(group_name) | 27 local function import_jids_to_roster(group_name) |
| 28 for jid in pairs(groups[group_name]) do | 28 for jid in pairs(groups[group_name]) do |
| 29 -- Add them to roster | 29 -- Add them to roster |
| 30 --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)); |
| 48 for _, group_name in ipairs(members[bare_jid]) do | 48 for _, group_name in ipairs(members[bare_jid]) do |
| 49 --module:log("debug", "Importing group %s", group_name); | 49 --module:log("debug", "Importing group %s", group_name); |
| 50 import_jids_to_roster(group_name); | 50 import_jids_to_roster(group_name); |
| 51 end | 51 end |
| 52 end | 52 end |
| 53 | 53 |
| 54 -- Import public groups | 54 -- Import public groups |
| 55 if members[false] then | 55 if members[false] then |
| 56 for _, group_name in ipairs(members[false]) do | 56 for _, group_name in ipairs(members[false]) do |
| 57 --module:log("debug", "Importing group %s", group_name); | 57 --module:log("debug", "Importing group %s", group_name); |
| 58 import_jids_to_roster(group_name); | 58 import_jids_to_roster(group_name); |
| 59 end | 59 end |
| 60 end | 60 end |
| 61 | 61 |
| 62 if roster[false] then | 62 if roster[false] then |
| 63 roster[false].version = true; | 63 roster[false].version = true; |
| 64 end | 64 end |
| 65 end | 65 end |
| 66 | 66 |
| 82 end | 82 end |
| 83 | 83 |
| 84 function module.load() | 84 function module.load() |
| 85 groups_file = module:get_option_string("groups_file"); | 85 groups_file = module:get_option_string("groups_file"); |
| 86 if not groups_file then return; end | 86 if not groups_file then return; end |
| 87 | 87 |
| 88 module:hook("roster-load", inject_roster_contacts); | 88 module:hook("roster-load", inject_roster_contacts); |
| 89 datamanager.add_callback(remove_virtual_contacts); | 89 datamanager.add_callback(remove_virtual_contacts); |
| 90 | 90 |
| 91 groups = { default = {} }; | 91 groups = { default = {} }; |
| 92 members = { }; | 92 members = { }; |
| 93 local curr_group = "default"; | 93 local curr_group = "default"; |
| 94 for line in io.lines(groups_file) do | 94 for line in io.lines(groups_file) do |
| 95 if line:match("^%s*%[.-%]%s*$") then | 95 if line:match("^%s*%[.-%]%s*$") then |