Add some sessions (#5052)

* Add AccountEdit

* Add PasswordChange

* Cleanup

* Add SessionService.accountImage

* Add SessionService.message

* Add SessionService.getUserInfo

* Lint
This commit is contained in:
Zach H
2024-06-14 23:06:50 -04:00
committed by GitHub
parent 34d70980e8
commit e2ab8db958
8 changed files with 190 additions and 0 deletions

View File

@@ -1,4 +1,6 @@
import { SessionCommands } from 'websocket';
import { common } from 'protobufjs';
import IBytesValue = common.IBytesValue;
export default class SessionService {
static addToBuddyList(userName: string) {
@@ -16,4 +18,24 @@ export default class SessionService {
static removeFromIgnoreList(userName: string) {
SessionCommands.removeFromIgnoreList(userName);
}
static changeAccountPassword(oldPassword: string, newPassword: string, hashedNewPassword?: string): void {
SessionCommands.accountPassword(oldPassword, newPassword, hashedNewPassword);
}
static changeAccountDetails(passwordCheck: string, realName?: string, email?: string, country?: string): void {
SessionCommands.accountEdit(passwordCheck, realName, email, country);
}
static changeAccountImage(image: IBytesValue): void {
SessionCommands.accountImage(image);
}
static sendDirectMessage(userName: string, message: string): void {
SessionCommands.message(userName, message);
}
static getUserInfo(userName: string): void {
SessionCommands.getUserInfo(userName);
}
}

View File

@@ -0,0 +1,28 @@
import webClient from '../../WebClient';
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
});
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.accountEditChanged(realName, email, country);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
console.log('Not allowed');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
console.log('Wrong password');
break;
default:
console.log('Failed to update information');
}
});
}

View File

@@ -0,0 +1,30 @@
import webClient from '../../WebClient';
import { SessionPersistence } from '../../persistence';
import { common } from 'protobufjs';
import IBytesValue = common.IBytesValue;
export function accountImage(image: IBytesValue): void {
const command = webClient.protobuf.controller.Command_AccountImage.create({ image });
const sc = webClient.protobuf.controller.SessionCommand.create({
'.Command_AccountImage.ext': command
});
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.accountImageChanged();
break;
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
console.log('Not allowed');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
console.log('Wrong password');
break;
default:
console.log('Failed to update information');
}
});
}

View File

@@ -0,0 +1,22 @@
import webClient from '../../WebClient';
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
});
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.accountPasswordChange();
break;
default:
console.log('Failed to change password');
}
});
}

View File

@@ -0,0 +1,29 @@
import webClient from '../../WebClient';
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
});
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
const { userInfo } = raw['.Response_GetUserInfo.ext'];
SessionPersistence.getUserInfo(userInfo);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespFunctionNotAllowed:
console.log('Not allowed');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
console.log('Wrong password');
break;
default:
console.log('Failed to update information');
}
});
}

View File

@@ -13,3 +13,8 @@ export * from './resetPassword';
export * from './resetPasswordChallenge'
export * from './resetPasswordRequest';
export * from './updateStatus';
export * from './accountPassword';
export * from './accountEdit';
export * from './accountImage';
export * from './message';
export * from './getUserInfo';

View File

@@ -0,0 +1,34 @@
import webClient from '../../WebClient';
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
});
webClient.protobuf.sendSessionCommand(sc, raw => {
const { responseCode } = raw;
switch (responseCode) {
case webClient.protobuf.controller.Response.ResponseCode.RespOk:
SessionPersistence.directMessageSent(userName, message);
break;
case webClient.protobuf.controller.Response.ResponseCode.RespNameNotFound:
console.log('Name not found');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespInIgnoreList:
console.log('On ignore list');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespChatFlood:
console.log('Flooding chat');
break;
case webClient.protobuf.controller.Response.ResponseCode.RespWrongPassword:
console.log('Wrong password');
break;
default:
console.log('Failed to send direct message');
}
});
}

View File

@@ -144,4 +144,24 @@ export class SessionPersistence {
static resetPasswordFailed() {
ServerDispatch.resetPasswordFailed();
}
static accountPasswordChange(): void {
console.log('accountPassword');
}
static accountEditChanged(realName?: string, email?: string, country?: string): void {
console.log('accountEditChange');
}
static accountImageChanged(): void {
console.log('accountImageChanged');
}
static directMessageSent(userName: string, message: string): void {
console.log('directMessageSent');
}
static getUserInfo(userInfo: string) {
console.log('getUserInfo');
}
}