/** * Get IDs in a range * * @param int $offset Offset from start * @param int $limit Limit of number to get * @param int $since_id Since this notice * @param int $max_id Before this notice * * @return Array IDs found */ function getNoticeIds($offset, $limit, $since_id, $max_id) { $notice = new Notice(); $notice->selectAdd(); $notice->selectAdd('id'); $notice->whereAdd(sprintf('notice.created > "%s"', $notice->escape($this->target->created))); // Reply:: is a table of mentions // Subscription:: is a table of subscriptions (every user is subscribed to themselves) $notice->whereAdd(sprintf('( notice.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d) ' . 'OR notice.id IN (SELECT notice_id FROM group_inbox WHERE group_id IN (SELECT group_id FROM group_member WHERE profile_id=%1$d))' . 'OR notice.id IN (SELECT notice_id FROM attention WHERE profile_id=%1$d) ) ' . 'AND (notice.reply_to IS NULL ' . 'OR notice.profile_id=%1$d ' . 'OR notice.reply_to IN (SELECT id FROM notice as noticereplies WHERE noticereplies.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d))) ' . 'OR (notice.id IN (SELECT notice_id FROM reply WHERE profile_id=%1$d) ' . 'AND notice.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d))', $this->target->id)); if (!empty($since_id)) { $notice->whereAdd(sprintf('notice.id > %d', $since_id)); } if (!empty($max_id)) { $notice->whereAdd(sprintf('notice.id <= %d', $max_id)); } if (!empty($this->selectVerbs)) { $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb')); } $notice->limit($offset, $limit); // notice.id will give us even really old posts, which were // recently imported. For example if a remote instance had // problems and just managed to post here. Another solution // would be to have a 'notice.imported' field and order by it. $notice->orderBy('notice.id DESC'); if (!$notice->find()) { return array(); } $ids = $notice->fetchAll('id'); return $ids; }
function getNoticeIds($offset, $limit, $since_id = null, $max_id = null) { $notice = new Notice(); // SELECT $notice->selectAdd(); $notice->selectAdd('id'); // WHERE $notice->conversation = $this->id; if (!empty($since_id)) { $notice->whereAdd(sprintf('notice.id > %d', $since_id)); } if (!empty($max_id)) { $notice->whereAdd(sprintf('notice.id <= %d', $max_id)); } if (!is_null($offset)) { $notice->limit($offset, $limit); } if (!empty($this->selectVerbs)) { $notice->whereAddIn('verb', $this->selectVerbs, $notice->columnType('verb')); } // ORDER BY // currently imitates the previously used "_reverseChron" sorting $notice->orderBy('notice.created DESC'); $notice->find(); return $notice->fetchAll('id'); }
function _repeatStreamDirect($limit) { $notice = new Notice(); $notice->selectAdd(); // clears it $notice->selectAdd('id'); $notice->repeat_of = $this->id; $notice->orderBy('created, id'); // NB: asc! if (!is_null($limit)) { $notice->limit(0, $limit); } return $notice->fetchAll('id'); }
/** * Handle the request * * Check the format and show the user info * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); // favs $fave = new Fave(); $fave->selectAdd(); $fave->selectAdd('user_id'); $fave->selectAdd('modified'); $fave->notice_id = $this->original->id; $fave->orderBy('modified'); if (!is_null($this->cnt)) { $fave->limit(0, $this->cnt); } $fav_ids = $fave->fetchAll('user_id', 'modified'); // get nickname and profile image $fav_ids_with_profile_data = array(); $i = 0; foreach ($fav_ids as $id => $time) { $profile = Profile::getKV('id', $id); $fav_ids_with_profile_data[$i]['user_id'] = $id; $fav_ids_with_profile_data[$i]['nickname'] = $profile->nickname; $fav_ids_with_profile_data[$i]['fullname'] = $profile->fullname; $fav_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; $fav_ids_with_profile_data[$i]['time'] = strtotime($time); $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(48); $fav_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; } // repeats $notice = new Notice(); $notice->selectAdd(); // clears it $notice->selectAdd('profile_id'); $notice->selectAdd('created'); $notice->repeat_of = $this->original->id; $notice->orderBy('created, id'); // NB: asc! if (!is_null($this->cnt)) { $notice->limit(0, $this->cnt); } $repeat_ids = $notice->fetchAll('profile_id', 'created'); // get nickname and profile image $repeat_ids_with_profile_data = array(); $i = 0; foreach ($repeat_ids as $id => $time) { $profile = Profile::getKV('id', $id); $repeat_ids_with_profile_data[$i]['user_id'] = $id; $repeat_ids_with_profile_data[$i]['nickname'] = $profile->nickname; $repeat_ids_with_profile_data[$i]['fullname'] = $profile->fullname; $repeat_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; $repeat_ids_with_profile_data[$i]['time'] = strtotime($time); $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(48); $repeat_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; } $favs_and_repeats = array('favs' => $fav_ids_with_profile_data, 'repeats' => $repeat_ids_with_profile_data); $this->initDocument('json'); $this->showJsonObjects($favs_and_repeats); $this->endDocument('json'); }
/** * Handle the request * * Check the format and show the user info * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); // since this api method is in practice only used when expanding a // notice, we can assume the user has seen the notice in question, // an no longer need a notification about it. mark reply/mention- // notifications tied to this notice and the current profile as read if ($this->auth_user) { QvitterPlugin::markNotificationAsSeen($this->notice_id, $this->auth_user->id, 'mention'); QvitterPlugin::markNotificationAsSeen($this->notice_id, $this->auth_user->id, 'reply'); } // favs $fave = new Fave(); $fave->selectAdd(); $fave->selectAdd('user_id'); $fave->selectAdd('modified'); $fave->notice_id = $this->original->id; $fave->orderBy('modified'); if (!is_null($this->cnt)) { $fave->limit(0, $this->cnt); } $fav_ids = $fave->fetchAll('user_id', 'modified'); // get nickname and profile image $fav_ids_with_profile_data = array(); $i = 0; foreach ($fav_ids as $id => $time) { $profile = Profile::getKV('id', $id); $fav_ids_with_profile_data[$i]['user_id'] = $id; $fav_ids_with_profile_data[$i]['nickname'] = $profile->nickname; $fav_ids_with_profile_data[$i]['fullname'] = $profile->fullname; $fav_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; $fav_ids_with_profile_data[$i]['time'] = strtotime($time); $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(48); $fav_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; } // repeats $notice = new Notice(); $notice->selectAdd(); // clears it $notice->selectAdd('profile_id'); $notice->selectAdd('created'); $notice->repeat_of = $this->original->id; $notice->verb = ActivityVerb::SHARE; $notice->orderBy('created, id'); // NB: asc! if (!is_null($this->cnt)) { $notice->limit(0, $this->cnt); } $repeat_ids = $notice->fetchAll('profile_id', 'created'); // get nickname and profile image $repeat_ids_with_profile_data = array(); $i = 0; foreach ($repeat_ids as $id => $time) { $profile = Profile::getKV('id', $id); $repeat_ids_with_profile_data[$i]['user_id'] = $id; $repeat_ids_with_profile_data[$i]['nickname'] = $profile->nickname; $repeat_ids_with_profile_data[$i]['fullname'] = $profile->fullname; $repeat_ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; $repeat_ids_with_profile_data[$i]['time'] = strtotime($time); $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(48); $repeat_ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; } $favs_and_repeats = array('favs' => $fav_ids_with_profile_data, 'repeats' => $repeat_ids_with_profile_data); $this->initDocument('json'); $this->showJsonObjects($favs_and_repeats); $this->endDocument('json'); }
/** * Show search results * * @return void */ function showResults() { // TODO: Support search operators like from: and to:, boolean, etc. $notice = new Notice(); $this->notices = array(); $search_engine = $notice->getSearchEngine('notice'); $search_engine->set_sort_mode('chron'); $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1); if ($search_engine->query($this->query)) { $cnt = $notice->find(); $this->notices = $notice->fetchAll(); } $this->showJsonTimeline($this->notices); }