* Add Types

* Add Types
This commit is contained in:
Zach H 2024-06-17 00:32:36 -04:00 committed by GitHub
parent 0994d10410
commit c4bf9eb61c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 207 additions and 737 deletions

View file

@ -3,10 +3,7 @@ import { AdminPersistence } from '../../persistence';
export function adjustMod(userName: string, shouldBeMod?: boolean, shouldBeJudge?: boolean): void {
const command = webClient.protobuf.controller.Command_AdjustMod.create({ userName, shouldBeMod, shouldBeJudge });
const sc = webClient.protobuf.controller.AdminCommand.create({
'.Command_AdjustMod.ext': command
});
const sc = webClient.protobuf.controller.AdminCommand.create({ '.Command_AdjustMod.ext': command });
webClient.protobuf.sendAdminCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { AdminPersistence } from '../../persistence';
export function reloadConfig(): void {
const command = webClient.protobuf.controller.Command_ReloadConfig.create();
const sc = webClient.protobuf.controller.AdminCommand.create({
'.Command_ReloadConfig.ext': command
});
const sc = webClient.protobuf.controller.AdminCommand.create({ '.Command_ReloadConfig.ext': command });
webClient.protobuf.sendAdminCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { AdminPersistence } from '../../persistence';
export function shutdownServer(reason: string, minutes: number): void {
const command = webClient.protobuf.controller.Command_ShutdownServer.create({ reason, minutes });
const sc = webClient.protobuf.controller.AdminCommand.create({
'.Command_ShutdownServer.ext': command
});
const sc = webClient.protobuf.controller.AdminCommand.create({ '.Command_ShutdownServer.ext': command });
webClient.protobuf.sendAdminCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { AdminPersistence } from '../../persistence';
export function updateServerMessage(): void {
const command = webClient.protobuf.controller.Command_UpdateServerMessage.create();
const sc = webClient.protobuf.controller.AdminCommand.create({
'.Command_UpdateServerMessage.ext': command
});
const sc = webClient.protobuf.controller.AdminCommand.create({ '.Command_UpdateServerMessage.ext': command });
webClient.protobuf.sendAdminCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -6,10 +6,7 @@ export function banFromServer(minutes: number, userName?: string, address?: stri
const command = webClient.protobuf.controller.Command_BanFromServer.create({
minutes, userName, address, reason, visibleReason, clientid, removeMessages
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_BanFromServer.ext': command
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_BanFromServer.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { ModeratorPersistence } from '../../persistence';
export function getBanHistory(userName: string): void {
const command = webClient.protobuf.controller.Command_GetBanHistory.create({ userName });
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_GetBanHistory.ext': command
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_GetBanHistory.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { ModeratorPersistence } from '../../persistence';
export function getWarnHistory(userName: string): void {
const command = webClient.protobuf.controller.Command_GetWarnHistory.create({ userName });
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_GetWarnHistory.ext': command
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_GetWarnHistory.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { ModeratorPersistence } from '../../persistence';
export function getWarnList(modName: string, userName: string, userClientid: string): void {
const command = webClient.protobuf.controller.Command_GetWarnList.create({ modName, userName, userClientid });
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_GetWarnList.ext': command
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_GetWarnList.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -1,12 +1,10 @@
import webClient from '../../WebClient';
import { ModeratorPersistence } from '../../persistence';
import { LogFilters } from 'types';
export function viewLogHistory(filters): void {
export function viewLogHistory(filters: LogFilters): void {
const command = webClient.protobuf.controller.Command_ViewLogHistory.create(filters);
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_ViewLogHistory.ext': command
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_ViewLogHistory.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { ModeratorPersistence } from '../../persistence';
export function warnUser(userName: string, reason: string, clientid?: string, removeMessage?: boolean): void {
const command = webClient.protobuf.controller.Command_BanFromServer.create({ userName, reason, clientid, removeMessage });
const sc = webClient.protobuf.controller.ModeratorCommand.create({
'.Command_WarnUser.ext': command
});
const sc = webClient.protobuf.controller.ModeratorCommand.create({ '.Command_WarnUser.ext': command });
webClient.protobuf.sendModeratorCommand(sc, (raw) => {
const { responseCode } = raw;

View file

@ -1,75 +0,0 @@
import { RoomPersistence } from '../../persistence';
import webClient from '../../WebClient';
import { leaveRoom, roomSay } from './';
describe.skip('RoomCommands', () => {
const roomId = 1;
let sendRoomCommandSpy;
beforeEach(() => {
sendRoomCommandSpy = jest.spyOn(webClient.protobuf, 'sendRoomCommand').mockImplementation(() => {});
webClient.protobuf.controller.RoomCommand = { create: args => args };
});
afterEach(() => {
jest.restoreAllMocks();
});
describe('roomSay', () => {
beforeEach(() => {
webClient.protobuf.controller.Command_RoomSay = { create: args => args };
});
it('should call protobuf controller methods and sendCommand', () => {
const message = ' message ';
roomSay(roomId, message);
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(roomId, {
'.Command_RoomSay.ext': { message: message.trim() }
});
});
it('should not call sendRoomCommand if trimmed message is empty', () => {
const message = ' ';
roomSay(roomId, message);
expect(webClient.protobuf.sendRoomCommand).not.toHaveBeenCalled();
});
});
describe('leaveRoom', () => {
beforeEach(() => {
webClient.protobuf.controller.Command_LeaveRoom = { create: () => ({}) };
});
it('should call protobuf controller methods and sendCommand', () => {
leaveRoom(roomId);
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalled();
expect(webClient.protobuf.sendRoomCommand).toHaveBeenCalledWith(
roomId,
{ '.Command_LeaveRoom.ext': {} },
expect.any(Function)
);
});
it('should call RoomPersistence.leaveRoom if RespOk', () => {
const RespOk = 'ok';
webClient.protobuf.controller.Response = { ResponseCode: { RespOk } };
sendRoomCommandSpy.mockImplementation((_, __, callback) => {
callback({ responseCode: RespOk })
});
jest.spyOn(RoomPersistence, 'leaveRoom').mockImplementation(() => {});
leaveRoom(roomId);
expect(RoomPersistence.leaveRoom).toHaveBeenCalledWith(roomId);
});
});
});

View file

@ -2,11 +2,8 @@ import { RoomPersistence } from '../../persistence';
import webClient from '../../WebClient';
export function leaveRoom(roomId: number): void {
const CmdLeaveRoom = webClient.protobuf.controller.Command_LeaveRoom.create();
const rc = webClient.protobuf.controller.RoomCommand.create({
'.Command_LeaveRoom.ext': CmdLeaveRoom
});
const command = webClient.protobuf.controller.Command_LeaveRoom.create();
const rc = webClient.protobuf.controller.RoomCommand.create({ '.Command_LeaveRoom.ext': command });
webClient.protobuf.sendRoomCommand(roomId, rc, (raw) => {
const { responseCode } = raw;

View file

@ -7,13 +7,8 @@ export function roomSay(roomId: number, message: string): void {
return;
}
const CmdRoomSay = webClient.protobuf.controller.Command_RoomSay.create({
'message': trimmed
});
const rc = webClient.protobuf.controller.RoomCommand.create({
'.Command_RoomSay.ext': CmdRoomSay
});
const command = webClient.protobuf.controller.Command_RoomSay.create({ 'message': trimmed });
const rc = webClient.protobuf.controller.RoomCommand.create({ '.Command_RoomSay.ext': command });
webClient.protobuf.sendRoomCommand(roomId, rc);
}

View file

@ -3,10 +3,7 @@ import { SessionPersistence } from '../../persistence';
export function accountEdit(passwordCheck: string, realName?: string, email?: string, country?: string): void {
const command = webClient.protobuf.controller.Command_AccountEdit.create({ passwordCheck, realName, email, country });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_AccountEdit.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountEdit.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -1,14 +1,9 @@
import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence';
import { common } from 'protobufjs';
import IBytesValue = common.IBytesValue;
export function accountImage(image: IBytesValue): void {
export function accountImage(image: unknown): void {
const command = webClient.protobuf.controller.Command_AccountImage.create({ image });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_AccountImage.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountImage.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { SessionPersistence } from '../../persistence';
export function accountPassword(oldPassword: string, newPassword: string, hashedNewPassword: string): void {
const command = webClient.protobuf.controller.Command_AccountPassword.create({ oldPassword, newPassword, hashedNewPassword });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_AccountPassword.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AccountPassword.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -15,11 +15,8 @@ export function activate(options: WebSocketConnectOptions, passwordSalt?: string
token,
};
const CmdActivate = webClient.protobuf.controller.Command_Activate.create(accountActivationConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_Activate.ext': CmdActivate
});
const command = webClient.protobuf.controller.Command_Activate.create(accountActivationConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Activate.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespActivationAccepted) {

View file

@ -1,4 +1,5 @@
import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence';
export function addToBuddyList(userName: string): void {
addToList('buddy', userName);
@ -9,13 +10,16 @@ export function addToIgnoreList(userName: string): void {
}
export function addToList(list: string, userName: string): void {
const CmdAddToList = webClient.protobuf.controller.Command_AddToList.create({ list, userName });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_AddToList.ext': CmdAddToList
});
const command = webClient.protobuf.controller.Command_AddToList.create({ list, userName });
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_AddToList.ext': command });
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
// @TODO: filter responseCode, pop snackbar for error
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.addToList(list, userName);
break;
default:
console.error('Failed to add to list', responseCode);
}
});
}

View file

@ -14,11 +14,8 @@ export function forgotPasswordChallenge(options: WebSocketConnectOptions): void
email,
};
const CmdForgotPasswordChallenge = webClient.protobuf.controller.Command_ForgotPasswordChallenge.create(forgotPasswordChallengeConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ForgotPasswordChallenge.ext': CmdForgotPasswordChallenge
});
const command = webClient.protobuf.controller.Command_ForgotPasswordChallenge.create(forgotPasswordChallengeConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordChallenge.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {

View file

@ -22,11 +22,8 @@ export function forgotPasswordRequest(options: WebSocketConnectOptions, password
forgotPasswordResetConfig.newPassword = newPassword;
}
const CmdForgotPasswordReset = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ForgotPasswordReset.ext': CmdForgotPasswordReset
});
const command = webClient.protobuf.controller.Command_ForgotPasswordReset.create(forgotPasswordResetConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordReset.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {

View file

@ -3,10 +3,7 @@ import { SessionPersistence } from '../../persistence';
export function getGamesOfUser(userName: string): void {
const command = webClient.protobuf.controller.Command_GetGamesOfUser.create({ userName });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_GetGamesOfUser.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_GetGamesOfUser.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -3,10 +3,7 @@ import { SessionPersistence } from '../../persistence';
export function getUserInfo(userName: string): void {
const command = webClient.protobuf.controller.Command_GetUserInfo.create({ userName });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_GetUserInfo.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_GetUserInfo.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -2,16 +2,13 @@ import webClient from '../../WebClient';
import { RoomPersistence } from '../../persistence';
export function joinRoom(roomId: number): void {
const CmdJoinRoom = webClient.protobuf.controller.Command_JoinRoom.create({ roomId });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_JoinRoom.ext': CmdJoinRoom
});
const command = webClient.protobuf.controller.Command_JoinRoom.create({ roomId });
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_JoinRoom.ext': command });
webClient.protobuf.sendSessionCommand(sc, (raw) => {
const { responseCode } = raw;
let error;
let error: string;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:

View file

@ -1,11 +1,8 @@
import webClient from '../../WebClient';
export function listRooms(): void {
const CmdListRooms = webClient.protobuf.controller.Command_ListRooms.create();
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ListRooms.ext': CmdListRooms
});
const command = webClient.protobuf.controller.Command_ListRooms.create();
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ListRooms.ext': command });
webClient.protobuf.sendSessionCommand(sc);
}

View file

@ -2,11 +2,8 @@ import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence';
export function listUsers(): void {
const CmdListUsers = webClient.protobuf.controller.Command_ListUsers.create();
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ListUsers.ext': CmdListUsers
});
const command = webClient.protobuf.controller.Command_ListUsers.create();
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ListUsers.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -25,13 +25,10 @@ export function login(options: WebSocketConnectOptions, passwordSalt?: string):
loginConfig.password = password;
}
const CmdLogin = webClient.protobuf.controller.Command_Login.create(loginConfig);
const command = webClient.protobuf.controller.Command_Login.create(loginConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Login.ext': command });
const command = webClient.protobuf.controller.SessionCommand.create({
'.Command_Login.ext': CmdLogin
});
webClient.protobuf.sendSessionCommand(command, raw => {
webClient.protobuf.sendSessionCommand(sc, raw => {
const resp = raw['.Response_Login.ext'];
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {

View file

@ -3,10 +3,7 @@ import { SessionPersistence } from '../../persistence';
export function message(userName: string, message: string): void {
const command = webClient.protobuf.controller.Command_Message.create({ userName, message });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_Message.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Message.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;

View file

@ -1,12 +1,8 @@
import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence';
export function ping(pingReceived: Function): void {
const command = webClient.protobuf.controller.Command_Ping.create();
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_Ping.ext': command
});
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Ping.ext': command });
webClient.protobuf.sendSessionCommand(sc, pingReceived);
}

View file

@ -25,11 +25,8 @@ export function register(options: WebSocketConnectOptions, passwordSalt?: string
registerConfig.password = password;
}
const CmdRegister = webClient.protobuf.controller.Command_Register.create(registerConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_Register.ext': CmdRegister
});
const command = webClient.protobuf.controller.Command_Register.create(registerConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_Register.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespRegistrationAccepted) {
@ -46,7 +43,6 @@ export function register(options: WebSocketConnectOptions, passwordSalt?: string
SessionPersistence.registrationUserNameError('Username is taken');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespUsernameInvalid:
console.error('ResponseCode.RespUsernameInvalid', raw.reasonStr);
SessionPersistence.registrationUserNameError('Invalid username');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespPasswordTooShort:
@ -65,7 +61,7 @@ export function register(options: WebSocketConnectOptions, passwordSalt?: string
SessionPersistence.registrationFailed('Registration is currently disabled');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespUserIsBanned:
SessionPersistence.registrationFailed(NormalizeService.normalizeBannedUserError(raw.reasonStr, raw.endTime));
SessionPersistence.registrationFailed(raw.reasonStr, raw.endTime);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespRegistrationFailed:
default:

View file

@ -1,4 +1,5 @@
import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence';
export function removeFromBuddyList(userName: string): void {
removeFromList('buddy', userName);
@ -9,13 +10,16 @@ export function removeFromIgnoreList(userName: string): void {
}
export function removeFromList(list: string, userName: string): void {
const CmdRemoveFromList = webClient.protobuf.controller.Command_RemoveFromList.create({ list, userName });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_RemoveFromList.ext': CmdRemoveFromList
});
const command = webClient.protobuf.controller.Command_RemoveFromList.create({ list, userName });
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_RemoveFromList.ext': command });
webClient.protobuf.sendSessionCommand(sc, ({ responseCode }) => {
// @TODO: filter responseCode, pop snackbar for error
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.removeFromList(list, userName);
break;
default:
console.error('Failed to remove from list', responseCode);
}
});
}

View file

@ -20,11 +20,8 @@ export function requestPasswordSalt(options: WebSocketConnectOptions): void {
userName,
};
const CmdRequestPasswordSalt = webClient.protobuf.controller.Command_RequestPasswordSalt.create(registerConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_RequestPasswordSalt.ext': CmdRequestPasswordSalt
});
const command = webClient.protobuf.controller.Command_RequestPasswordSalt.create(registerConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_RequestPasswordSalt.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
switch (raw.responseCode) {

View file

@ -14,11 +14,8 @@ export function resetPasswordRequest(options: WebSocketConnectOptions): void {
userName,
};
const CmdForgotPasswordRequest = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_ForgotPasswordRequest.ext': CmdForgotPasswordRequest
});
const command = webClient.protobuf.controller.Command_ForgotPasswordRequest.create(forgotPasswordConfig);
const sc = webClient.protobuf.controller.SessionCommand.create({ '.Command_ForgotPasswordRequest.ext': command });
webClient.protobuf.sendSessionCommand(sc, raw => {
if (raw.responseCode === webClient.protobuf.controller.Response.ResponseCode.RespOk) {