framework/ember/app/models/discussion.js
Toby Zerner 5e288f55f5 Change the way post count metadata is stored
We care about the number of “comment” posts, not the number of posts in
total.
2015-01-16 17:26:17 +10:30

46 lines
1.1 KiB
JavaScript

import Ember from 'ember';
import DS from 'ember-data';
var Discussion = DS.Model.extend({
title: DS.attr('string'),
slug: function() {
return this.get('title').toLowerCase().replace(/[^a-z0-9]/gi, '-').replace(/-+/g, '-');
}.property('title'),
canReply: DS.attr('boolean'),
canEdit: DS.attr('boolean'),
canDelete: DS.attr('boolean'),
startTime: DS.attr('date'),
startUser: DS.belongsTo('user'),
startPost: DS.belongsTo('post'),
lastTime: DS.attr('date'),
lastUser: DS.belongsTo('user'),
lastPost: DS.belongsTo('post'),
lastPostNumber: DS.attr('number'),
relevantPosts: DS.hasMany('post'),
commentsCount: DS.attr('number'),
repliesCount: function() {
return Math.max(0, this.get('commentsCount') - 1);
}.property('commentsCount'),
posts: DS.attr('string'),
postIds: function() {
return this.get('posts').split(',');
}.property('posts'),
readTime: DS.attr('date'),
readNumber: DS.attr('number'),
unreadCount: function() {
return this.get('lastPostNumber') - this.get('readNumber');
}.property('lastPostNumber', 'readNumber'),
isUnread: Ember.computed.bool('unreadCount')
});
export default Discussion;