Skip to content

Commit

Permalink
Add a message formatter function before tranferring the message to th…
Browse files Browse the repository at this point in the history
…e panel
  • Loading branch information
brichet committed Feb 29, 2024
1 parent 5f6a82f commit 6583d30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/chat-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,26 @@ export class ChatHandler implements IDisposable {
}
}

/**
* A function called before transferring the message to the panel(s).
* Can be useful if some actions are required on the message.
*/
protected formatChatMessage(
message: ChatService.IChatMessage
): ChatService.IChatMessage {
return message;
}

private _onMessage(message: ChatService.IMessage): void {
// resolve promise from `sendMessage()`
if (message.type === 'msg' && message.sender.id === this.id) {
this._sendResolverQueue.shift()?.(message.id);
}

if (message.type === 'msg') {
message = this.formatChatMessage(message as ChatService.IChatMessage);
}

// call listeners in serial
this._listeners.forEach(listener => listener(message));
}
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './chat-handler';
export * from './services';
export * from './widgets/chat-error';
export * from './widgets/chat-sidebar';

0 comments on commit 6583d30

Please sign in to comment.