Added RPC for emotes list.

This commit is contained in:
flash 2024-11-14 02:44:02 +00:00
parent 8e006c7003
commit 058b409adf
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,40 @@
<?php
namespace Misuzu\Emoticons;
use Index\XArray;
use RPCii\Server\{RpcHandler,RpcHandlerCommon,RpcQuery};
final class EmotesRpcHandler implements RpcHandler {
use RpcHandlerCommon;
public function __construct(
private Emotes $emotes
) {}
#[RpcQuery('misuzu:emotes:all')]
public function queryAll(bool $includeId = false, bool $includeOrder = false): array {
return XArray::select(
$this->emotes->getEmotes(orderBy: 'order'),
function($emote) use ($includeId, $includeOrder) {
$info = [
'url' => $emote->getUrl(),
'strings' => XArray::select(
$this->emotes->getEmoteStrings($emote),
fn($string) => $string->getString()
),
];
if($includeId)
$info['id'] = $emote->getId();
if($includeOrder)
$info['order'] = $emote->getOrder();
$rank = $emote->getMinRank();
if($rank != 0)
$info['min_rank'] = $rank;
return $info;
}
);
}
}

View file

@ -292,6 +292,10 @@ class MisuzuContext {
$this->authCtx
));
$rpcServer->register(new Emoticons\EmotesRpcHandler(
$this->emotes
));
$rpcServer->register(new Users\UsersRpcHandler(
$this->siteInfo,
$this->urls,