123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- defined('GNUSOCIAL') || die();
- class ApiStatusesFavsAction extends ApiAuthAction
- {
- const MAXCOUNT = 100;
-
- public $original = null;
- public $cnt = self::MAXCOUNT;
-
- protected function prepare(array $args = [])
- {
- parent::prepare($args);
- if ($this->format !== 'json') {
- $this->clientError('This method currently only serves JSON.', 415);
- }
- $id = $this->trimmed('id');
- $this->original = Notice::getKV('id', $id);
- if (!($this->original instanceof Notice)) {
-
- $this->clientError(_('No such notice.'), 400);
- }
- $cnt = $this->trimmed('count');
- if (empty($cnt) || !is_integer($cnt)) {
- $cnt = 100;
- } else {
- $this->cnt = min((int)$cnt, self::MAXCOUNT);
- }
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- $fave = new Fave();
- $fave->selectAdd();
- $fave->selectAdd('user_id');
- $fave->notice_id = $this->original->id;
- $fave->orderBy('modified, user_id');
- if (!is_null($this->cnt)) {
- $fave->limit(0, $this->cnt);
- }
- $ids = $fave->fetchAll('user_id');
-
- $ids_with_profile_data = [];
- foreach (array_values($ids) as $i => $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;
- }
- $this->initDocument('json');
- $this->showJsonObjects($ids_with_profile_data);
- $this->endDocument('json');
- }
-
- public function isReadOnly($args)
- {
- return true;
- }
- }
|