Remove originator configuration and merge MessageData with MessageMetadata

This commit is contained in:
R. Richard 2019-08-26 13:32:15 +02:00 committed by therealkrispet
parent f90907607d
commit 45767b6711
2 changed files with 2 additions and 19 deletions

View File

@ -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;
}

View File

@ -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);
}