function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $inbox = new Group_inbox();
     $inbox->group_id = $this->group->id;
     $inbox->selectAdd();
     $inbox->selectAdd('notice_id');
     Notice::addWhereSinceId($inbox, $since_id, 'notice_id');
     Notice::addWhereMaxId($inbox, $max_id, 'notice_id');
     $inbox->orderBy('created DESC, notice_id DESC');
     if (!is_null($offset)) {
         $inbox->limit($offset, $limit);
     }
     $ids = array();
     if ($inbox->find()) {
         while ($inbox->fetch()) {
             $ids[] = $inbox->notice_id;
         }
     }
     return $ids;
 }
Example #2
0
 function _streamDirect($offset, $limit, $since_id, $max_id)
 {
     $inbox = new Group_inbox();
     $inbox->group_id = $this->id;
     $inbox->selectAdd();
     $inbox->selectAdd('notice_id');
     if ($since_id != 0) {
         $inbox->whereAdd('notice_id > ' . $since_id);
     }
     if ($max_id != 0) {
         $inbox->whereAdd('notice_id <= ' . $max_id);
     }
     $inbox->orderBy('notice_id DESC');
     if (!is_null($offset)) {
         $inbox->limit($offset, $limit);
     }
     $ids = array();
     if ($inbox->find()) {
         while ($inbox->fetch()) {
             $ids[] = $inbox->notice_id;
         }
     }
     return $ids;
 }
Example #3
0
 static function fillGroups(&$notices)
 {
     $ids = self::_idsOf($notices);
     $gis = Group_inbox::listGet('notice_id', $ids);
     $gids = array();
     foreach ($gis as $id => $gi) {
         foreach ($gi as $g) {
             $gids[] = $g->group_id;
         }
     }
     $gids = array_unique($gids);
     $group = User_group::pivotGet('id', $gids);
     foreach ($notices as $notice) {
         $grps = array();
         $gi = $gis[$notice->id];
         foreach ($gi as $g) {
             $grps[] = $group[$g->group_id];
         }
         $notice->_setGroups($grps);
     }
 }
 function onHandleQueuedNotice($notice)
 {
     $paths = array();
     // Add to the author's timeline
     $user = User::staticGet('id', $notice->profile_id);
     if (!empty($user)) {
         $paths[] = array('showstream', $user->nickname);
     }
     // Add to the public timeline
     if ($notice->is_local == Notice::LOCAL_PUBLIC || $notice->is_local == Notice::REMOTE_OMB && !common_config('public', 'localonly')) {
         $paths[] = array('public');
     }
     // Add to the tags timeline
     $tags = $this->getNoticeTags($notice);
     if (!empty($tags)) {
         foreach ($tags as $tag) {
             $paths[] = array('tag', $tag);
         }
     }
     // Add to inbox timelines
     // XXX: do a join
     $ni = $notice->whoGets();
     foreach (array_keys($ni) as $user_id) {
         $user = User::staticGet('id', $user_id);
         $paths[] = array('all', $user->nickname);
     }
     // Add to the replies timeline
     $reply = new Reply();
     $reply->notice_id = $notice->id;
     if ($reply->find()) {
         while ($reply->fetch()) {
             $user = User::staticGet('id', $reply->profile_id);
             if (!empty($user)) {
                 $paths[] = array('replies', $user->nickname);
             }
         }
     }
     // Add to the group timeline
     // XXX: join
     $gi = new Group_inbox();
     $gi->notice_id = $notice->id;
     if ($gi->find()) {
         while ($gi->fetch()) {
             $ug = User_group::staticGet('id', $gi->group_id);
             $paths[] = array('showgroup', $ug->nickname);
         }
     }
     if (count($paths) > 0) {
         $json = $this->noticeAsJson($notice);
         $this->_connect();
         foreach ($paths as $path) {
             $timeline = $this->_pathToChannel($path);
             $this->_publish($timeline, $json);
         }
         $this->_disconnect();
     }
     return true;
 }
Example #5
0
 function clearGroupInboxes()
 {
     $gi = new Group_inbox();
     $gi->notice_id = $this->id;
     if ($gi->find()) {
         while ($gi->fetch()) {
             self::blow('user_group:notice_ids:%d', $gi->group_id);
             $gi->delete();
         }
     }
     $gi->free();
 }
 public function onHandleQueuedNotice(Notice $notice)
 {
     $paths = array();
     // Add to the author's timeline
     try {
         $profile = $notice->getProfile();
     } catch (Exception $e) {
         $this->log(LOG_ERR, $e->getMessage());
         return true;
     }
     try {
         $user = $profile->getUser();
         $paths[] = array('showstream', $user->nickname, null);
     } catch (NoSuchUserException $e) {
         // We really should handle the remote profile views too
         $user = null;
     }
     // Add to the public timeline
     $is_local = intval($notice->is_local);
     if ($is_local === Notice::LOCAL_PUBLIC || $is_local === Notice::REMOTE && !common_config('public', 'localonly')) {
         $paths[] = array('public', null, null);
     }
     // Add to the tags timeline
     $tags = $this->getNoticeTags($notice);
     if (!empty($tags)) {
         foreach ($tags as $tag) {
             $paths[] = array('tag', $tag, null);
         }
     }
     // Add to inbox timelines
     // XXX: do a join
     $ni = $notice->whoGets();
     foreach (array_keys($ni) as $user_id) {
         $user = User::getKV('id', $user_id);
         $paths[] = array('all', $user->nickname, null);
     }
     // Add to the replies timeline
     $reply = new Reply();
     $reply->notice_id = $notice->id;
     if ($reply->find()) {
         while ($reply->fetch()) {
             $user = User::getKV('id', $reply->profile_id);
             if (!empty($user)) {
                 $paths[] = array('replies', $user->nickname, null);
             }
         }
     }
     // Add to the group timeline
     // XXX: join
     $gi = new Group_inbox();
     $gi->notice_id = $notice->id;
     if ($gi->find()) {
         while ($gi->fetch()) {
             $ug = User_group::getKV('id', $gi->group_id);
             $paths[] = array('showgroup', $ug->nickname, null);
         }
     }
     if (count($paths) > 0) {
         $json = $this->noticeAsJson($notice);
         $this->_connect();
         // XXX: We should probably fan-out here and do a
         // new queue item for each path
         foreach ($paths as $path) {
             list($action, $arg1, $arg2) = $path;
             $channels = Realtime_channel::getAllChannels($action, $arg1, $arg2);
             $this->log(LOG_INFO, sprintf(_("%d candidate channels for notice %d"), count($channels), $notice->id));
             foreach ($channels as $channel) {
                 // XXX: We should probably fan-out here and do a
                 // new queue item for each user/path combo
                 if (is_null($channel->user_id)) {
                     $profile = null;
                 } else {
                     $profile = Profile::getKV('id', $channel->user_id);
                 }
                 if ($notice->inScope($profile)) {
                     $this->log(LOG_INFO, sprintf(_("Delivering notice %d to channel (%s, %s, %s) for user '%s'"), $notice->id, $channel->action, $channel->arg1, $channel->arg2, $profile ? $profile->nickname : "<public>"));
                     $timeline = $this->_pathToChannel(array($channel->channel_key));
                     $this->_publish($timeline, $json);
                 }
             }
         }
         $this->_disconnect();
     }
     return true;
 }
Example #7
0
 function saveGroups()
 {
     $enabled = common_config('inboxes', 'enabled');
     if ($enabled !== true && $enabled !== 'transitional') {
         return;
     }
     /* extract all !group */
     $count = preg_match_all('/(?:^|\\s)!([A-Za-z0-9]{1,64})/', strtolower($this->content), $match);
     if (!$count) {
         return true;
     }
     $profile = $this->getProfile();
     /* Add them to the database */
     foreach (array_unique($match[1]) as $nickname) {
         /* XXX: remote groups. */
         $group = User_group::staticGet('nickname', $nickname);
         if (!$group) {
             continue;
         }
         // we automatically add a tag for every group name, too
         $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname), 'notice_id' => $this->id));
         if (is_null($tag)) {
             $this->saveTag($nickname);
         }
         if ($profile->isMember($group)) {
             $gi = new Group_inbox();
             $gi->group_id = $group->id;
             $gi->notice_id = $this->id;
             $gi->created = common_sql_now();
             $result = $gi->insert();
             if (!$result) {
                 common_log_db_error($gi, 'INSERT', __FILE__);
             }
             // FIXME: do this in an offline daemon
             $inbox = new Notice_inbox();
             $UT = common_config('db', 'type') == 'pgsql' ? '"user"' : 'user';
             $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . "SELECT {$UT}.id, " . $this->id . ", '" . $this->created . "', 2 " . "FROM {$UT} JOIN group_member ON {$UT}.id = group_member.profile_id " . 'WHERE group_member.group_id = ' . $group->id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . "WHERE user_id = {$UT}.id " . 'AND notice_id = ' . $this->id . ' )';
             if ($enabled === 'transitional') {
                 $qry .= " AND {$UT}.inboxed = 1";
             }
             $result = $inbox->query($qry);
         }
     }
 }