Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
39be84fcc0 | |||
242e70eabf | |||
174ceaa4e7 | |||
058b409adf |
4 changed files with 72 additions and 18 deletions
40
src/Emoticons/EmotesRpcHandler.php
Normal file
40
src/Emoticons/EmotesRpcHandler.php
Normal 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;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -269,7 +269,8 @@ class MisuzuContext {
|
||||||
$this->authCtx,
|
$this->authCtx,
|
||||||
$this->emotes,
|
$this->emotes,
|
||||||
$this->perms,
|
$this->perms,
|
||||||
$this->authInfo
|
$this->authInfo,
|
||||||
|
$this->counters
|
||||||
));
|
));
|
||||||
|
|
||||||
$routingCtx->register(new \Misuzu\Satori\SatoriRoutes(
|
$routingCtx->register(new \Misuzu\Satori\SatoriRoutes(
|
||||||
|
@ -292,6 +293,10 @@ class MisuzuContext {
|
||||||
$this->authCtx
|
$this->authCtx
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$rpcServer->register(new Emoticons\EmotesRpcHandler(
|
||||||
|
$this->emotes
|
||||||
|
));
|
||||||
|
|
||||||
$rpcServer->register(new Users\UsersRpcHandler(
|
$rpcServer->register(new Users\UsersRpcHandler(
|
||||||
$this->siteInfo,
|
$this->siteInfo,
|
||||||
$this->urls,
|
$this->urls,
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace Misuzu\SharpChat;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Misuzu\RoutingContext;
|
use Misuzu\RoutingContext;
|
||||||
use Misuzu\Auth\{AuthContext,AuthInfo,Sessions};
|
use Misuzu\Auth\{AuthContext,AuthInfo,Sessions};
|
||||||
|
use Misuzu\Counters\Counters;
|
||||||
use Misuzu\Emoticons\Emotes;
|
use Misuzu\Emoticons\Emotes;
|
||||||
use Misuzu\Perms\Permissions;
|
use Misuzu\Perms\Permissions;
|
||||||
use Misuzu\Users\{Bans,UsersContext,UserInfo};
|
use Misuzu\Users\{Bans,UsersContext,UserInfo};
|
||||||
|
@ -25,7 +26,8 @@ final class SharpChatRoutes implements RouteHandler {
|
||||||
private AuthContext $authCtx,
|
private AuthContext $authCtx,
|
||||||
private Emotes $emotes,
|
private Emotes $emotes,
|
||||||
private Permissions $perms,
|
private Permissions $perms,
|
||||||
private AuthInfo $authInfo
|
private AuthInfo $authInfo,
|
||||||
|
private Counters $counters
|
||||||
) {
|
) {
|
||||||
$this->hashKey = $this->config->getString('hashKey', 'woomy');
|
$this->hashKey = $this->config->getString('hashKey', 'woomy');
|
||||||
}
|
}
|
||||||
|
@ -40,6 +42,8 @@ final class SharpChatRoutes implements RouteHandler {
|
||||||
if($request->getMethod() === 'OPTIONS')
|
if($request->getMethod() === 'OPTIONS')
|
||||||
return 204;
|
return 204;
|
||||||
|
|
||||||
|
$this->counters->increment('dev:legacy_emotes_loads');
|
||||||
|
|
||||||
$emotes = $this->emotes->getEmotes(orderBy: 'order');
|
$emotes = $this->emotes->getEmotes(orderBy: 'order');
|
||||||
$out = [];
|
$out = [];
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ final class UsersRpcHandler implements RpcHandler {
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
#[RpcQuery('misuzu:users:getUser')]
|
#[RpcQuery('misuzu:users:getUser')]
|
||||||
public function queryGetUser(string $userId): array {
|
public function queryGetUser(string $userId, bool $includeEMailAddress = false): array {
|
||||||
try {
|
try {
|
||||||
$userInfo = $this->usersCtx->getUserInfo($userId, Users::GET_USER_ID);
|
$userInfo = $this->usersCtx->getUserInfo($userId, Users::GET_USER_ID);
|
||||||
} catch(RuntimeException) {
|
} catch(RuntimeException) {
|
||||||
|
@ -53,33 +53,38 @@ final class UsersRpcHandler implements RpcHandler {
|
||||||
|
|
||||||
$avatars = array_reverse($avatars);
|
$avatars = array_reverse($avatars);
|
||||||
|
|
||||||
$output = [
|
$output = [];
|
||||||
'id' => $userInfo->getId(),
|
|
||||||
'name' => $userInfo->getName(),
|
|
||||||
'colour_raw' => $colourRaw,
|
|
||||||
'colour_css' => $colourCSS,
|
|
||||||
'rank' => $rank,
|
|
||||||
'country_code' => $userInfo->getCountryCode(),
|
|
||||||
'avatar_urls' => $avatars,
|
|
||||||
'profile_url' => $baseUrl . $this->urls->format('user-profile', ['user' => $userInfo->getId()]),
|
|
||||||
'created_at' => $userInfo->getCreatedAt()->toIso8601ZuluString(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if($userInfo->hasLastActive())
|
$output['id'] = $userInfo->getId();
|
||||||
$output['last_active_at'] = $userInfo->getLastActiveAt()->toIso8601ZuluString();
|
$output['name'] = $userInfo->getName();
|
||||||
|
if($includeEMailAddress)
|
||||||
|
$output['email'] = $userInfo->getEMailAddress();
|
||||||
|
|
||||||
|
$output['colour_raw'] = $colourRaw;
|
||||||
|
$output['colour_css'] = $colourCSS;
|
||||||
|
$output['rank'] = $rank;
|
||||||
|
$output['country_code'] = $userInfo->getCountryCode();
|
||||||
|
|
||||||
$roles = XArray::select(
|
$roles = XArray::select(
|
||||||
$this->usersCtx->getRoles()->getRoles(userInfo: $userInfo, hasString: true, orderByRank: true),
|
$this->usersCtx->getRoles()->getRoles(userInfo: $userInfo, hasString: true, orderByRank: true),
|
||||||
fn($roleInfo) => $roleInfo->getString(),
|
fn($roleInfo) => $roleInfo->getString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if(!empty($roles))
|
if(!empty($roles))
|
||||||
$output['roles'] = $roles;
|
$output['roles'] = $roles;
|
||||||
|
if($userInfo->isSuperUser())
|
||||||
|
$output['is_super'] = true;
|
||||||
|
|
||||||
if($userInfo->hasTitle())
|
if($userInfo->hasTitle())
|
||||||
$output['title'] = $userInfo->getTitle();
|
$output['title'] = $userInfo->getTitle();
|
||||||
|
|
||||||
if($userInfo->isSuperUser())
|
$output['created_at'] = $userInfo->getCreatedAt()->toIso8601ZuluString();
|
||||||
$output['is_super'] = true;
|
if($userInfo->hasLastActive())
|
||||||
|
$output['last_active_at'] = $userInfo->getLastActiveAt()->toIso8601ZuluString();
|
||||||
|
|
||||||
|
$output['profile_url'] = $baseUrl . $this->urls->format('user-profile', ['user' => $userInfo->getId()]);
|
||||||
|
$output['avatar_urls'] = $avatars;
|
||||||
|
|
||||||
if($userInfo->isDeleted())
|
if($userInfo->isDeleted())
|
||||||
$output['is_deleted'] = true;
|
$output['is_deleted'] = true;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue