mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2024-12-05 02:11:32 +00:00
Remove originator configuration and merge MessageData with MessageMetadata
This commit is contained in:
parent
f90907607d
commit
45767b6711
@ -4,13 +4,10 @@ export interface MessageConfig extends WebSocketMessage {
|
||||
originator?: string;
|
||||
}
|
||||
|
||||
export interface MessageMetadata {
|
||||
export interface MessageData {
|
||||
originator?: string;
|
||||
timestamp?: Date;
|
||||
typing?: boolean;
|
||||
}
|
||||
|
||||
export interface MessageData extends MessageMetadata {
|
||||
message: string;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ChangeDetectorRef, Component, OnInit, EventEmitter, Output } from '@angular/core';
|
||||
import { MessageConfig, MessageData, Message } from '../message-types/bot-messages';
|
||||
import { MessageData, Message } from '../message-types/bot-messages';
|
||||
import { MarkdownService } from '../services/markdown.service';
|
||||
import { WebSocketService } from '../services/websocket.service';
|
||||
|
||||
@ -16,7 +16,6 @@ export class MessagesComponent implements OnInit {
|
||||
newMessage: Subject<MessageData> = new Subject<MessageData>();
|
||||
showTypingIndicator = false;
|
||||
|
||||
originator = 'avataobot';
|
||||
messages: MessageData[] = [];
|
||||
|
||||
constructor(
|
||||
@ -28,7 +27,6 @@ export class MessagesComponent implements OnInit {
|
||||
ngOnInit() {
|
||||
this.newMessage.subscribe(
|
||||
message => {
|
||||
this.showTypingIndicator = true;
|
||||
this.writeMessage(message);
|
||||
this.newMessageEvent.emit();
|
||||
});
|
||||
@ -37,9 +35,6 @@ export class MessagesComponent implements OnInit {
|
||||
this.websocketService.observeKey<Message>('message.send').subscribe(
|
||||
message => this.newMessage.next(message)
|
||||
);
|
||||
this.websocketService.observeKey<MessageConfig>('message.config').subscribe(
|
||||
message => this.configureMessages(message)
|
||||
);
|
||||
}
|
||||
|
||||
writeMessage(message: MessageData) {
|
||||
@ -50,21 +45,12 @@ export class MessagesComponent implements OnInit {
|
||||
|
||||
transformMessage(message: MessageData) {
|
||||
message.message = this.convertMarkdownToHTML(message.message);
|
||||
if (!message.originator) {
|
||||
message.originator = this.originator;
|
||||
}
|
||||
if (!message.timestamp) {
|
||||
message.timestamp = new Date();
|
||||
}
|
||||
this.showTypingIndicator = message.typing;
|
||||
}
|
||||
|
||||
configureMessages(message: MessageConfig) {
|
||||
if (message.originator) {
|
||||
this.originator = message.originator;
|
||||
}
|
||||
}
|
||||
|
||||
convertMarkdownToHTML(text: string) {
|
||||
return this.markdownService.convertToHtml(text);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user