3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @author Brenda Wallace <shiny@cpan.org>
22 * @author Christopher Vollick <psycotica0@gmail.com>
23 * @author CiaranG <ciaran@ciarang.com>
24 * @author Craig Andrews <candrews@integralblue.com>
25 * @author Evan Prodromou <evan@controlezvous.ca>
26 * @author Gina Haeussge <osd@foosel.net>
27 * @author Jeffery To <jeffery.to@gmail.com>
28 * @author Mike Cochrane <mikec@mikenz.geek.nz>
29 * @author Robin Millette <millette@controlyourself.ca>
30 * @author Sarven Capadisli <csarven@controlyourself.ca>
31 * @author Tom Adams <tom@holizz.com>
32 * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org
33 * @license GNU Affero General Public License http://www.gnu.org/licenses/
36 if (!defined('STATUSNET') && !defined('LACONICA')) {
41 * Table Definition for notice
43 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
45 /* We keep 200 notices, the max number of notices available per API request,
46 * in the memcached cache. */
48 define('NOTICE_CACHE_WINDOW', CachingNoticeStream::CACHE_WINDOW);
50 define('MAX_BOXCARS', 128);
52 class Notice extends Memcached_DataObject
55 /* the code below is auto generated do not remove the above tag */
57 public $__table = 'notice'; // table name
58 public $id; // int(4) primary_key not_null
59 public $profile_id; // int(4) multiple_key not_null
60 public $uri; // varchar(255) unique_key
61 public $content; // text
62 public $rendered; // text
63 public $url; // varchar(255)
64 public $created; // datetime multiple_key not_null default_0000-00-00%2000%3A00%3A00
65 public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
66 public $reply_to; // int(4)
67 public $is_local; // int(4)
68 public $source; // varchar(32)
69 public $conversation; // int(4)
70 public $lat; // decimal(10,7)
71 public $lon; // decimal(10,7)
72 public $location_id; // int(4)
73 public $location_ns; // int(4)
74 public $repeat_of; // int(4)
75 public $object_type; // varchar(255)
76 public $scope; // int(4)
79 function staticGet($k,$v=NULL)
81 return Memcached_DataObject::staticGet('Notice',$k,$v);
84 /* the code above is auto generated do not remove the tag below */
88 const LOCAL_PUBLIC = 1;
90 const LOCAL_NONPUBLIC = -1;
94 const ADDRESSEE_SCOPE = 2;
95 const GROUP_SCOPE = 4;
96 const FOLLOWER_SCOPE = 8;
100 $profile = Profile::staticGet('id', $this->profile_id);
102 if (empty($profile)) {
103 // TRANS: Server exception thrown when a user profile for a notice cannot be found.
104 // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number).
105 throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id));
113 // For auditing purposes, save a record that the notice
116 // @fixme we have some cases where things get re-run and so the
118 $deleted = Deleted_notice::staticGet('id', $this->id);
121 $deleted = Deleted_notice::staticGet('uri', $this->uri);
125 $deleted = new Deleted_notice();
127 $deleted->id = $this->id;
128 $deleted->profile_id = $this->profile_id;
129 $deleted->uri = $this->uri;
130 $deleted->created = $this->created;
131 $deleted->deleted = common_sql_now();
136 if (Event::handle('NoticeDeleteRelated', array($this))) {
138 // Clear related records
140 $this->clearReplies();
141 $this->clearRepeats();
144 $this->clearGroupInboxes();
147 // NOTE: we don't clear inboxes
148 // NOTE: we don't clear queue items
151 $result = parent::delete();
153 $this->blowOnDelete();
158 * Extract #hashtags from this notice's content and save them to the database.
162 /* extract all #hastags */
163 $count = preg_match_all('/(?:^|\s)#([\pL\pN_\-\.]{1,64})/u', strtolower($this->content), $match);
168 /* Add them to the database */
169 return $this->saveKnownTags($match[1]);
173 * Record the given set of hash tags in the db for this notice.
174 * Given tag strings will be normalized and checked for dupes.
176 function saveKnownTags($hashtags)
178 //turn each into their canonical tag
179 //this is needed to remove dupes before saving e.g. #hash.tag = #hashtag
180 for($i=0; $i<count($hashtags); $i++) {
181 /* elide characters we don't want in the tag */
182 $hashtags[$i] = common_canonical_tag($hashtags[$i]);
185 foreach(array_unique($hashtags) as $hashtag) {
186 $this->saveTag($hashtag);
187 self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, $hashtag);
193 * Record a single hash tag as associated with this notice.
194 * Tag format and uniqueness must be validated by caller.
196 function saveTag($hashtag)
198 $tag = new Notice_tag();
199 $tag->notice_id = $this->id;
200 $tag->tag = $hashtag;
201 $tag->created = $this->created;
202 $id = $tag->insert();
205 // TRANS: Server exception. %s are the error details.
206 throw new ServerException(sprintf(_('Database error inserting hashtag: %s'),
207 $last_error->message));
211 // if it's saved, blow its cache
212 $tag->blowCache(false);
216 * Save a new notice and push it out to subscribers' inboxes.
217 * Poster's permissions are checked before sending.
219 * @param int $profile_id Profile ID of the poster
220 * @param string $content source message text; links may be shortened
221 * per current user's preference
222 * @param string $source source key ('web', 'api', etc)
223 * @param array $options Associative array of optional properties:
224 * string 'created' timestamp of notice; defaults to now
225 * int 'is_local' source/gateway ID, one of:
226 * Notice::LOCAL_PUBLIC - Local, ok to appear in public timeline
227 * Notice::REMOTE_OMB - Sent from a remote OMB service;
228 * hide from public timeline but show in
229 * local "and friends" timelines
230 * Notice::LOCAL_NONPUBLIC - Local, but hide from public timeline
231 * Notice::GATEWAY - From another non-OMB service;
232 * will not appear in public views
233 * float 'lat' decimal latitude for geolocation
234 * float 'lon' decimal longitude for geolocation
235 * int 'location_id' geoname identifier
236 * int 'location_ns' geoname namespace to interpret location_id
237 * int 'reply_to'; notice ID this is a reply to
238 * int 'repeat_of'; notice ID this is a repeat of
239 * string 'uri' unique ID for notice; defaults to local notice URL
240 * string 'url' permalink to notice; defaults to local notice URL
241 * string 'rendered' rendered HTML version of content
242 * array 'replies' list of profile URIs for reply delivery in
243 * place of extracting @-replies from content.
244 * array 'groups' list of group IDs to deliver to, in place of
245 * extracting ! tags from content
246 * array 'tags' list of hashtag strings to save with the notice
247 * in place of extracting # tags from content
248 * array 'urls' list of attached/referred URLs to save with the
249 * notice in place of extracting links from content
250 * boolean 'distribute' whether to distribute the notice, default true
251 * string 'object_type' URL of the associated object type (default ActivityObject::NOTE)
253 * @fixme tag override
256 * @throws ClientException
258 static function saveNew($profile_id, $content, $source, $options=null) {
259 $defaults = array('uri' => null,
263 'distribute' => true);
265 if (!empty($options)) {
266 $options = $options + $defaults;
272 if (!isset($is_local)) {
273 $is_local = Notice::LOCAL_PUBLIC;
276 $profile = Profile::staticGet('id', $profile_id);
277 $user = User::staticGet('id', $profile_id);
279 // Use the local user's shortening preferences, if applicable.
280 $final = $user->shortenLinks($content);
282 $final = common_shorten_links($content);
285 if (Notice::contentTooLong($final)) {
286 // TRANS: Client exception thrown if a notice contains too many characters.
287 throw new ClientException(_('Problem saving notice. Too long.'));
290 if (empty($profile)) {
291 // TRANS: Client exception thrown when trying to save a notice for an unknown user.
292 throw new ClientException(_('Problem saving notice. Unknown user.'));
295 if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) {
296 common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.');
297 // TRANS: Client exception thrown when a user tries to post too many notices in a given time frame.
298 throw new ClientException(_('Too many notices too fast; take a breather '.
299 'and post again in a few minutes.'));
302 if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) {
303 common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.');
304 // TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame.
305 throw new ClientException(_('Too many duplicate messages too quickly;'.
306 ' take a breather and post again in a few minutes.'));
309 if (!$profile->hasRight(Right::NEWNOTICE)) {
310 common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname);
312 // TRANS: Client exception thrown when a user tries to post while being banned.
313 throw new ClientException(_('You are banned from posting notices on this site.'), 403);
316 $notice = new Notice();
317 $notice->profile_id = $profile_id;
319 $autosource = common_config('public', 'autosource');
321 // Sandboxed are non-false, but not 1, either
323 if (!$profile->hasRight(Right::PUBLICNOTICE) ||
324 ($source && $autosource && in_array($source, $autosource))) {
325 $notice->is_local = Notice::LOCAL_NONPUBLIC;
327 $notice->is_local = $is_local;
330 if (!empty($created)) {
331 $notice->created = $created;
333 $notice->created = common_sql_now();
336 $notice->content = $final;
338 $notice->source = $source;
342 // Handle repeat case
344 if (isset($repeat_of)) {
345 $notice->repeat_of = $repeat_of;
347 $notice->reply_to = self::getReplyTo($reply_to, $profile_id, $source, $final);
350 if (!empty($notice->reply_to)) {
351 $reply = Notice::staticGet('id', $notice->reply_to);
352 $notice->conversation = $reply->conversation;
355 if (!empty($lat) && !empty($lon)) {
360 if (!empty($location_ns) && !empty($location_id)) {
361 $notice->location_id = $location_id;
362 $notice->location_ns = $location_ns;
365 if (!empty($rendered)) {
366 $notice->rendered = $rendered;
368 $notice->rendered = common_render_content($final, $notice);
371 if (empty($object_type)) {
372 $notice->object_type = (empty($notice->reply_to)) ? ActivityObject::NOTE : ActivityObject::COMMENT;
374 $notice->object_type = $object_type;
377 if (Event::handle('StartNoticeSave', array(&$notice))) {
379 // XXX: some of these functions write to the DB
381 $id = $notice->insert();
384 common_log_db_error($notice, 'INSERT', __FILE__);
385 // TRANS: Server exception thrown when a notice cannot be saved.
386 throw new ServerException(_('Problem saving notice.'));
389 // Update ID-dependent columns: URI, conversation
391 $orig = clone($notice);
396 $notice->uri = common_notice_uri($notice);
400 // If it's not part of a conversation, it's
401 // the beginning of a new conversation.
403 if (empty($notice->conversation)) {
404 $conv = Conversation::create();
405 $notice->conversation = $conv->id;
410 if (!$notice->update($orig)) {
411 common_log_db_error($notice, 'UPDATE', __FILE__);
412 // TRANS: Server exception thrown when a notice cannot be updated.
413 throw new ServerException(_('Problem saving notice.'));
419 // Clear the cache for subscribed users, so they'll update at next request
420 // XXX: someone clever could prepend instead of clearing the cache
422 $notice->blowOnInsert();
424 // Save per-notice metadata...
426 if (isset($replies)) {
427 $notice->saveKnownReplies($replies);
429 $notice->saveReplies();
433 $notice->saveKnownTags($tags);
438 // Note: groups may save tags, so must be run after tags are saved
439 // to avoid errors on duplicates.
440 if (isset($groups)) {
441 $notice->saveKnownGroups($groups);
443 $notice->saveGroups();
447 $notice->saveKnownUrls($urls);
453 // Prepare inbox delivery, may be queued to background.
454 $notice->distribute();
460 function blowOnInsert($conversation = false)
462 self::blow('profile:notice_ids:%d', $this->profile_id);
464 if ($this->isPublic()) {
465 self::blow('public');
468 // XXX: Before we were blowing the casche only if the notice id
469 // was not the root of the conversation. What to do now?
471 self::blow('notice:conversation_ids:%d', $this->conversation);
473 if (!empty($this->repeat_of)) {
474 self::blow('notice:repeats:%d', $this->repeat_of);
477 $original = Notice::staticGet('id', $this->repeat_of);
479 if (!empty($original)) {
480 $originalUser = User::staticGet('id', $original->profile_id);
481 if (!empty($originalUser)) {
482 self::blow('user:repeats_of_me:%d', $originalUser->id);
486 $profile = Profile::staticGet($this->profile_id);
487 if (!empty($profile)) {
488 $profile->blowNoticeCount();
493 * Clear cache entries related to this notice at delete time.
494 * Necessary to avoid breaking paging on public, profile timelines.
496 function blowOnDelete()
498 $this->blowOnInsert();
500 self::blow('profile:notice_ids:%d;last', $this->profile_id);
502 if ($this->isPublic()) {
503 self::blow('public;last');
506 self::blow('fave:by_notice', $this->id);
508 if ($this->conversation) {
509 // In case we're the first, will need to calc a new root.
510 self::blow('notice:conversation_root:%d', $this->conversation);
514 /** save all urls in the notice to the db
516 * follow redirects and save all available file information
517 * (mimetype, date, size, oembed, etc.)
521 function saveUrls() {
522 if (common_config('attachments', 'process_links')) {
523 common_replace_urls_callback($this->content, array($this, 'saveUrl'), $this->id);
528 * Save the given URLs as related links/attachments to the db
530 * follow redirects and save all available file information
531 * (mimetype, date, size, oembed, etc.)
535 function saveKnownUrls($urls)
537 if (common_config('attachments', 'process_links')) {
538 // @fixme validation?
539 foreach (array_unique($urls) as $url) {
540 File::processNew($url, $this->id);
548 function saveUrl($url, $notice_id) {
549 File::processNew($url, $notice_id);
552 static function checkDupes($profile_id, $content) {
553 $profile = Profile::staticGet($profile_id);
554 if (empty($profile)) {
557 $notice = $profile->getNotices(0, CachingNoticeStream::CACHE_WINDOW);
558 if (!empty($notice)) {
560 while ($notice->fetch()) {
561 if (time() - strtotime($notice->created) >= common_config('site', 'dupelimit')) {
563 } else if ($notice->content == $content) {
568 // If we get here, oldest item in cache window is not
569 // old enough for dupe limit; do direct check against DB
570 $notice = new Notice();
571 $notice->profile_id = $profile_id;
572 $notice->content = $content;
573 $threshold = common_sql_date(time() - common_config('site', 'dupelimit'));
574 $notice->whereAdd(sprintf("created > '%s'", $notice->escape($threshold)));
576 $cnt = $notice->count();
580 static function checkEditThrottle($profile_id) {
581 $profile = Profile::staticGet($profile_id);
582 if (empty($profile)) {
585 // Get the Nth notice
586 $notice = $profile->getNotices(common_config('throttle', 'count') - 1, 1);
587 if ($notice && $notice->fetch()) {
588 // If the Nth notice was posted less than timespan seconds ago
589 if (time() - strtotime($notice->created) <= common_config('throttle', 'timespan')) {
594 // Either not N notices in the stream, OR the Nth was not posted within timespan seconds
598 function getUploadedAttachment() {
600 $query = 'select file.url as up, file.id as i from file join file_to_post on file.id = file_id where post_id=' . $post->escape($post->id) . ' and url like "%/notice/%/file"';
601 $post->query($query);
603 if (empty($post->up) || empty($post->i)) {
606 $ret = array($post->up, $post->i);
612 function hasAttachments() {
614 $query = "select count(file_id) as n_attachments from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $post->escape($post->id);
615 $post->query($query);
617 $n_attachments = intval($post->n_attachments);
619 return $n_attachments;
622 function attachments() {
625 $f2p = new File_to_post;
626 $f2p->post_id = $this->id;
628 while ($f2p->fetch()) {
629 $f = File::staticGet($f2p->file_id);
639 function publicStream($offset=0, $limit=20, $since_id=0, $max_id=0)
641 $stream = new PublicNoticeStream();
642 return $stream->getNotices($offset, $limit, $since_id, $max_id);
646 function conversationStream($id, $offset=0, $limit=20, $since_id=0, $max_id=0)
648 $stream = new ConversationNoticeStream($id);
650 return $stream->getNotices($offset, $limit, $since_id, $max_id);
654 * Is this notice part of an active conversation?
656 * @return boolean true if other messages exist in the same
657 * conversation, false if this is the only one
659 function hasConversation()
661 if (!empty($this->conversation)) {
662 $conversation = Notice::conversationStream(
668 if ($conversation->N > 0) {
676 * Grab the earliest notice from this conversation.
678 * @return Notice or null
680 function conversationRoot()
682 if (!empty($this->conversation)) {
683 $c = self::memcache();
685 $key = Cache::key('notice:conversation_root:' . $this->conversation);
686 $notice = $c->get($key);
691 $notice = new Notice();
692 $notice->conversation = $this->conversation;
693 $notice->orderBy('CREATED');
698 $c->set($key, $notice);
705 * Pull up a full list of local recipients who will be getting
706 * this notice in their inbox. Results will be cached, so don't
707 * change the input data wily-nilly!
709 * @param array $groups optional list of Group objects;
710 * if left empty, will be loaded from group_inbox records
711 * @param array $recipient optional list of reply profile ids
712 * if left empty, will be loaded from reply records
713 * @return array associating recipient user IDs with an inbox source constant
715 function whoGets($groups=null, $recipients=null)
717 $c = self::memcache();
720 $ni = $c->get(Cache::key('notice:who_gets:'.$this->id));
726 if (is_null($groups)) {
727 $groups = $this->getGroups();
730 if (is_null($recipients)) {
731 $recipients = $this->getReplies();
734 $users = $this->getSubscribedUsers();
736 // FIXME: kind of ignoring 'transitional'...
737 // we'll probably stop supporting inboxless mode
742 // Give plugins a chance to add folks in at start...
743 if (Event::handle('StartNoticeWhoGets', array($this, &$ni))) {
745 foreach ($users as $id) {
746 $ni[$id] = NOTICE_INBOX_SOURCE_SUB;
749 foreach ($groups as $group) {
750 $users = $group->getUserMembers();
751 foreach ($users as $id) {
752 if (!array_key_exists($id, $ni)) {
753 $ni[$id] = NOTICE_INBOX_SOURCE_GROUP;
758 foreach ($recipients as $recipient) {
759 if (!array_key_exists($recipient, $ni)) {
760 $ni[$recipient] = NOTICE_INBOX_SOURCE_REPLY;
764 // Exclude any deleted, non-local, or blocking recipients.
765 $profile = $this->getProfile();
766 $originalProfile = null;
767 if ($this->repeat_of) {
768 // Check blocks against the original notice's poster as well.
769 $original = Notice::staticGet('id', $this->repeat_of);
771 $originalProfile = $original->getProfile();
774 foreach ($ni as $id => $source) {
775 $user = User::staticGet('id', $id);
776 if (empty($user) || $user->hasBlocked($profile) ||
777 ($originalProfile && $user->hasBlocked($originalProfile))) {
782 // Give plugins a chance to filter out...
783 Event::handle('EndNoticeWhoGets', array($this, &$ni));
787 // XXX: pack this data better
788 $c->set(Cache::key('notice:who_gets:'.$this->id), $ni);
795 * Adds this notice to the inboxes of each local user who should receive
796 * it, based on author subscriptions, group memberships, and @-replies.
798 * Warning: running a second time currently will make items appear
799 * multiple times in users' inboxes.
801 * @fixme make more robust against errors
802 * @fixme break up massive deliveries to smaller background tasks
804 * @param array $groups optional list of Group objects;
805 * if left empty, will be loaded from group_inbox records
806 * @param array $recipient optional list of reply profile ids
807 * if left empty, will be loaded from reply records
809 function addToInboxes($groups=null, $recipients=null)
811 $ni = $this->whoGets($groups, $recipients);
813 $ids = array_keys($ni);
815 // We remove the author (if they're a local user),
816 // since we'll have already done this in distribute()
818 $i = array_search($this->profile_id, $ids);
826 Inbox::bulkInsert($this->id, $ids);
831 function getSubscribedUsers()
835 if(common_config('db','quote_identifiers'))
836 $user_table = '"user"';
837 else $user_table = 'user';
841 'FROM '. $user_table .' JOIN subscription '.
842 'ON '. $user_table .'.id = subscription.subscriber ' .
843 'WHERE subscription.subscribed = %d ';
845 $user->query(sprintf($qry, $this->profile_id));
849 while ($user->fetch()) {
859 * Record this notice to the given group inboxes for delivery.
860 * Overrides the regular parsing of !group markup.
862 * @param string $group_ids
863 * @fixme might prefer URIs as identifiers, as for replies?
864 * best with generalizations on user_group to support
865 * remote groups better.
867 function saveKnownGroups($group_ids)
869 if (!is_array($group_ids)) {
870 // TRANS: Server exception thrown when no array is provided to the method saveKnownGroups().
871 throw new ServerException(_('Bad type provided to saveKnownGroups.'));
875 foreach (array_unique($group_ids) as $id) {
876 $group = User_group::staticGet('id', $id);
878 common_log(LOG_ERR, "Local delivery to group id $id, $group->nickname");
879 $result = $this->addToGroupInbox($group);
881 common_log_db_error($gi, 'INSERT', __FILE__);
884 // @fixme should we save the tags here or not?
885 $groups[] = clone($group);
887 common_log(LOG_ERR, "Local delivery to group id $id skipped, doesn't exist");
895 * Parse !group delivery and record targets into group_inbox.
896 * @return array of Group objects
898 function saveGroups()
900 // Don't save groups for repeats
902 if (!empty($this->repeat_of)) {
908 /* extract all !group */
909 $count = preg_match_all('/(?:^|\s)!(' . Nickname::DISPLAY_FMT . ')/',
910 strtolower($this->content),
916 $profile = $this->getProfile();
918 /* Add them to the database */
920 foreach (array_unique($match[1]) as $nickname) {
921 /* XXX: remote groups. */
922 $group = User_group::getForNickname($nickname, $profile);
928 // we automatically add a tag for every group name, too
930 $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname),
931 'notice_id' => $this->id));
934 $this->saveTag($nickname);
937 if ($profile->isMember($group)) {
939 $result = $this->addToGroupInbox($group);
942 common_log_db_error($gi, 'INSERT', __FILE__);
945 $groups[] = clone($group);
952 function addToGroupInbox($group)
954 $gi = Group_inbox::pkeyGet(array('group_id' => $group->id,
955 'notice_id' => $this->id));
959 $gi = new Group_inbox();
961 $gi->group_id = $group->id;
962 $gi->notice_id = $this->id;
963 $gi->created = $this->created;
965 $result = $gi->insert();
968 common_log_db_error($gi, 'INSERT', __FILE__);
969 // TRANS: Server exception thrown when an update for a group inbox fails.
970 throw new ServerException(_('Problem saving group inbox.'));
973 self::blow('user_group:notice_ids:%d', $gi->group_id);
980 * Save reply records indicating that this notice needs to be
981 * delivered to the local users with the given URIs.
983 * Since this is expected to be used when saving foreign-sourced
984 * messages, we won't deliver to any remote targets as that's the
985 * source service's responsibility.
987 * Mail notifications etc will be handled later.
989 * @param array of unique identifier URIs for recipients
991 function saveKnownReplies($uris)
997 $sender = Profile::staticGet($this->profile_id);
999 foreach (array_unique($uris) as $uri) {
1001 $profile = Profile::fromURI($uri);
1003 if (empty($profile)) {
1004 common_log(LOG_WARNING, "Unable to determine profile for URI '$uri'");
1008 if ($profile->hasBlocked($sender)) {
1009 common_log(LOG_INFO, "Not saving reply to profile {$profile->id} ($uri) from sender {$sender->id} because of a block.");
1013 $reply = new Reply();
1015 $reply->notice_id = $this->id;
1016 $reply->profile_id = $profile->id;
1017 $reply->modified = $this->created;
1019 common_log(LOG_INFO, __METHOD__ . ": saving reply: notice $this->id to profile $profile->id");
1021 $id = $reply->insert();
1028 * Pull @-replies from this message's content in StatusNet markup format
1029 * and save reply records indicating that this message needs to be
1030 * delivered to those users.
1032 * Mail notifications to local profiles will be sent later.
1034 * @return array of integer profile IDs
1037 function saveReplies()
1039 // Don't save reply data for repeats
1041 if (!empty($this->repeat_of)) {
1045 $sender = Profile::staticGet($this->profile_id);
1047 // @todo ideally this parser information would only
1048 // be calculated once.
1050 $mentions = common_find_mentions($this->content, $this);
1054 // store replied only for first @ (what user/notice what the reply directed,
1055 // we assume first @ is it)
1057 foreach ($mentions as $mention) {
1059 foreach ($mention['mentioned'] as $mentioned) {
1061 // skip if they're already covered
1063 if (!empty($replied[$mentioned->id])) {
1067 // Don't save replies from blocked profile to local user
1069 $mentioned_user = User::staticGet('id', $mentioned->id);
1070 if (!empty($mentioned_user) && $mentioned_user->hasBlocked($sender)) {
1074 $reply = new Reply();
1076 $reply->notice_id = $this->id;
1077 $reply->profile_id = $mentioned->id;
1078 $reply->modified = $this->created;
1080 $id = $reply->insert();
1083 common_log_db_error($reply, 'INSERT', __FILE__);
1084 // TRANS: Server exception thrown when a reply cannot be saved.
1085 // TRANS: %1$d is a notice ID, %2$d is the ID of the mentioned user.
1086 throw new ServerException(sprintf(_('Could not save reply for %1$d, %2$d.'), $this->id, $mentioned->id));
1088 $replied[$mentioned->id] = 1;
1089 self::blow('reply:stream:%d', $mentioned->id);
1094 $recipientIds = array_keys($replied);
1096 return $recipientIds;
1100 * Pull the complete list of @-reply targets for this notice.
1102 * @return array of integer profile ids
1104 function getReplies()
1110 $reply = new Reply();
1111 $reply->selectAdd();
1112 $reply->selectAdd('profile_id');
1113 $reply->notice_id = $this->id;
1115 if ($reply->find()) {
1116 while($reply->fetch()) {
1117 $ids[] = $reply->profile_id;
1127 * Send e-mail notifications to local @-reply targets.
1129 * Replies must already have been saved; this is expected to be run
1130 * from the distrib queue handler.
1132 function sendReplyNotifications()
1134 // Don't send reply notifications for repeats
1136 if (!empty($this->repeat_of)) {
1140 $recipientIds = $this->getReplies();
1142 foreach ($recipientIds as $recipientId) {
1143 $user = User::staticGet('id', $recipientId);
1144 if (!empty($user)) {
1145 mail_notify_attn($user, $this);
1151 * Pull list of groups this notice needs to be delivered to,
1152 * as previously recorded by saveGroups() or saveKnownGroups().
1154 * @return array of Group objects
1156 function getGroups()
1158 // Don't save groups for repeats
1160 if (!empty($this->repeat_of)) {
1168 $gi = new Group_inbox();
1171 $gi->selectAdd('group_id');
1173 $gi->notice_id = $this->id;
1176 while ($gi->fetch()) {
1177 $group = User_group::staticGet('id', $gi->group_id);
1190 * Convert a notice into an activity for export.
1192 * @param User $cur Current user
1194 * @return Activity activity object representing this Notice.
1197 function asActivity($cur)
1199 $act = self::cacheGet(Cache::codeKey('notice:as-activity:'.$this->id));
1204 $act = new Activity();
1206 if (Event::handle('StartNoticeAsActivity', array($this, &$act))) {
1208 $profile = $this->getProfile();
1210 $act->actor = ActivityObject::fromProfile($profile);
1211 $act->actor->extra[] = $profile->profileInfo($cur);
1212 $act->verb = ActivityVerb::POST;
1213 $act->objects[] = ActivityObject::fromNotice($this);
1215 // XXX: should this be handled by default processing for object entry?
1217 $act->time = strtotime($this->created);
1218 $act->link = $this->bestUrl();
1220 $act->content = common_xml_safe_str($this->rendered);
1221 $act->id = $this->uri;
1222 $act->title = common_xml_safe_str($this->content);
1226 $tags = $this->getTags();
1228 foreach ($tags as $tag) {
1229 $cat = new AtomCategory();
1232 $act->categories[] = $cat;
1236 // XXX: use Atom Media and/or File activity objects instead
1238 $attachments = $this->attachments();
1240 foreach ($attachments as $attachment) {
1241 $enclosure = $attachment->getEnclosure();
1243 $act->enclosures[] = $enclosure;
1247 $ctx = new ActivityContext();
1249 if (!empty($this->reply_to)) {
1250 $reply = Notice::staticGet('id', $this->reply_to);
1251 if (!empty($reply)) {
1252 $ctx->replyToID = $reply->uri;
1253 $ctx->replyToUrl = $reply->bestUrl();
1257 $ctx->location = $this->getLocation();
1261 if (!empty($this->conversation)) {
1262 $conv = Conversation::staticGet('id', $this->conversation);
1263 if (!empty($conv)) {
1264 $ctx->conversation = $conv->uri;
1268 $reply_ids = $this->getReplies();
1270 foreach ($reply_ids as $id) {
1271 $profile = Profile::staticGet('id', $id);
1272 if (!empty($profile)) {
1273 $ctx->attention[] = $profile->getUri();
1277 $groups = $this->getGroups();
1279 foreach ($groups as $group) {
1280 $ctx->attention[] = $group->getUri();
1283 // XXX: deprecated; use ActivityVerb::SHARE instead
1287 if (!empty($this->repeat_of)) {
1288 $repeat = Notice::staticGet('id', $this->repeat_of);
1289 $ctx->forwardID = $repeat->uri;
1290 $ctx->forwardUrl = $repeat->bestUrl();
1293 $act->context = $ctx;
1297 $atom_feed = $profile->getAtomFeed();
1299 if (!empty($atom_feed)) {
1301 $act->source = new ActivitySource();
1303 // XXX: we should store the actual feed ID
1305 $act->source->id = $atom_feed;
1307 // XXX: we should store the actual feed title
1309 $act->source->title = $profile->getBestName();
1311 $act->source->links['alternate'] = $profile->profileurl;
1312 $act->source->links['self'] = $atom_feed;
1314 $act->source->icon = $profile->avatarUrl(AVATAR_PROFILE_SIZE);
1316 $notice = $profile->getCurrentNotice();
1318 if (!empty($notice)) {
1319 $act->source->updated = self::utcDate($notice->created);
1322 $user = User::staticGet('id', $profile->id);
1324 if (!empty($user)) {
1325 $act->source->links['license'] = common_config('license', 'url');
1329 if ($this->isLocal()) {
1330 $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id,
1331 'format' => 'atom'));
1332 $act->editLink = $act->selfLink;
1335 Event::handle('EndNoticeAsActivity', array($this, &$act));
1338 self::cacheSet(Cache::codeKey('notice:as-activity:'.$this->id), $act);
1343 // This has gotten way too long. Needs to be sliced up into functional bits
1344 // or ideally exported to a utility class.
1346 function asAtomEntry($namespace=false,
1351 $act = $this->asActivity($cur);
1352 $act->extra[] = $this->noticeInfo($cur);
1353 return $act->asString($namespace, $author, $source);
1357 * Extra notice info for atom entries
1359 * Clients use some extra notice info in the atom stream.
1360 * This gives it to them.
1362 * @param User $cur Current user
1364 * @return array representation of <statusnet:notice_info> element
1367 function noticeInfo($cur)
1369 // local notice ID (useful to clients for ordering)
1371 $noticeInfoAttr = array('local_id' => $this->id);
1375 $ns = $this->getSource();
1378 $noticeInfoAttr['source'] = $ns->code;
1379 if (!empty($ns->url)) {
1380 $noticeInfoAttr['source_link'] = $ns->url;
1381 if (!empty($ns->name)) {
1382 $noticeInfoAttr['source'] = '<a href="'
1383 . htmlspecialchars($ns->url)
1384 . '" rel="nofollow">'
1385 . htmlspecialchars($ns->name)
1391 // favorite and repeated
1394 $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
1395 $cp = $cur->getProfile();
1396 $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this->id)) ? "true" : "false";
1399 if (!empty($this->repeat_of)) {
1400 $noticeInfoAttr['repeat_of'] = $this->repeat_of;
1403 return array('statusnet:notice_info', $noticeInfoAttr, null);
1407 * Returns an XML string fragment with a reference to a notice as an
1408 * Activity Streams noun object with the given element type.
1410 * Assumes that 'activity' namespace has been previously defined.
1412 * @param string $element one of 'subject', 'object', 'target'
1416 function asActivityNoun($element)
1418 $noun = ActivityObject::fromNotice($this);
1419 return $noun->asString('activity:' . $element);
1424 if (!empty($this->url)) {
1426 } else if (!empty($this->uri) && preg_match('/^https?:/', $this->uri)) {
1429 return common_local_url('shownotice',
1430 array('notice' => $this->id));
1436 * Determine which notice, if any, a new notice is in reply to.
1438 * For conversation tracking, we try to see where this notice fits
1439 * in the tree. Rough algorithm is:
1441 * if (reply_to is set and valid) {
1443 * } else if ((source not API or Web) and (content starts with "T NAME" or "@name ")) {
1444 * return ID of last notice by initial @name in content;
1447 * Note that all @nickname instances will still be used to save "reply" records,
1448 * so the notice shows up in the mentioned users' "replies" tab.
1450 * @param integer $reply_to ID passed in by Web or API
1451 * @param integer $profile_id ID of author
1452 * @param string $source Source tag, like 'web' or 'gwibber'
1453 * @param string $content Final notice content
1455 * @return integer ID of replied-to notice, or null for not a reply.
1458 static function getReplyTo($reply_to, $profile_id, $source, $content)
1460 static $lb = array('xmpp', 'mail', 'sms', 'omb');
1462 // If $reply_to is specified, we check that it exists, and then
1463 // return it if it does
1465 if (!empty($reply_to)) {
1466 $reply_notice = Notice::staticGet('id', $reply_to);
1467 if (!empty($reply_notice)) {
1472 // If it's not a "low bandwidth" source (one where you can't set
1473 // a reply_to argument), we return. This is mostly web and API
1476 if (!in_array($source, $lb)) {
1480 // Is there an initial @ or T?
1482 if (preg_match('/^T ([A-Z0-9]{1,64}) /', $content, $match) ||
1483 preg_match('/^@([a-z0-9]{1,64})\s+/', $content, $match)) {
1484 $nickname = common_canonical_nickname($match[1]);
1489 // Figure out who that is.
1491 $sender = Profile::staticGet('id', $profile_id);
1492 if (empty($sender)) {
1496 $recipient = common_relative_profile($sender, $nickname, common_sql_now());
1498 if (empty($recipient)) {
1502 // Get their last notice
1504 $last = $recipient->getCurrentNotice();
1506 if (!empty($last)) {
1511 static function maxContent()
1513 $contentlimit = common_config('notice', 'contentlimit');
1514 // null => use global limit (distinct from 0!)
1515 if (is_null($contentlimit)) {
1516 $contentlimit = common_config('site', 'textlimit');
1518 return $contentlimit;
1521 static function contentTooLong($content)
1523 $contentlimit = self::maxContent();
1524 return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit));
1527 function getLocation()
1531 if (!empty($this->location_id) && !empty($this->location_ns)) {
1532 $location = Location::fromId($this->location_id, $this->location_ns);
1535 if (is_null($location)) { // no ID, or Location::fromId() failed
1536 if (!empty($this->lat) && !empty($this->lon)) {
1537 $location = Location::fromLatLon($this->lat, $this->lon);
1544 function repeat($repeater_id, $source)
1546 $author = Profile::staticGet('id', $this->profile_id);
1548 // TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
1549 // TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
1550 $content = sprintf(_('RT @%1$s %2$s'),
1554 $maxlen = common_config('site', 'textlimit');
1555 if ($maxlen > 0 && mb_strlen($content) > $maxlen) {
1556 // Web interface and current Twitter API clients will
1557 // pull the original notice's text, but some older
1558 // clients and RSS/Atom feeds will see this trimmed text.
1560 // Unfortunately this is likely to lose tags or URLs
1561 // at the end of long notices.
1562 $content = mb_substr($content, 0, $maxlen - 4) . ' ...';
1565 return self::saveNew($repeater_id, $content, $source,
1566 array('repeat_of' => $this->id));
1569 // These are supposed to be in chron order!
1571 function repeatStream($limit=100)
1573 $cache = Cache::instance();
1575 if (empty($cache)) {
1576 $ids = $this->_repeatStreamDirect($limit);
1578 $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id));
1579 if ($idstr !== false) {
1580 $ids = explode(',', $idstr);
1582 $ids = $this->_repeatStreamDirect(100);
1583 $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids));
1586 // We do a max of 100, so slice down to limit
1587 $ids = array_slice($ids, 0, $limit);
1591 return NoticeStream::getStreamByIds($ids);
1594 function _repeatStreamDirect($limit)
1596 $notice = new Notice();
1598 $notice->selectAdd(); // clears it
1599 $notice->selectAdd('id');
1601 $notice->repeat_of = $this->id;
1603 $notice->orderBy('created, id'); // NB: asc!
1605 if (!is_null($limit)) {
1606 $notice->limit(0, $limit);
1611 if ($notice->find()) {
1612 while ($notice->fetch()) {
1613 $ids[] = $notice->id;
1623 function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
1627 if (!empty($location_id) && !empty($location_ns)) {
1628 $options['location_id'] = $location_id;
1629 $options['location_ns'] = $location_ns;
1631 $location = Location::fromId($location_id, $location_ns);
1633 if (!empty($location)) {
1634 $options['lat'] = $location->lat;
1635 $options['lon'] = $location->lon;
1638 } else if (!empty($lat) && !empty($lon)) {
1639 $options['lat'] = $lat;
1640 $options['lon'] = $lon;
1642 $location = Location::fromLatLon($lat, $lon);
1644 if (!empty($location)) {
1645 $options['location_id'] = $location->location_id;
1646 $options['location_ns'] = $location->location_ns;
1648 } else if (!empty($profile)) {
1649 if (isset($profile->lat) && isset($profile->lon)) {
1650 $options['lat'] = $profile->lat;
1651 $options['lon'] = $profile->lon;
1654 if (isset($profile->location_id) && isset($profile->location_ns)) {
1655 $options['location_id'] = $profile->location_id;
1656 $options['location_ns'] = $profile->location_ns;
1663 function clearReplies()
1665 $replyNotice = new Notice();
1666 $replyNotice->reply_to = $this->id;
1668 //Null any notices that are replies to this notice
1670 if ($replyNotice->find()) {
1671 while ($replyNotice->fetch()) {
1672 $orig = clone($replyNotice);
1673 $replyNotice->reply_to = null;
1674 $replyNotice->update($orig);
1680 $reply = new Reply();
1681 $reply->notice_id = $this->id;
1683 if ($reply->find()) {
1684 while($reply->fetch()) {
1685 self::blow('reply:stream:%d', $reply->profile_id);
1693 function clearFiles()
1695 $f2p = new File_to_post();
1697 $f2p->post_id = $this->id;
1700 while ($f2p->fetch()) {
1704 // FIXME: decide whether to delete File objects
1705 // ...and related (actual) files
1708 function clearRepeats()
1710 $repeatNotice = new Notice();
1711 $repeatNotice->repeat_of = $this->id;
1713 //Null any notices that are repeats of this notice
1715 if ($repeatNotice->find()) {
1716 while ($repeatNotice->fetch()) {
1717 $orig = clone($repeatNotice);
1718 $repeatNotice->repeat_of = null;
1719 $repeatNotice->update($orig);
1724 function clearFaves()
1727 $fave->notice_id = $this->id;
1729 if ($fave->find()) {
1730 while ($fave->fetch()) {
1731 self::blow('fave:ids_by_user_own:%d', $fave->user_id);
1732 self::blow('fave:ids_by_user_own:%d;last', $fave->user_id);
1733 self::blow('fave:ids_by_user:%d', $fave->user_id);
1734 self::blow('fave:ids_by_user:%d;last', $fave->user_id);
1742 function clearTags()
1744 $tag = new Notice_tag();
1745 $tag->notice_id = $this->id;
1748 while ($tag->fetch()) {
1749 self::blow('profile:notice_ids_tagged:%d:%s', $this->profile_id, Cache::keyize($tag->tag));
1750 self::blow('profile:notice_ids_tagged:%d:%s;last', $this->profile_id, Cache::keyize($tag->tag));
1751 self::blow('notice_tag:notice_ids:%s', Cache::keyize($tag->tag));
1752 self::blow('notice_tag:notice_ids:%s;last', Cache::keyize($tag->tag));
1760 function clearGroupInboxes()
1762 $gi = new Group_inbox();
1764 $gi->notice_id = $this->id;
1767 while ($gi->fetch()) {
1768 self::blow('user_group:notice_ids:%d', $gi->group_id);
1776 function distribute()
1778 // We always insert for the author so they don't
1780 Event::handle('StartNoticeDistribute', array($this));
1782 $user = User::staticGet('id', $this->profile_id);
1783 if (!empty($user)) {
1784 Inbox::insertNotice($user->id, $this->id);
1787 if (common_config('queue', 'inboxes')) {
1788 // If there's a failure, we want to _force_
1789 // distribution at this point.
1791 $qm = QueueManager::get();
1792 $qm->enqueue($this, 'distrib');
1793 } catch (Exception $e) {
1794 // If the exception isn't transient, this
1795 // may throw more exceptions as DQH does
1796 // its own enqueueing. So, we ignore them!
1798 $handler = new DistribQueueHandler();
1799 $handler->handle($this);
1800 } catch (Exception $e) {
1801 common_log(LOG_ERR, "emergency redistribution resulted in " . $e->getMessage());
1803 // Re-throw so somebody smarter can handle it.
1807 $handler = new DistribQueueHandler();
1808 $handler->handle($this);
1814 $result = parent::insert();
1817 // Profile::hasRepeated() abuses pkeyGet(), so we
1818 // have to clear manually
1819 if (!empty($this->repeat_of)) {
1820 $c = self::memcache();
1822 $ck = self::multicacheKey('Notice',
1823 array('profile_id' => $this->profile_id,
1824 'repeat_of' => $this->repeat_of));
1834 * Get the source of the notice
1836 * @return Notice_source $ns A notice source object. 'code' is the only attribute
1837 * guaranteed to be populated.
1839 function getSource()
1841 $ns = new Notice_source();
1842 if (!empty($this->source)) {
1843 switch ($this->source) {
1850 $ns->code = $this->source;
1853 $ns = Notice_source::staticGet($this->source);
1855 $ns = new Notice_source();
1856 $ns->code = $this->source;
1857 $app = Oauth_application::staticGet('name', $this->source);
1859 $ns->name = $app->name;
1860 $ns->url = $app->source_url;
1870 * Determine whether the notice was locally created
1872 * @return boolean locality
1875 public function isLocal()
1877 return ($this->is_local == Notice::LOCAL_PUBLIC ||
1878 $this->is_local == Notice::LOCAL_NONPUBLIC);
1882 * Get the list of hash tags saved with this notice.
1884 * @return array of strings
1886 public function getTags()
1889 $tag = new Notice_tag();
1890 $tag->notice_id = $this->id;
1892 while ($tag->fetch()) {
1893 $tags[] = $tag->tag;
1900 static private function utcDate($dt)
1902 $dateStr = date('d F Y H:i:s', strtotime($dt));
1903 $d = new DateTime($dateStr, new DateTimeZone('UTC'));
1904 return $d->format(DATE_W3C);
1908 * Look up the creation timestamp for a given notice ID, even
1909 * if it's been deleted.
1912 * @return mixed string recorded creation timestamp, or false if can't be found
1914 public static function getAsTimestamp($id)
1920 $notice = Notice::staticGet('id', $id);
1922 return $notice->created;
1925 $deleted = Deleted_notice::staticGet('id', $id);
1927 return $deleted->created;
1934 * Build an SQL 'where' fragment for timestamp-based sorting from a since_id
1935 * parameter, matching notices posted after the given one (exclusive).
1937 * If the referenced notice can't be found, will return false.
1940 * @param string $idField
1941 * @param string $createdField
1942 * @return mixed string or false if no match
1944 public static function whereSinceId($id, $idField='id', $createdField='created')
1946 $since = Notice::getAsTimestamp($id);
1948 return sprintf("($createdField = '%s' and $idField > %d) or ($createdField > '%s')", $since, $id, $since);
1954 * Build an SQL 'where' fragment for timestamp-based sorting from a since_id
1955 * parameter, matching notices posted after the given one (exclusive), and
1956 * if necessary add it to the data object's query.
1958 * @param DB_DataObject $obj
1960 * @param string $idField
1961 * @param string $createdField
1962 * @return mixed string or false if no match
1964 public static function addWhereSinceId(DB_DataObject $obj, $id, $idField='id', $createdField='created')
1966 $since = self::whereSinceId($id, $idField, $createdField);
1968 $obj->whereAdd($since);
1973 * Build an SQL 'where' fragment for timestamp-based sorting from a max_id
1974 * parameter, matching notices posted before the given one (inclusive).
1976 * If the referenced notice can't be found, will return false.
1979 * @param string $idField
1980 * @param string $createdField
1981 * @return mixed string or false if no match
1983 public static function whereMaxId($id, $idField='id', $createdField='created')
1985 $max = Notice::getAsTimestamp($id);
1987 return sprintf("($createdField < '%s') or ($createdField = '%s' and $idField <= %d)", $max, $max, $id);
1993 * Build an SQL 'where' fragment for timestamp-based sorting from a max_id
1994 * parameter, matching notices posted before the given one (inclusive), and
1995 * if necessary add it to the data object's query.
1997 * @param DB_DataObject $obj
1999 * @param string $idField
2000 * @param string $createdField
2001 * @return mixed string or false if no match
2003 public static function addWhereMaxId(DB_DataObject $obj, $id, $idField='id', $createdField='created')
2005 $max = self::whereMaxId($id, $idField, $createdField);
2007 $obj->whereAdd($max);
2013 if (common_config('public', 'localonly')) {
2014 return ($this->is_local == Notice::LOCAL_PUBLIC);
2016 return (($this->is_local != Notice::LOCAL_NONPUBLIC) &&
2017 ($this->is_local != Notice::GATEWAY));
2022 * Check that the given profile is allowed to read, respond to, or otherwise
2023 * act on this notice.
2025 * The $scope member is a bitmask of scopes, representing a logical AND of the
2026 * scope requirement. So, 0x03 (Notice::ADDRESSEE_SCOPE | Notice::SITE_SCOPE) means
2027 * "only visible to people who are mentioned in the notice AND are users on this site."
2028 * Users on the site who are not mentioned in the notice will not be able to see the
2031 * @param Profile $profile The profile to check
2033 * @return boolean whether the profile is in the notice's scope
2036 function inScope($profile)
2038 // If there's any scope, and there's no logged-in user,
2041 if ($this->scope > 0 && empty($profile)) {
2045 // Only for users on this site
2047 if ($this->scope & Notice::SITE_SCOPE) {
2048 $user = $profile->getUser();
2054 // Only for users mentioned in the notice
2056 if ($this->scope & Notice::ADDRESSEE_SCOPE) {
2058 // XXX: just query for the single reply
2060 $replies = $this->getReplies();
2062 if (!in_array($profile->id, $replies)) {
2067 // Only for members of the given group
2069 if ($this->scope & Notice::GROUP_SCOPE) {
2071 // XXX: just query for the single membership
2073 $groups = $this->getGroups();
2077 foreach ($groups as $group) {
2078 if ($profile->isMember($group)) {
2089 // Only for followers of the author
2091 if ($this->scope & Notice::FOLLOWER_SCOPE) {
2092 $author = $this->getProfile();
2093 if (!Subscription::exists($profile, $author)) {