diff --git a/src/app/components/chat/chat.component.html b/src/app/components/chat/chat.component.html
index b29ddc6..a30d068 100644
--- a/src/app/components/chat/chat.component.html
+++ b/src/app/components/chat/chat.component.html
@@ -4,7 +4,7 @@
{{childChat.memberName}}
-
+
{{message.content}}
{{message.content}}
diff --git a/src/app/components/chat/chat.component.ts b/src/app/components/chat/chat.component.ts
index 524dc30..2cc80d4 100644
--- a/src/app/components/chat/chat.component.ts
+++ b/src/app/components/chat/chat.component.ts
@@ -11,17 +11,15 @@ import { Chat } from 'src/app/models/chat';
})
export class ChatComponent implements OnInit {
- messages:Array
= [new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true),
- new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true),
- new Chatmessage("Hallo", "01.01.",true)]
+ messages:Array
@Output() goBackEvent = new EventEmitter();
- @Output() refreshEvent = new EventEmitter()
@Input() childChat: Chat;
constructor(private chatService: ChatService) { }
ngOnInit() {
+ this.refresh()
}
goBack() {
@@ -30,8 +28,20 @@ export class ChatComponent implements OnInit {
sendMessage(pElement) {
this.chatService.sendMessage(this.childChat.id, pElement.value)
- this.refreshEvent.emit(true)
- pElement.value = ""
+ .subscribe(response => {
+ console.log("Message sent")
+ pElement.value = ""
+ this.refresh()
+ })
+ }
+
+ refresh() {
+ this.chatService.getMessagesRaw(this.childChat.id)
+ .subscribe(response =>
+ {
+ console.log("Downloading messages ...")
+ this.messages = this.chatService.renderMessages(response.json())
+ })
}
}
diff --git a/src/app/components/chatmanager/chatmanager.component.html b/src/app/components/chatmanager/chatmanager.component.html
index 2be65b3..2d57601 100644
--- a/src/app/components/chatmanager/chatmanager.component.html
+++ b/src/app/components/chatmanager/chatmanager.component.html
@@ -2,7 +2,7 @@
-
+
diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts
index e96543b..d740d32 100644
--- a/src/app/services/chat/chat.service.ts
+++ b/src/app/services/chat/chat.service.ts
@@ -117,13 +117,13 @@ export class ChatService {
return chatPartners
}
- public sendMessage(pChatID: number, pContent: string) {
+ public sendMessage(pChatID: number, pContent: string): any {
let url = 'https://greenvironment.net/graphql'
let headers = new Headers()
headers.set('Content-Type', 'application/json')
- this.http.post(url, this.getBodyForSendMessage(pChatID, pContent)).subscribe(response => console.log("Message sent"))
+ return this.http.post(url, this.getBodyForSendMessage(pChatID, pContent))
}
public getMessages(pChatID): Array {
@@ -266,8 +266,8 @@ export class ChatService {
}
getBodyForGetMessagesInChat(pChatID: number) {
- const body = {query: `query($chatID: ID!) {
- getChat(chatId: $chatID) {
+ const body = {query: `query($chatId: ID!) {
+ getChat(chatId: $chatId) {
messages(first: 1000, offset: 0) {author {id}, createdAt, content}
}
}`, variables: {
diff --git a/src/app/services/feed/feed.service.ts b/src/app/services/feed/feed.service.ts
index 8c8287f..efc3c73 100644
--- a/src/app/services/feed/feed.service.ts
+++ b/src/app/services/feed/feed.service.ts
@@ -113,7 +113,8 @@ export class FeedService {
let upvotes: number = post.upvotes
let downvotes: number = post.downvotes
let author = new Author(post.author.id, post.author.name, post.author.handle)
- let date = new Date(post.createdAt).toDateString()
+ let temp = new Date(Number(post.createdAt))
+ let date = temp.toDateString()
posts.push(new Post(id, content, htmlContent, upvotes, downvotes, date, author))
}