plugins/mod_privacy.lua

changeset 2616
58148ad08af5
parent 2615
c5f7c803fe7d
child 2925
692b3c6c5bd2
equal deleted inserted replaced
2615:c5f7c803fe7d 2616:58148ad08af5
63 origin.send(presence); 63 origin.send(presence);
64 end 64 end
65 end 65 end
66 end 66 end
67 67
68 function sendNeededUnavailablePersences(origin, listnameOrItem) -- TODO implement it correctly!
69 if type(listnameOrItem) == "string" then
70 local listname = listnameOrItem;
71 for _,list in ipairs(privacy_lists.lists) do
72 if list.name == listname then
73 for _,item in ipairs(list.items) do
74 sendNeededUnavailablePersences(origin, item);
75 end
76 end
77 end
78 elseif type(listnameOrItem) == "table" then
79 module:log("debug", "got an item, check whether to send unavailable presence stanza or not");
80 local item = listnameOrItem;
81
82 if item["presence-out"] == true then
83 if item.type == "jid" then
84 sendUnavailable(origin, item.value, origin.full_jid);
85 elseif item.type == "group" then
86 elseif item.type == "subscription" then
87 elseif item.type == nil then
88 end
89 elseif item["presence-in"] == true then
90 if item.type == "jid" then
91 sendUnavailable(origin, origin.full_jid, item.value);
92 elseif item.type == "group" then
93 elseif item.type == "subscription" then
94 elseif item.type == nil then
95 end
96 end
97 else
98 module:log("debug", "got unknown type: %s", type(listnameOrItem));
99 end
100 end
101
102 function declineList(privacy_lists, origin, stanza, which) 68 function declineList(privacy_lists, origin, stanza, which)
103 if which == "default" then 69 if which == "default" then
104 if isAnotherSessionUsingDefaultList(origin) then 70 if isAnotherSessionUsingDefaultList(origin) then
105 return { "cancel", "conflict", "Another session is online and using the default list."}; 71 return { "cancel", "conflict", "Another session is online and using the default list."};
106 end 72 end
122 if isAnotherSessionUsingDefaultList(origin) then 88 if isAnotherSessionUsingDefaultList(origin) then
123 return {"cancel", "conflict", "Another session is online and using the default list."}; 89 return {"cancel", "conflict", "Another session is online and using the default list."};
124 end 90 end
125 privacy_lists.default = name; 91 privacy_lists.default = name;
126 origin.send(st.reply(stanza)); 92 origin.send(st.reply(stanza));
127 --[[
128 if origin.activePrivacyList == nil then
129 sendNeededUnavailablePersences(origin, name);
130 end
131 ]]--
132 elseif which == "active" and list then 93 elseif which == "active" and list then
133 origin.activePrivacyList = name; 94 origin.activePrivacyList = name;
134 origin.send(st.reply(stanza)); 95 origin.send(st.reply(stanza));
135 -- sendNeededUnavailablePersences(origin, name);
136 else 96 else
137 return {"modify", "bad-request", "Either not active or default given or unknown list name specified."}; 97 return {"modify", "bad-request", "Either not active or default given or unknown list name specified."};
138 end 98 end
139 return true; 99 return true;
140 end 100 end
229 end 189 end
230 190
231 if tmp.action ~= "deny" and tmp.action ~= "allow" then 191 if tmp.action ~= "deny" and tmp.action ~= "allow" then
232 return {"cancel", "bad-request", "Action must be either deny or allow."}; 192 return {"cancel", "bad-request", "Action must be either deny or allow."};
233 end 193 end
234
235 --[[
236 if (privacy_lists.default == name and origin.activePrivacyList == nil) or origin.activePrivacyList == name then
237 module:log("debug", "calling sendNeededUnavailablePresences!");
238 -- item is valid and list is active, so send needed unavailable stanzas
239 sendNeededUnavailablePersences(origin, tmp);
240 end
241 ]]--
242 list.items[#list.items + 1] = tmp; 194 list.items[#list.items + 1] = tmp;
243 end 195 end
244 196
245 table.sort(list, function(a, b) return a.order < b.order; end); 197 table.sort(list, function(a, b) return a.order < b.order; end);
246 198

mercurial