mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: adapt chat Module to strict null checks
This commit is contained in:
parent
9b8a605bf8
commit
11ef58d048
@ -8,14 +8,12 @@
|
||||
|
||||
import { ChannelName } from '@/channel/types';
|
||||
|
||||
export type SubscriberChannelData<
|
||||
C extends ChannelName = null,
|
||||
// K extends keyof SubscriberChannelDict[C] = keyof SubscriberChannelDict[C],
|
||||
> = C extends null
|
||||
? { name: ChannelName }
|
||||
: {
|
||||
name: C;
|
||||
} & {
|
||||
// Channel's specific attributes
|
||||
[P in keyof SubscriberChannelDict[C]]: SubscriberChannelDict[C][P];
|
||||
};
|
||||
export type SubscriberChannelData<C extends ChannelName = 'unknown-channel'> =
|
||||
C extends 'unknown-channel'
|
||||
? { name: ChannelName }
|
||||
: {
|
||||
name: C;
|
||||
} & {
|
||||
// Channel's specific attributes
|
||||
[P in keyof SubscriberChannelDict[C]]: SubscriberChannelDict[C][P];
|
||||
};
|
||||
|
@ -117,6 +117,12 @@ export class ChatService {
|
||||
try {
|
||||
const msg = await this.messageService.create(received);
|
||||
const populatedMsg = await this.messageService.findOneAndPopulate(msg.id);
|
||||
|
||||
if (!populatedMsg) {
|
||||
this.logger.warn('Unable to find populated message.', event);
|
||||
throw new Error(`Unable to find Message by ID ${msg.id} not found`);
|
||||
}
|
||||
|
||||
this.websocketGateway.broadcastMessageReceived(populatedMsg, subscriber);
|
||||
this.eventEmitter.emit('hook:stats:entry', 'incoming', 'Incoming');
|
||||
this.eventEmitter.emit(
|
||||
@ -288,7 +294,7 @@ export class ChatService {
|
||||
@OnEvent('hook:subscriber:postCreate')
|
||||
async onSubscriberCreate({ _id }: SubscriberDocument) {
|
||||
const subscriber = await this.subscriberService.findOne(_id);
|
||||
this.websocketGateway.broadcastSubscriberNew(subscriber);
|
||||
if (subscriber) this.websocketGateway.broadcastSubscriberNew(subscriber);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,6 +305,6 @@ export class ChatService {
|
||||
@OnEvent('hook:subscriber:postUpdate')
|
||||
async onSubscriberUpdate({ _id }: SubscriberDocument) {
|
||||
const subscriber = await this.subscriberService.findOne(_id);
|
||||
this.websocketGateway.broadcastSubscriberUpdate(subscriber);
|
||||
if (subscriber) this.websocketGateway.broadcastSubscriberUpdate(subscriber);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user