Merge branch 'niklas_dev2' of Software_Engineering_I/greenvironment-frontend into master

master
Niklas_L 5 years ago committed by Gitea
commit efc09b97fe

@ -4,7 +4,7 @@
<span class='title'>{{childChat.memberName}}</span> <span class='title'>{{childChat.memberName}}</span>
</div> </div>
<div id='messagecontainer'> <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 == true" id='ownmessage'><span>{{message.content}}</span></div>
<div *ngIf="message.myself == false" id='foreignmessage'><span>{{message.content}}</span></div> <div *ngIf="message.myself == false" id='foreignmessage'><span>{{message.content}}</span></div>
</div> </div>

@ -11,17 +11,15 @@ import { Chat } from 'src/app/models/chat';
}) })
export class ChatComponent implements OnInit { export class ChatComponent implements OnInit {
messages:Array<Chatmessage> = [new Chatmessage("Hallo", "01.01.",true), new Chatmessage("Hallo", "01.01.",true), 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)]
@Output() goBackEvent = new EventEmitter<boolean>(); @Output() goBackEvent = new EventEmitter<boolean>();
@Output() refreshEvent = new EventEmitter<boolean>()
@Input() childChat: Chat; @Input() childChat: Chat;
constructor(private chatService: ChatService) { } constructor(private chatService: ChatService) { }
ngOnInit() { ngOnInit() {
this.refresh()
} }
goBack() { goBack() {
@ -30,8 +28,20 @@ export class ChatComponent implements OnInit {
sendMessage(pElement) { sendMessage(pElement) {
this.chatService.sendMessage(this.childChat.id, pElement.value) this.chatService.sendMessage(this.childChat.id, pElement.value)
this.refreshEvent.emit(true) .subscribe(response => {
console.log("Message sent")
pElement.value = "" 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> <chatmanager-chatlist (showChatEvent)="showSpecialChat($event)" (showCreateChatEvent)="showNewChat($event)" [childChats]="parentChats"></chatmanager-chatlist>
</div> </div>
<div *ngIf="showChat"> <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>
<div *ngIf="showCreateNewChat"> <div *ngIf="showCreateNewChat">
<chatmanager-chatcontacts (goBackEvent)="goBackToChatlist($event)"></chatmanager-chatcontacts> <chatmanager-chatcontacts (goBackEvent)="goBackToChatlist($event)"></chatmanager-chatcontacts>

@ -117,13 +117,13 @@ export class ChatService {
return chatPartners return chatPartners
} }
public sendMessage(pChatID: number, pContent: string) { public sendMessage(pChatID: number, pContent: string): any {
let url = 'https://greenvironment.net/graphql' let url = 'https://greenvironment.net/graphql'
let headers = new Headers() let headers = new Headers()
headers.set('Content-Type', 'application/json') 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> { public getMessages(pChatID): Array<Chatmessage> {
@ -266,8 +266,8 @@ export class ChatService {
} }
getBodyForGetMessagesInChat(pChatID: number) { getBodyForGetMessagesInChat(pChatID: number) {
const body = {query: `query($chatID: ID!) { const body = {query: `query($chatId: ID!) {
getChat(chatId: $chatID) { getChat(chatId: $chatId) {
messages(first: 1000, offset: 0) {author {id}, createdAt, content} messages(first: 1000, offset: 0) {author {id}, createdAt, content}
} }
}`, variables: { }`, variables: {

@ -113,7 +113,8 @@ export class FeedService {
let upvotes: number = post.upvotes let upvotes: number = post.upvotes
let downvotes: number = post.downvotes let downvotes: number = post.downvotes
let author = new Author(post.author.id, post.author.name, post.author.handle) 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)) posts.push(new Post(id, content, htmlContent, upvotes, downvotes, date, author))
} }

Loading…
Cancel
Save