move feed service from match component

This commit is contained in:
chsakell
2016-10-04 14:57:37 +03:00
parent fb6127d281
commit fdcae26d63
6 changed files with 34 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ChatMessage, Match } from '../interfaces';
import { FeedService } from '../services/feed.service';
@@ -11,32 +11,43 @@ import { DataService } from '../services/data.service';
export class MatchComponent implements OnInit {
@Input() match: Match;
@Output() updateSubscription = new EventEmitter();
subscribed: boolean;
chatMessage: string = '';
constructor(private feedService: FeedService,
private dataService: DataService) { }
constructor(private dataService: DataService) { }
ngOnInit() { }
ngOnInit() { }
subscribe() {
console.log(this.match.Id);
this.subscribed = true;
this.feedService.subscribeToFeed(this.match.Id);
//this.feedService.subscribeToFeed(this.match.Id);
}
unsubscribe() {
this.subscribed = false;
this.feedService.unsubscribeToFeed(this.match.Id);
//this.feedService.unsubscribeToFeed(this.match.Id);
}
setSubscription(val: boolean) {
this.subscribed = val;
let subscription =
{
subscribe: val,
matchId: this.match.Id
}
this.updateSubscription.emit(subscription);
}
addChatMessage() {
let self = this;
let messageToSend: ChatMessage = {
MatchId : self.match.Id,
Text : self.chatMessage,
CreatedAt : new Date(Date.now())
};
let messageToSend: ChatMessage = {
MatchId: self.match.Id,
Text: self.chatMessage,
CreatedAt: new Date(Date.now())
};
this.dataService.addChatMessage(messageToSend)
.subscribe(() => {