mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-12 17:14:52 -07:00
refactor web socket layer
This commit is contained in:
parent
19f5eefdd2
commit
141f0e59f5
124 changed files with 927 additions and 853 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_BanFromServer_ext, Command_BanFromServerSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function banFromServer(minutes: number, userName?: string, address?: string, reason?: string,
|
||||
visibleReason?: string, clientid?: string, removeMessages?: number): void {
|
||||
BackendService.sendModeratorCommand(Command_BanFromServer_ext, create(Command_BanFromServerSchema, {
|
||||
webClient.protobuf.sendModeratorCommand(Command_BanFromServer_ext, create(Command_BanFromServerSchema, {
|
||||
minutes, userName, address, reason, visibleReason, clientid, removeMessages
|
||||
}), {
|
||||
onSuccess: () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_ForceActivateUser_ext, Command_ForceActivateUserSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
|
|
@ -7,7 +7,7 @@ import { ModeratorPersistence } from '../../persistence';
|
|||
|
||||
export function forceActivateUser(usernameToActivate: string, moderatorName: string): void {
|
||||
const cmd = create(Command_ForceActivateUserSchema, { usernameToActivate, moderatorName });
|
||||
BackendService.sendModeratorCommand(Command_ForceActivateUser_ext, cmd, {
|
||||
webClient.protobuf.sendModeratorCommand(Command_ForceActivateUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.forceActivateUser(usernameToActivate, moderatorName);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetAdminNotes_ext, Command_GetAdminNotesSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_GetAdminNotes_ext } from 'generated/proto/response_get_admin_notes_pb';
|
||||
|
||||
export function getAdminNotes(userName: string): void {
|
||||
BackendService.sendModeratorCommand(Command_GetAdminNotes_ext, create(Command_GetAdminNotesSchema, { userName }), {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetAdminNotes_ext, create(Command_GetAdminNotesSchema, { userName }), {
|
||||
responseExt: Response_GetAdminNotes_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.getAdminNotes(userName, response.notes);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetBanHistory_ext, Command_GetBanHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_BanHistory_ext } from 'generated/proto/response_ban_history_pb';
|
||||
|
||||
export function getBanHistory(userName: string): void {
|
||||
BackendService.sendModeratorCommand(Command_GetBanHistory_ext, create(Command_GetBanHistorySchema, { userName }), {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetBanHistory_ext, create(Command_GetBanHistorySchema, { userName }), {
|
||||
responseExt: Response_BanHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.banHistory(userName, response.banList);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetWarnHistory_ext, Command_GetWarnHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnHistory_ext } from 'generated/proto/response_warn_history_pb';
|
||||
|
||||
export function getWarnHistory(userName: string): void {
|
||||
BackendService.sendModeratorCommand(Command_GetWarnHistory_ext, create(Command_GetWarnHistorySchema, { userName }), {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetWarnHistory_ext, create(Command_GetWarnHistorySchema, { userName }), {
|
||||
responseExt: Response_WarnHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnHistory(userName, response.warnList);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_GetWarnList_ext, Command_GetWarnListSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_WarnList_ext } from 'generated/proto/response_warn_list_pb';
|
||||
|
||||
export function getWarnList(modName: string, userName: string, userClientid: string): void {
|
||||
BackendService.sendModeratorCommand(Command_GetWarnList_ext, create(Command_GetWarnListSchema, { modName, userName, userClientid }), {
|
||||
webClient.protobuf.sendModeratorCommand(Command_GetWarnList_ext, create(Command_GetWarnListSchema, { modName, userName, userClientid }), {
|
||||
responseExt: Response_WarnList_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.warnListOptions([response]);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,18 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_GrantReplayAccess_ext, Command_GrantReplayAccessSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function grantReplayAccess(replayId: number, moderatorName: string): void {
|
||||
BackendService.sendModeratorCommand(Command_GrantReplayAccess_ext, create(Command_GrantReplayAccessSchema, { replayId, moderatorName }), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.grantReplayAccess(replayId, moderatorName);
|
||||
webClient.protobuf.sendModeratorCommand(
|
||||
Command_GrantReplayAccess_ext,
|
||||
create(Command_GrantReplayAccessSchema, { replayId, moderatorName }),
|
||||
{
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.grantReplayAccess(replayId, moderatorName);
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
vi.mock('../../services/BackendService', () => ({
|
||||
BackendService: {
|
||||
sendModeratorCommand: vi.fn(),
|
||||
},
|
||||
vi.mock('../../WebClient', () => ({
|
||||
__esModule: true,
|
||||
default: { protobuf: { sendModeratorCommand: vi.fn() } },
|
||||
}));
|
||||
|
||||
vi.mock('../../persistence', () => ({
|
||||
|
|
@ -20,7 +19,7 @@ vi.mock('../../persistence', () => ({
|
|||
}));
|
||||
|
||||
import { makeCallbackHelpers } from '../../__mocks__/callbackHelpers';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import {
|
||||
Command_BanFromServer_ext,
|
||||
|
|
@ -53,7 +52,7 @@ import { warnUser } from './warnUser';
|
|||
import { Mock } from 'vitest';
|
||||
|
||||
const { invokeOnSuccess } = makeCallbackHelpers(
|
||||
BackendService.sendModeratorCommand as Mock,
|
||||
webClient.protobuf.sendModeratorCommand as Mock,
|
||||
2
|
||||
);
|
||||
|
||||
|
|
@ -66,7 +65,7 @@ describe('banFromServer', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_BanFromServer', () => {
|
||||
banFromServer(30, 'alice', '1.2.3.4', 'reason', 'visible', 'cid', 1);
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_BanFromServer_ext,
|
||||
expect.objectContaining({ minutes: 30, userName: 'alice' }),
|
||||
expect.any(Object)
|
||||
|
|
@ -87,7 +86,9 @@ describe('forceActivateUser', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_ForceActivateUser', () => {
|
||||
forceActivateUser('alice', 'mod1');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_ForceActivateUser_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.forceActivateUser', () => {
|
||||
|
|
@ -104,7 +105,7 @@ describe('getAdminNotes', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_GetAdminNotes', () => {
|
||||
getAdminNotes('alice');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetAdminNotes_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_GetAdminNotes_ext })
|
||||
|
|
@ -126,7 +127,7 @@ describe('getBanHistory', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_GetBanHistory', () => {
|
||||
getBanHistory('alice');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetBanHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_BanHistory_ext })
|
||||
|
|
@ -148,7 +149,7 @@ describe('getWarnHistory', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_GetWarnHistory', () => {
|
||||
getWarnHistory('alice');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetWarnHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_WarnHistory_ext })
|
||||
|
|
@ -170,7 +171,7 @@ describe('getWarnList', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_GetWarnList', () => {
|
||||
getWarnList('mod1', 'alice', 'US');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GetWarnList_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_WarnList_ext })
|
||||
|
|
@ -192,7 +193,9 @@ describe('grantReplayAccess', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_GrantReplayAccess', () => {
|
||||
grantReplayAccess(10, 'mod1');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_GrantReplayAccess_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.grantReplayAccess', () => {
|
||||
|
|
@ -209,7 +212,9 @@ describe('updateAdminNotes', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_UpdateAdminNotes', () => {
|
||||
updateAdminNotes('alice', 'new notes');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_UpdateAdminNotes_ext, expect.any(Object), expect.any(Object)
|
||||
);
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.updateAdminNotes', () => {
|
||||
|
|
@ -226,7 +231,7 @@ describe('viewLogHistory', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_ViewLogHistory', () => {
|
||||
viewLogHistory({ dateRange: 7 } as any);
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(
|
||||
Command_ViewLogHistory_ext,
|
||||
expect.any(Object),
|
||||
expect.objectContaining({ responseExt: Response_ViewLogHistory_ext })
|
||||
|
|
@ -248,7 +253,7 @@ describe('warnUser', () => {
|
|||
|
||||
it('calls sendModeratorCommand with Command_WarnUser', () => {
|
||||
warnUser('alice', 'bad behavior', 'cid');
|
||||
expect(BackendService.sendModeratorCommand).toHaveBeenCalledWith(Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
expect(webClient.protobuf.sendModeratorCommand).toHaveBeenCalledWith(Command_WarnUser_ext, expect.any(Object), expect.any(Object));
|
||||
});
|
||||
|
||||
it('onSuccess calls ModeratorPersistence.warnUser', () => {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import {
|
||||
Command_UpdateAdminNotes_ext, Command_UpdateAdminNotesSchema,
|
||||
} from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function updateAdminNotes(userName: string, notes: string): void {
|
||||
BackendService.sendModeratorCommand(Command_UpdateAdminNotes_ext, create(Command_UpdateAdminNotesSchema, { userName, notes }), {
|
||||
webClient.protobuf.sendModeratorCommand(Command_UpdateAdminNotes_ext, create(Command_UpdateAdminNotesSchema, { userName, notes }), {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.updateAdminNotes(userName, notes);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_ViewLogHistory_ext, Command_ViewLogHistorySchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
import { Response_ViewLogHistory_ext } from 'generated/proto/response_viewlog_history_pb';
|
||||
import { LogFilters } from 'types';
|
||||
|
||||
export function viewLogHistory(filters: LogFilters): void {
|
||||
BackendService.sendModeratorCommand(Command_ViewLogHistory_ext, create(Command_ViewLogHistorySchema, filters), {
|
||||
webClient.protobuf.sendModeratorCommand(Command_ViewLogHistory_ext, create(Command_ViewLogHistorySchema, filters), {
|
||||
responseExt: Response_ViewLogHistory_ext,
|
||||
onSuccess: (response) => {
|
||||
ModeratorPersistence.viewLogs(response.logMessage);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { create } from '@bufbuild/protobuf';
|
||||
import { BackendService } from '../../services/BackendService';
|
||||
import webClient from '../../WebClient';
|
||||
import { Command_WarnUser_ext, Command_WarnUserSchema } from 'generated/proto/moderator_commands_pb';
|
||||
import { ModeratorPersistence } from '../../persistence';
|
||||
|
||||
export function warnUser(userName: string, reason: string, clientid?: string, removeMessages?: number): void {
|
||||
const cmd = create(Command_WarnUserSchema, { userName, reason, clientid, removeMessages });
|
||||
BackendService.sendModeratorCommand(Command_WarnUser_ext, cmd, {
|
||||
webClient.protobuf.sendModeratorCommand(Command_WarnUser_ext, cmd, {
|
||||
onSuccess: () => {
|
||||
ModeratorPersistence.warnUser(userName);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue