ui/src/app/services/chat.service.ts

57 lines
1.3 KiB
TypeScript

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Channel } from '../models/channel';
import { Message } from '../models/message';
@Injectable({
providedIn: 'root'
})
export class ChatService {
constructor() { }
// TODO: implement
public ListChannels(): Observable<Channel[]> {
return new Observable<Channel[]>(subscriber => {
subscriber.next([
{
id: 0,
name: 'default',
description: 'this is the default channel'
},
{
id: 1,
name: 'gaming',
description: 'this is another channel'
},
]);
subscriber.complete();
});
}
// TODO: implement
// TODO: refactor this so it first returns the n last messages,
// then listens for incoming messages and forwards them as they come
public GetMessages(channelID: number): Observable<Message[]> {
return new Observable<Message[]>(subscriber => {
subscriber.next([
{
id: 1,
sender: 'Test User 1',
channel: 1,
time: new Date(),
content: 'this is my first message'
},
{
id: 2,
sender: 'Test User 2',
channel: 2,
time: new Date(),
content: 'this is my second message'
}
]);
subscriber.complete();
});
}
}