constructor(private chatService: ChatService) { }
ngOnInit() {
- this.chats = this.chatService.chats
+
}
showNewChat() {
diff --git a/src/app/components/chatmanager/chatmanager.component.html b/src/app/components/chatmanager/chatmanager.component.html
index 039d4a1..2be65b3 100644
--- a/src/app/components/chatmanager/chatmanager.component.html
+++ b/src/app/components/chatmanager/chatmanager.component.html
@@ -1,8 +1,8 @@
-
+
-
+
diff --git a/src/app/components/chatmanager/chatmanager.component.ts b/src/app/components/chatmanager/chatmanager.component.ts
index c92aeee..4d7ebe3 100644
--- a/src/app/components/chatmanager/chatmanager.component.ts
+++ b/src/app/components/chatmanager/chatmanager.component.ts
@@ -15,23 +15,25 @@ export class ChatmanagerComponent implements OnInit {
showChatlist: boolean = true
showChat: boolean = false
showCreateNewChat: boolean = false
- parentSelectedChat: Chat
- chatIds: number[] = []
+ parentSelectedChat: Chat
+ parentChats: Array
constructor(private data: DatasharingService, private chatService: ChatService) { }
ngOnInit() {
- this.data.currentChatIDs.subscribe(chatIDs => {
- this.chatIds = chatIDs
- })
- this.chatService.getChatsByID(this.chatIds)
+ /*this.data.currentChatIDs.subscribe(chatIDs => {
+ this.parentChatIds = chatIDs
+ })*/
+ this.refresh()
}
goBackToChatlist($event) {
this.showChatlist = $event
this.showChat = false
this.showCreateNewChat = false
+
+ this.refresh()
}
showSpecialChat($event) {
@@ -47,4 +49,11 @@ export class ChatmanagerComponent implements OnInit {
this.showCreateNewChat = $event
}
+ refresh() {
+ this.chatService.getAllChatsRaw()
+ .subscribe(response => {
+ this.parentChats = this.chatService.renderAllChats(response.json())
+ })
+ }
+
}
diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts
index dded0b4..01837be 100644
--- a/src/app/services/chat/chat.service.ts
+++ b/src/app/services/chat/chat.service.ts
@@ -29,11 +29,21 @@ export class ChatService {
this.http.post(url, this.getBodyForGetAllChats())
.subscribe(response => {
- this.chats = this.updateAllChats(response.json())
+ this.chats = this.renderAllChats(response.json())
});
return this.chats
}
+ public getAllChatsRaw(): any {
+ console.log("Getting all chats ..")
+ let url = 'https://greenvironment.net/graphql'
+
+ let headers = new Headers()
+ headers.set('Content-Type', 'application/json')
+
+ return this.http.post(url, this.getBodyForGetAllChats())
+ }
+
public getChatsByID(pChatIDs: number[]): Array {
this.chats = []
console.log("Getting chats by ID..")
@@ -52,6 +62,23 @@ export class ChatService {
return this.chats
}
+ public getChatsByIDRaw(pChatIDs: number[]): any {
+ console.log("Getting chats by ID..")
+
+ for(let chatId of pChatIDs) {
+ let url = 'https://greenvironment.net/graphql'
+
+ let headers = new Headers()
+ headers.set('Content-Type', 'application/json')
+
+ this.http.post(url, this.getBodyForGetChatsByID(chatId))
+ .subscribe(response => {
+ this.updateChat(response.json())
+ })
+ }
+ return this.chats
+ }
+
public createNewChat(pUserID: number) {
let url = 'https://greenvironment.net/graphql'
@@ -108,12 +135,21 @@ export class ChatService {
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response =>
{
console.log("Downloading messages ...")
- messages = this.updateMessages(response.json())
+ messages = this.renderMessages(response.json())
})
return messages
}
- updateMessages(pResponse: any): Array {
+ public getMessagesRaw(pChatID): any {
+ let url = 'https://greenvironment.net/graphql'
+
+ let headers = new Headers()
+ headers.set('Content-Type', 'application/json')
+
+ return this.http.post(url, this.getBodyForGetMessagesInChat(pChatID))
+ }
+
+ public renderMessages(pResponse: any): Array {
let messages = new Array()
for(let message of pResponse.data.getChat.messages) {
if(message.author.id == this.ownID) {
@@ -125,7 +161,7 @@ export class ChatService {
return messages
}
- updateAllChats(pResponse: any): Array {
+ public renderAllChats(pResponse: any): Array {
let chats = Array()
for(let chat of pResponse.data.getSelf.chats) {
let memberID: number
@@ -204,9 +240,13 @@ export class ChatService {
getBodyForGetAllChats() {
const body = {query: `query {
- getUser {
- chats(first: 1000, offset: 0) {id, members{name, id},
- messages(first: 1000, offset: 0) {author {id}, createdAt, content}}
+ getSelf {
+ chats(first: 1000, offset: 0) {
+ id, members{name, id},
+ messages(first: 1000, offset: 0) {
+ author {id}, createdAt, content
+ }
+ }
}
}`
}