|
|
|
@ -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<Chat> {
|
|
|
|
|
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<Chatmessage> {
|
|
|
|
|
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<Chatmessage> {
|
|
|
|
|
let messages = new Array<Chatmessage>()
|
|
|
|
|
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<Chat> {
|
|
|
|
|
public renderAllChats(pResponse: any): Array<Chat> {
|
|
|
|
|
let chats = Array<Chat>()
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}`
|
|
|
|
|
}
|
|
|
|
|