{"size": 1246, "ext": "js", "max_stars_repo_path": "app/imports/ui/pages/messages/messages-page.js", "max_stars_repo_name": "UHvibe/UHvibe", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/imports/ui/pages/messages/messages-page.js", "max_issues_repo_name": "UHvibe/UHvibe", "max_issues_repo_issues_event_min_datetime": "2017-11-17T04:13:07.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-13T22:48:40.000Z", "max_forks_repo_path": "app/imports/ui/pages/messages/messages-page.js", "max_forks_repo_name": "UHvibe/UHvibe", "max_forks_repo_forks_event_min_datetime": "2017-12-01T04:50:24.000Z", "max_forks_repo_forks_event_max_datetime": "2017-12-01T04:56:13.000Z"}
{"max_stars_count": null, "max_issues_count": 51, "max_forks_count": 2, "avg_line_length": 28.3181818182, "max_line_length": 77, "alphanum_fraction": 0.6540930979}
import { Meteor } from 'meteor/meteor';
import { ReactiveDict } from 'meteor/reactive-dict';
import { Template } from 'meteor/templating';
import { Message } from '../../../api/message/MessageCollection.js';

Template.Message_Page.onCreated(function () {
  this.subscribe(Message.getPublicationName());
  this.receivedMessage = new ReactiveDict();
  this.receivedMessage.set('showReceivedMessages', true);
});

Template.Message_Page.helpers({
  receivedMessageList() {
    const id = Meteor.user().profile.name;
    return Message.find({
      $and: [
        { destination: id },
        { isDraft: false },
      ],
    });
  },
  sentMessageList() {
    const id = Meteor.user().profile.name;
    return Message.find({ username: id });
  },
  routeUserName() {
    return Meteor.user().profile.name;
  },
  showReceivedMessages() {
    return Template.instance().receivedMessage.get('showReceivedMessages');
  },
});

Template.Message_Page.events({
  'change select'(event) {
    if ($(event.target).val() === 'receive') {
      Template.instance().receivedMessage.set('showReceivedMessages', true);
    }
    if ($(event.target).val() === 'sent') {
      Template.instance().receivedMessage.set('showReceivedMessages', false);
    }
  },
});
