function handle($channel) { $cur = $this->user; $all = new SearchSub(); $all->profile_id = $cur->id; $all->find(); if ($all->N == 0) { // TRANS: Error text shown a user tries to disable all a search subscriptions with track off command, but has none. $channel->error($cur, _m('You are not tracking any searches.')); return; } $profile = $cur->getProfile(); while ($all->fetch()) { try { SearchSub::cancel($profile, $all->search); } catch (Exception $e) { // TRANS: Message given having failed to cancel one of the search subs with 'track off' command. // TRANS: %s is the search for which the subscription removal failed. $channel->error($cur, sprintf(_m('Error disabling search subscription for query "%s".'), $all->search)); return; } } // TRANS: Message given having disabled all search subscriptions with 'track off'. $channel->output($cur, _m('Disabled all your search subscriptions.')); }
function handle($channel) { $cur = $this->user; $all = new SearchSub(); $all->profile_id = $cur->id; $all->find(); if ($all->N == 0) { // TRANS: Error text shown a user tries to disable all a search subscriptions with track off command, but has none. $channel->error($cur, _m('You are not tracking any searches.')); return; } $list = array(); while ($all->fetch()) { $list[] = $all->search; } // TRANS: Separator for list of tracked searches. $separator = _m('SEPARATOR', '", "'); // TRANS: Message given having disabled all search subscriptions with 'track off'. // TRANS: %s is a list of searches. Separator default is '", "'. $channel->output($cur, sprintf(_m('You are tracking searches for: "%s".'), implode($separator, $list))); }
static function forProfile(Profile $profile) { $searches = array(); $keypart = sprintf('searchsub:by_profile:%d', $profile->id); $searchstring = self::cacheGet($keypart); if ($searchstring !== false && !empty($searchstring)) { $searches = explode(',', $searchstring); } else { $searchsub = new SearchSub(); $searchsub->profile_id = $profile->id; if ($searchsub->find()) { while ($searchsub->fetch()) { if (!empty($searchsub->search)) { $searches[] = $searchsub->search; } } } self::cacheSet($keypart, implode(',', $searches)); } return $searches; }
/** * Hook inbox delivery setup so search subscribers receive all * notices with that search in their inbox. * * Currently makes no distinction between local messages and * remote ones which happen to come in to the system. Remote * notices that don't come in at all won't ever reach this. * * @param Notice $notice * @param array $ni in/out map of profile IDs to inbox constants * @return boolean hook result */ function onStartNoticeWhoGets(Notice $notice, array &$ni) { // Warning: this is potentially very slow // with a lot of searches! $sub = new SearchSub(); $sub->groupBy('search'); $sub->find(); while ($sub->fetch()) { $search = $sub->search; if ($this->matchSearch($notice, $search)) { // Match? Find all those who subscribed to this // search term and get our delivery on... $searchsub = new SearchSub(); $searchsub->search = $search; $searchsub->find(); while ($searchsub->fetch()) { // These constants are currently not actually used, iirc $ni[$searchsub->profile_id] = NOTICE_INBOX_SOURCE_SUB; } } } return true; }