mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-04-03 11:52:40 +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;
|
originator?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MessageMetadata {
|
export interface MessageData {
|
||||||
originator?: string;
|
originator?: string;
|
||||||
timestamp?: Date;
|
timestamp?: Date;
|
||||||
typing?: boolean;
|
typing?: boolean;
|
||||||
}
|
|
||||||
|
|
||||||
export interface MessageData extends MessageMetadata {
|
|
||||||
message: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ChangeDetectorRef, Component, OnInit, EventEmitter, Output } from '@angular/core';
|
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 { MarkdownService } from '../services/markdown.service';
|
||||||
import { WebSocketService } from '../services/websocket.service';
|
import { WebSocketService } from '../services/websocket.service';
|
||||||
|
|
||||||
@ -16,7 +16,6 @@ export class MessagesComponent implements OnInit {
|
|||||||
newMessage: Subject<MessageData> = new Subject<MessageData>();
|
newMessage: Subject<MessageData> = new Subject<MessageData>();
|
||||||
showTypingIndicator = false;
|
showTypingIndicator = false;
|
||||||
|
|
||||||
originator = 'avataobot';
|
|
||||||
messages: MessageData[] = [];
|
messages: MessageData[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -28,7 +27,6 @@ export class MessagesComponent implements OnInit {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.newMessage.subscribe(
|
this.newMessage.subscribe(
|
||||||
message => {
|
message => {
|
||||||
this.showTypingIndicator = true;
|
|
||||||
this.writeMessage(message);
|
this.writeMessage(message);
|
||||||
this.newMessageEvent.emit();
|
this.newMessageEvent.emit();
|
||||||
});
|
});
|
||||||
@ -37,9 +35,6 @@ export class MessagesComponent implements OnInit {
|
|||||||
this.websocketService.observeKey<Message>('message.send').subscribe(
|
this.websocketService.observeKey<Message>('message.send').subscribe(
|
||||||
message => this.newMessage.next(message)
|
message => this.newMessage.next(message)
|
||||||
);
|
);
|
||||||
this.websocketService.observeKey<MessageConfig>('message.config').subscribe(
|
|
||||||
message => this.configureMessages(message)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
writeMessage(message: MessageData) {
|
writeMessage(message: MessageData) {
|
||||||
@ -50,21 +45,12 @@ export class MessagesComponent implements OnInit {
|
|||||||
|
|
||||||
transformMessage(message: MessageData) {
|
transformMessage(message: MessageData) {
|
||||||
message.message = this.convertMarkdownToHTML(message.message);
|
message.message = this.convertMarkdownToHTML(message.message);
|
||||||
if (!message.originator) {
|
|
||||||
message.originator = this.originator;
|
|
||||||
}
|
|
||||||
if (!message.timestamp) {
|
if (!message.timestamp) {
|
||||||
message.timestamp = new Date();
|
message.timestamp = new Date();
|
||||||
}
|
}
|
||||||
this.showTypingIndicator = message.typing;
|
this.showTypingIndicator = message.typing;
|
||||||
}
|
}
|
||||||
|
|
||||||
configureMessages(message: MessageConfig) {
|
|
||||||
if (message.originator) {
|
|
||||||
this.originator = message.originator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
convertMarkdownToHTML(text: string) {
|
convertMarkdownToHTML(text: string) {
|
||||||
return this.markdownService.convertToHtml(text);
|
return this.markdownService.convertToHtml(text);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user