/** * Handle the request * * Get favs and return them as json object * * @param array $args $_REQUEST data (unused) * * @return void */ protected function handle() { parent::handle(); $fave = new Fave(); $fave->selectAdd(); $fave->selectAdd('user_id'); $fave->notice_id = $this->original->id; $fave->orderBy('modified'); if (!is_null($this->cnt)) { $fave->limit(0, $this->cnt); } $ids = $fave->fetchAll('user_id'); // get nickname and profile image $ids_with_profile_data = array(); $i = 0; foreach ($ids as $id) { $profile = Profile::getKV('id', $id); $ids_with_profile_data[$i]['user_id'] = $id; $ids_with_profile_data[$i]['nickname'] = $profile->nickname; $ids_with_profile_data[$i]['fullname'] = $profile->fullname; $ids_with_profile_data[$i]['profileurl'] = $profile->profileurl; $profile = new Profile(); $profile->id = $id; $avatarurl = $profile->avatarUrl(24); $ids_with_profile_data[$i]['avatarurl'] = $avatarurl; $i++; } $this->initDocument('json'); $this->showJsonObjects($ids_with_profile_data); $this->endDocument('json'); }
function getNoticeIds($offset, $limit, $since_id, $max_id) { $weightexpr = common_sql_weight('modified', common_config('popular', 'dropoff')); $cutoff = sprintf("modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff'))); $fave = new Fave(); $fave->selectAdd(); $fave->selectAdd('notice_id'); $fave->selectAdd("{$weightexpr} as weight"); $fave->whereAdd($cutoff); $fave->orderBy('weight DESC'); $fave->groupBy('notice_id'); if (!is_null($offset)) { $fave->limit($offset, $limit); } // FIXME: $since_id, $max_id are ignored $ids = array(); if ($fave->find()) { while ($fave->fetch()) { $ids[] = $fave->notice_id; } } return $ids; }
/** * 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'); }