Skip to content

Commit

Permalink
Step 6.14: Implement sendTextMessage method
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent 3f0c071 commit 96695bb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/pages/messages/messages.ts
@@ -1,8 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { NavParams } from 'ionic-angular';
import { Chat, Message } from 'api/models';
import { Chat, Message, MessageType } from 'api/models';
import { Observable } from 'rxjs';
import { Messages } from 'api/collections';
import { MeteorObservable } from 'meteor-rxjs';

@Component({
selector: 'messages-page',
Expand All @@ -13,6 +14,7 @@ export class MessagesPage implements OnInit {
title: string;
picture: string;
messages: Observable<Message[]>;
message: string = '';

constructor(navParams: NavParams) {
this.selectedChat = <Chat>navParams.get('chat');
Expand All @@ -35,4 +37,25 @@ export class MessagesPage implements OnInit {
return messages;
});
}

onInputKeypress({ keyCode }: KeyboardEvent): void {
if (keyCode === 13) {
this.sendTextMessage();
}
}

sendTextMessage(): void {
// If message was yet to be typed, abort
if (!this.message) {
return;
}

MeteorObservable.call('addMessage', MessageType.TEXT,
this.selectedChat._id,
this.message
).zone().subscribe(() => {
// Zero the input field
this.message = '';
});
}
}

0 comments on commit 96695bb

Please sign in to comment.