Mercurial > prosody-hg
comparison util/pubsub.lua @ 4366:b6c18cadd3ec
util.pubsub: Add service:remove_all_subscriptions()
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 30 Aug 2011 15:48:16 -0400 |
| parents | 6704b3cd032e |
| children | 98b258b7d5dc |
comparison
equal
deleted
inserted
replaced
| 4365:6704b3cd032e | 4366:b6c18cadd3ec |
|---|---|
| 166 if next(subs) == nil then | 166 if next(subs) == nil then |
| 167 self.subscriptions[normal_jid] = nil; | 167 self.subscriptions[normal_jid] = nil; |
| 168 end | 168 end |
| 169 end | 169 end |
| 170 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); | 170 self.events.fire_event("subscription-removed", { node = node, jid = jid, normalized_jid = normal_jid }); |
| 171 return true; | |
| 172 end | |
| 173 | |
| 174 function service:remove_all_subscriptions(actor, jid) | |
| 175 -- Access checking | |
| 176 local cap; | |
| 177 if actor == true or jid == actor or self:jids_equal(actor, jid) then | |
| 178 cap = "unsubscribe"; | |
| 179 else | |
| 180 cap = "unsubscribe_other"; | |
| 181 end | |
| 182 if not self:may(node, actor, cap) then | |
| 183 return false, "forbidden"; | |
| 184 end | |
| 185 if not self:may(node, jid, "be_unsubscribed") then | |
| 186 return false, "forbidden"; | |
| 187 end | |
| 188 -- | |
| 189 local normal_jid = self.config.normalize_jid(jid); | |
| 190 local subs = self.subscriptions[normal_jid] | |
| 191 subs = subs and subs[jid]; | |
| 192 if subs then | |
| 193 for node in pairs(subs) do | |
| 194 self:remove_subscription(node, true, jid); | |
| 195 end | |
| 196 end | |
| 171 return true; | 197 return true; |
| 172 end | 198 end |
| 173 | 199 |
| 174 function service:get_subscription(node, actor, jid) | 200 function service:get_subscription(node, actor, jid) |
| 175 -- Access checking | 201 -- Access checking |
