Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Migarve55 committed Mar 6, 2019
1 parent 1592c7d commit c3f6c63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app/models/chat-message.model.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export class ChatMessage {

constructor(userName, message) {
constructor(userName, message, millis?) {
this.userName = userName;
this.message = message;
this.timeSent = new Date(millis);
}

$key?: string;
Expand Down
17 changes: 14 additions & 3 deletions src/app/services/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RdfService } from './rdf.service';
import { User } from '../models/user.model';
import { fn } from '@angular/compiler/src/output/output_ast';
import { async } from 'q';
import { Message } from '@angular/compiler/src/i18n/i18n_ast';

@Injectable()
export class ChatService {
Expand All @@ -18,7 +19,7 @@ export class ChatService {
constructor(private rdf : RdfService) {
this.loadUserData();
this.loadFriends();
//this.loadMessages();
this.loadMessages();
}

getUser() {
Expand Down Expand Up @@ -52,9 +53,19 @@ export class ChatService {
const messageFolder = "https://migarve55.solid.community/private/dechat/chat/";
(await this.rdf.getElementsFromContainer(messageFolder)).forEach(async element => {
console.log(element);
const text = this.rdf.getValueFromSchema("text", element.toString());
this.chatMessages.push(new ChatMessage(this.userName, text));
const text = this.rdf.getValueFromSchema("text", element.value);
this.addMessage(new ChatMessage(this.userName, text));
});
//Dummy data
this.addMessage(new ChatMessage("Test", "Test 3", 3000));
this.addMessage(new ChatMessage("Test", "Test 1", 1000));
this.addMessage(new ChatMessage("Test", "Test 4", 4000));
this.addMessage(new ChatMessage("Test", "Test 2", 2000));
}

private addMessage(message : ChatMessage) {
this.chatMessages.push(message);
this.chatMessages = this.chatMessages.sort((m1, m2) => m1.timeSent.getMilliseconds() - m2.timeSent.getMilliseconds());
}

sendMessage(msg: string) {
Expand Down

0 comments on commit c3f6c63

Please sign in to comment.