diff --git a/actions/apactorlikedcollection.php b/actions/apactorlikedcollection.php index 7ffc020..e36a332 100644 --- a/actions/apactorlikedcollection.php +++ b/actions/apactorlikedcollection.php @@ -39,22 +39,30 @@ class apActorLikedCollectionAction extends ManagedAction { $nickname = $this->trimmed('nickname'); try { - $user = User::getByNickname($nickname); + $user = User::getByNickname($nickname); $profile = $user->getProfile(); - $url = $profile->profileurl; + $url = $profile->profileurl; } catch (Exception $e) { throw new \Exception('Invalid username'); } - // TODO: Implement query parameters as per the doc + $limit = intval($this->trimmed('limit')); + $since_id = intval($this->trimmed('since_id')); + $max_id = intval($this->trimmed('max_id')); - $total_faves = Fave::countByProfile ($profile); + $limit = empty ($limit) ? 40 : $limit; // Default is 40 + $since_id = empty ($since_id) ? null : $since_id; + $max_id = empty ($max_id) ? null : $max_id; - $fave = Fave::byProfile ($user->getID(), 0, $total_faves); + if ($limit > 80) $limit = 80; // Max is 80 + + $fave = $this->fetch_faves ($user->getID(), $limit, $since_id, $max_id); + $total_faves = 0; $faves = []; while ($fave->fetch()) { $faves[] = $this->pretty_fave (clone($fave)); + ++$total_faves; } $res = [ @@ -83,4 +91,24 @@ class apActorLikedCollectionAction extends ManagedAction return $res; } + + private static function fetch_faves ($user_id, $limit = 40, $since_id = null, $max_id = null) + { + $fav = new Fave(); + + $fav->user_id = $user_id; + + $fav->orderBy('modified DESC'); + + if ($since_id != null) + $fav->whereAdd("notice_id > {$since_id}"); + if ($max_id != null) + $fav->whereAdd("notice_id < {$max_id}"); + + $fav->limit($limit); + + $fav->find(); + + return $fav; + } } diff --git a/classes/Activitypub_attachment.php b/classes/Activitypub_attachment.php index 5508e61..08d343d 100644 --- a/classes/Activitypub_attachment.php +++ b/classes/Activitypub_attachment.php @@ -45,7 +45,7 @@ class Activitypub_attachment extends Managed_DataObject 'id' => $attachment->getID (), 'mimetype' => $attachment->mimetype, 'url' => $attachment->getUrl (), - 'size' => $attachment->getSize (), + 'size' => intval($attachment->size), 'title' => $attachment->getTitle (), 'meta' => null ]; diff --git a/classes/Activitypub_notice.php b/classes/Activitypub_notice.php index 7e75108..9671e35 100644 --- a/classes/Activitypub_notice.php +++ b/classes/Activitypub_notice.php @@ -66,7 +66,7 @@ class Activitypub_notice extends Managed_DataObject 'url' => $notice->getUrl(), 'reply_to' => empty($notice->reply_to) ? null : Notice::getById($notice->reply_to)->getUrl(), 'is_local' => $notice->isLocal(), - 'conversation' => $notice->conversation, + 'conversation' => intval($notice->conversation), 'attachment' => $attachments, 'tag' => $tags ];