diff --git a/webclient/src/api/SessionService.tsx b/webclient/src/api/SessionService.tsx index a1605a683..c1fbeddbd 100644 --- a/webclient/src/api/SessionService.tsx +++ b/webclient/src/api/SessionService.tsx @@ -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); + } } diff --git a/webclient/src/websocket/commands/session/accountEdit.ts b/webclient/src/websocket/commands/session/accountEdit.ts new file mode 100644 index 000000000..582a31b4a --- /dev/null +++ b/webclient/src/websocket/commands/session/accountEdit.ts @@ -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'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/accountImage.ts b/webclient/src/websocket/commands/session/accountImage.ts new file mode 100644 index 000000000..243c43ccc --- /dev/null +++ b/webclient/src/websocket/commands/session/accountImage.ts @@ -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'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/accountPassword.ts b/webclient/src/websocket/commands/session/accountPassword.ts new file mode 100644 index 000000000..c07e830cb --- /dev/null +++ b/webclient/src/websocket/commands/session/accountPassword.ts @@ -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'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/getUserInfo.ts b/webclient/src/websocket/commands/session/getUserInfo.ts new file mode 100644 index 000000000..33da8da4b --- /dev/null +++ b/webclient/src/websocket/commands/session/getUserInfo.ts @@ -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'); + } + }); +} diff --git a/webclient/src/websocket/commands/session/index.ts b/webclient/src/websocket/commands/session/index.ts index 12b2e407d..16e34ee7c 100644 --- a/webclient/src/websocket/commands/session/index.ts +++ b/webclient/src/websocket/commands/session/index.ts @@ -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'; diff --git a/webclient/src/websocket/commands/session/message.ts b/webclient/src/websocket/commands/session/message.ts new file mode 100644 index 000000000..35dda60d2 --- /dev/null +++ b/webclient/src/websocket/commands/session/message.ts @@ -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'); + } + }); +} diff --git a/webclient/src/websocket/persistence/SessionPersistence.ts b/webclient/src/websocket/persistence/SessionPersistence.ts index e97fb3fbb..81e77458d 100644 --- a/webclient/src/websocket/persistence/SessionPersistence.ts +++ b/webclient/src/websocket/persistence/SessionPersistence.ts @@ -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'); + } }