mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: channels data type inference
This commit is contained in:
@@ -12,6 +12,11 @@ import CONSOLE_CHANNEL_SETTINGS, {
|
||||
|
||||
declare global {
|
||||
interface Settings extends SettingTree<typeof CONSOLE_CHANNEL_SETTINGS> {}
|
||||
interface SubscriberChannelDict {
|
||||
[CONSOLE_CHANNEL_NAME]: {
|
||||
name: typeof CONSOLE_CHANNEL_NAME;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare module '@nestjs/event-emitter' {
|
||||
|
||||
@@ -59,7 +59,7 @@ import { SocketRequest } from '@/websocket/utils/socket-request';
|
||||
import { SocketResponse } from '@/websocket/utils/socket-response';
|
||||
import { WebsocketGateway } from '@/websocket/websocket.gateway';
|
||||
|
||||
import { WEB_CHANNEL_NAMESPACE } from './settings';
|
||||
import { WEB_CHANNEL_NAME, WEB_CHANNEL_NAMESPACE } from './settings';
|
||||
import { Web } from './types';
|
||||
import WebEventWrapper from './wrapper';
|
||||
|
||||
@@ -1185,7 +1185,9 @@ export default abstract class BaseWebChannelHandler<
|
||||
type: StdEventType,
|
||||
content: any,
|
||||
): void {
|
||||
if (subscriber.channel.isSocket) {
|
||||
const channelData =
|
||||
Subscriber.getChannelData<typeof WEB_CHANNEL_NAME>(subscriber);
|
||||
if (channelData.isSocket) {
|
||||
this.websocketGateway.broadcast(subscriber, type, content);
|
||||
} else {
|
||||
// Do nothing, messages will be retrieved via polling
|
||||
@@ -1278,6 +1280,17 @@ export default abstract class BaseWebChannelHandler<
|
||||
* @returns The web's response, otherwise an error
|
||||
*/
|
||||
async getUserData(event: WebEventWrapper): Promise<SubscriberCreateDto> {
|
||||
return event.getSender() as SubscriberCreateDto;
|
||||
const sender = event.getSender();
|
||||
const {
|
||||
id: _id,
|
||||
createdAt: _createdAt,
|
||||
updatedAt: _updatedAt,
|
||||
...rest
|
||||
} = sender;
|
||||
const subscriber: SubscriberCreateDto = {
|
||||
...rest,
|
||||
channel: Subscriber.getChannelData(sender),
|
||||
};
|
||||
return subscriber;
|
||||
}
|
||||
}
|
||||
|
||||
10
api/src/extensions/channels/web/index.d.ts
vendored
10
api/src/extensions/channels/web/index.d.ts
vendored
@@ -7,11 +7,21 @@
|
||||
*/
|
||||
|
||||
import DEFAULT_WEB_CHANNEL_SETTINGS, {
|
||||
WEB_CHANNEL_NAME,
|
||||
WEB_CHANNEL_NAMESPACE,
|
||||
} from './settings';
|
||||
|
||||
declare global {
|
||||
interface Settings extends SettingTree<typeof DEFAULT_WEB_CHANNEL_SETTINGS> {}
|
||||
|
||||
interface SubscriberChannelDict {
|
||||
[WEB_CHANNEL_NAME]: {
|
||||
name: typeof WEB_CHANNEL_NAME;
|
||||
isSocket: boolean;
|
||||
ipAddress: string;
|
||||
agent: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
declare module '@nestjs/event-emitter' {
|
||||
|
||||
Reference in New Issue
Block a user