Another try

master
lampe_n1 5 years ago
parent 1c27f6d064
commit 0467efe682

@ -4,7 +4,7 @@
<span class='title'>{{childChat.memberName}}</span>
</div>
<div id='messagecontainer'>
<div class="chatmessage" *ngFor="let message of childChat.messages">
<div class="chatmessage" *ngFor="let message of messages">
<div *ngIf="message.myself == true" id='ownmessage'><span>{{message.content}}</span></div>
<div *ngIf="message.myself == false" id='foreignmessage'><span>{{message.content}}</span></div>
</div>

@ -11,17 +11,15 @@ import { Chat } from 'src/app/models/chat';
})
export class ChatComponent implements OnInit {
messages:Array<Chatmessage> = [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<Chatmessage>
@Output() goBackEvent = new EventEmitter<boolean>();
@Output() refreshEvent = new EventEmitter<boolean>()
@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())
})
}
}

@ -2,7 +2,7 @@
<chatmanager-chatlist (showChatEvent)="showSpecialChat($event)" (showCreateChatEvent)="showNewChat($event)" [childChats]="parentChats"></chatmanager-chatlist>
</div>
<div *ngIf="showChat">
<chatmanager-chat (goBackEvent)="goBackToChatlist($event)" (refreshEvent)="refresh()" [childChat]="parentSelectedChat"></chatmanager-chat>
<chatmanager-chat (goBackEvent)="goBackToChatlist($event)" [childChat]="parentSelectedChat"></chatmanager-chat>
</div>
<div *ngIf="showCreateNewChat">
<chatmanager-chatcontacts (goBackEvent)="goBackToChatlist($event)"></chatmanager-chatcontacts>

@ -116,13 +116,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<Chatmessage> {
@ -265,8 +265,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: {

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

Loading…
Cancel
Save