Skip to content

Commit

Permalink
Step 8.1: Add send picture logic
Browse files Browse the repository at this point in the history
  • Loading branch information
DAB0mB authored and Dotan Simha committed Nov 23, 2016
1 parent 5dcac98 commit 4e514e2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion client/scripts/controllers/chat.controller.js
@@ -1,6 +1,7 @@
import Ionic from 'ionic-scripts';
import { _ } from 'meteor/underscore';
import { Meteor } from 'meteor/meteor';
import { MeteorCameraUI } from 'meteor/okland:camera-ui';
import { Controller } from 'angular-ecmascript/module-helpers';
import { Chats, Messages } from '../../../lib/collections';

Expand All @@ -24,6 +25,18 @@ export default class ChatCtrl extends Controller {
this.autoScroll();
}

sendPicture() {
MeteorCameraUI.getPicture({}, (err, data) => {
if (err) return this.handleError(err);

this.callMethod('newMessage', {
picture: data,
type: 'picture',
chatId: this.chatId
});
});
}

sendMessage() {
if (_.isEmpty(this.message)) return;

Expand Down Expand Up @@ -74,7 +87,18 @@ export default class ChatCtrl extends Controller {
this.$ionicScrollDelegate.$getByHandle('chatScroll').scrollBottom(animate);
}, 300);
}

handleError(err) {
if (err.error == 'cancel') return;
this.$log.error('Profile save error ', err);

this.$ionicPopup.alert({
title: err.reason || 'Save failed',
template: 'Please try again',
okType: 'button-positive button-clear'
});
}
}

ChatCtrl.$name = 'ChatCtrl';
ChatCtrl.$inject = ['$stateParams', '$timeout', '$ionicScrollDelegate'];
ChatCtrl.$inject = ['$stateParams', '$timeout', '$ionicScrollDelegate', '$ionicPopup', '$log'];

0 comments on commit 4e514e2

Please sign in to comment.