* 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 { 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) {