Permalink
Browse files

Step 6.14: Implement sendTextMessage method

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 7180e2c commit 561b9798bb79b3bb38e348d6024b6e312d82c124
Showing with 24 additions and 1 deletion.
  1. +24 −1 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',
@@ -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');
@@ -35,4 +37,25 @@ export class MessagesPage implements OnInit {
return messages;
});
}
onInputKeypress({ keyCode }: KeyboardEvent): void {
if (keyCode.charCode === 13) {

This comment has been minimized.

Show comment
Hide comment
@netto89

netto89 Oct 19, 2017

keyCode is deprecated.
Use { key } instead and if (key === 'Enter') {

@netto89

netto89 Oct 19, 2017

keyCode is deprecated.
Use { key } instead and if (key === 'Enter') {

This comment has been minimized.

Show comment
Hide comment
@Urigo

Urigo Nov 1, 2017

Owner

@netto89 could you open this as a new issue? thank you!

@Urigo

Urigo Nov 1, 2017

Owner

@netto89 could you open this as a new issue? thank you!

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 561b979

Please sign in to comment.