Compare commits

...

2 commits

3 changed files with 51 additions and 2 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

@ -269,7 +269,8 @@ class MisuzuContext {
$this->authCtx,
$this->emotes,
$this->perms,
$this->authInfo
$this->authInfo,
$this->counters
));
$routingCtx->register(new \Misuzu\Satori\SatoriRoutes(
@ -292,6 +293,10 @@ class MisuzuContext {
$this->authCtx
));
$rpcServer->register(new Emoticons\EmotesRpcHandler(
$this->emotes
));
$rpcServer->register(new Users\UsersRpcHandler(
$this->siteInfo,
$this->urls,

View file

@ -4,6 +4,7 @@ namespace Misuzu\SharpChat;
use RuntimeException;
use Misuzu\RoutingContext;
use Misuzu\Auth\{AuthContext,AuthInfo,Sessions};
use Misuzu\Counters\Counters;
use Misuzu\Emoticons\Emotes;
use Misuzu\Perms\Permissions;
use Misuzu\Users\{Bans,UsersContext,UserInfo};
@ -25,7 +26,8 @@ final class SharpChatRoutes implements RouteHandler {
private AuthContext $authCtx,
private Emotes $emotes,
private Permissions $perms,
private AuthInfo $authInfo
private AuthInfo $authInfo,
private Counters $counters
) {
$this->hashKey = $this->config->getString('hashKey', 'woomy');
}
@ -40,6 +42,8 @@ final class SharpChatRoutes implements RouteHandler {
if($request->getMethod() === 'OPTIONS')
return 204;
$this->counters->increment('dev:legacy_emotes_loads');
$emotes = $this->emotes->getEmotes(orderBy: 'order');
$out = [];