From: Brion Vibber Date: Tue, 15 Mar 2011 19:49:17 +0000 (-0700) Subject: Add StartNoticeWhoGets, EndNoticeWhoGets events to allow upcoming TagSub plugin to... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b66250c6aa2d04aa1a7c15bf385a73397589e78d;p=quix0rs-gnu-social.git Add StartNoticeWhoGets, EndNoticeWhoGets events to allow upcoming TagSub plugin to do extra inbox delivery. --- diff --git a/EVENTS.txt b/EVENTS.txt index 1443a94fbe..54d06655ee 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1131,3 +1131,11 @@ StartActivityObjectOutputJson: Called at start of JSON output generation for Act EndActivityObjectOutputJson: Called at end of JSON output generation for ActivityObject chunks: the array has not yet been filled out. - $obj ActivityObject - &$out: array to be serialized; you're free to modify it + +StartNoticeWhoGets: Called at start of inbox delivery prep; plugins can schedule notices to go to particular profiles that would otherwise not have reached them. Canceling will take over the entire addressing operation. Be aware that output can be cached or used several times, so should remain idempotent. +- $notice Notice +- &$ni: in/out array mapping profile IDs to constants: NOTICE_INBOX_SOURCE_SUB etc + +EndNoticeWhoGets: Called at end of inbox delivery prep; plugins can filter out profiles from receiving inbox delivery here. Be aware that output can be cached or used several times, so should remain idempotent. +- $notice Notice +- &$ni: in/out array mapping profile IDs to constants: NOTICE_INBOX_SOURCE_SUB etc diff --git a/classes/Notice.php b/classes/Notice.php index d520f4728f..e5c758005d 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -812,41 +812,48 @@ class Notice extends Memcached_DataObject $ni = array(); - foreach ($users as $id) { - $ni[$id] = NOTICE_INBOX_SOURCE_SUB; - } + // Give plugins a chance to add folks in at start... + if (Event::handle('StartNoticeWhoGets', array($this, &$ni))) { - foreach ($groups as $group) { - $users = $group->getUserMembers(); foreach ($users as $id) { - if (!array_key_exists($id, $ni)) { - $ni[$id] = NOTICE_INBOX_SOURCE_GROUP; + $ni[$id] = NOTICE_INBOX_SOURCE_SUB; + } + + foreach ($groups as $group) { + $users = $group->getUserMembers(); + foreach ($users as $id) { + if (!array_key_exists($id, $ni)) { + $ni[$id] = NOTICE_INBOX_SOURCE_GROUP; + } } } - } - foreach ($recipients as $recipient) { - if (!array_key_exists($recipient, $ni)) { - $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY; + foreach ($recipients as $recipient) { + if (!array_key_exists($recipient, $ni)) { + $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY; + } } - } - // Exclude any deleted, non-local, or blocking recipients. - $profile = $this->getProfile(); - $originalProfile = null; - if ($this->repeat_of) { - // Check blocks against the original notice's poster as well. - $original = Notice::staticGet('id', $this->repeat_of); - if ($original) { - $originalProfile = $original->getProfile(); + // Exclude any deleted, non-local, or blocking recipients. + $profile = $this->getProfile(); + $originalProfile = null; + if ($this->repeat_of) { + // Check blocks against the original notice's poster as well. + $original = Notice::staticGet('id', $this->repeat_of); + if ($original) { + $originalProfile = $original->getProfile(); + } } - } - foreach ($ni as $id => $source) { - $user = User::staticGet('id', $id); - if (empty($user) || $user->hasBlocked($profile) || - ($originalProfile && $user->hasBlocked($originalProfile))) { - unset($ni[$id]); + foreach ($ni as $id => $source) { + $user = User::staticGet('id', $id); + if (empty($user) || $user->hasBlocked($profile) || + ($originalProfile && $user->hasBlocked($originalProfile))) { + unset($ni[$id]); + } } + + // Give plugins a chance to filter out... + Event::handle('EndNoticeWhoGets', array($this, &$ni)); } if (!empty($c)) {