|
|
@ -30,11 +30,21 @@ export class ChatService {
|
|
|
|
|
|
|
|
|
|
|
|
this.http.post(url, this.getBodyForGetAllChats())
|
|
|
|
this.http.post(url, this.getBodyForGetAllChats())
|
|
|
|
.subscribe(response => {
|
|
|
|
.subscribe(response => {
|
|
|
|
this.chats = this.updateAllChats(response.json())
|
|
|
|
this.chats = this.renderAllChats(response.json())
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return this.chats
|
|
|
|
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> {
|
|
|
|
public getChatsByID(pChatIDs: number[]): Array<Chat> {
|
|
|
|
this.chats = []
|
|
|
|
this.chats = []
|
|
|
|
console.log("Getting chats by ID..")
|
|
|
|
console.log("Getting chats by ID..")
|
|
|
@ -53,6 +63,23 @@ export class ChatService {
|
|
|
|
return this.chats
|
|
|
|
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) {
|
|
|
|
public createNewChat(pUserID: number) {
|
|
|
|
let url = 'https://greenvironment.net/graphql'
|
|
|
|
let url = 'https://greenvironment.net/graphql'
|
|
|
|
|
|
|
|
|
|
|
@ -109,12 +136,21 @@ export class ChatService {
|
|
|
|
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response =>
|
|
|
|
this.http.post(url, this.getBodyForGetMessagesInChat(pChatID)).subscribe(response =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
console.log("Downloading messages ...")
|
|
|
|
console.log("Downloading messages ...")
|
|
|
|
messages = this.updateMessages(response.json())
|
|
|
|
messages = this.renderMessages(response.json())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return messages
|
|
|
|
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>()
|
|
|
|
let messages = new Array<Chatmessage>()
|
|
|
|
for(let message of pResponse.data.getChat.messages) {
|
|
|
|
for(let message of pResponse.data.getChat.messages) {
|
|
|
|
if(message.author.id == this.ownID) {
|
|
|
|
if(message.author.id == this.ownID) {
|
|
|
@ -126,7 +162,7 @@ export class ChatService {
|
|
|
|
return messages
|
|
|
|
return messages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateAllChats(pResponse: any): Array<Chat> {
|
|
|
|
public renderAllChats(pResponse: any): Array<Chat> {
|
|
|
|
let chats = Array<Chat>()
|
|
|
|
let chats = Array<Chat>()
|
|
|
|
for(let chat of pResponse.data.getSelf.chats) {
|
|
|
|
for(let chat of pResponse.data.getSelf.chats) {
|
|
|
|
let memberID: number
|
|
|
|
let memberID: number
|
|
|
@ -205,9 +241,13 @@ export class ChatService {
|
|
|
|
|
|
|
|
|
|
|
|
getBodyForGetAllChats() {
|
|
|
|
getBodyForGetAllChats() {
|
|
|
|
const body = {query: `query {
|
|
|
|
const body = {query: `query {
|
|
|
|
getUser {
|
|
|
|
getSelf {
|
|
|
|
chats(first: 1000, offset: 0) {id, members{name, id},
|
|
|
|
chats(first: 1000, offset: 0) {
|
|
|
|
messages(first: 1000, offset: 0) {author {id}, createdAt, content}}
|
|
|
|
id, members{name, id},
|
|
|
|
|
|
|
|
messages(first: 1000, offset: 0) {
|
|
|
|
|
|
|
|
author {id}, createdAt, content
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
}`
|
|
|
|
}
|
|
|
|
}
|
|
|
|