Post.js

From disqus.com, 7 Months ago, written in JavaScript, viewed 3 times. This paste is a reply to UserProfile.js from disqus.com - view diff
URL https://pastebin.freepbx.org/view/a83bb067 Embed
Download Paste or View Raw
  1. define('home/models/Post',[
  2.     'jquery',
  3.     'underscore',
  4.  
  5.     'core/models/Post',
  6.  
  7.     'core/UniqueModel',
  8.     'home/models/Thread',
  9.     'home/models/User',
  10.     'home/collections/VotersUserCollection',
  11. ], function (
  12.     $,
  13.     _,
  14.  
  15.     CorePost,
  16.  
  17.     UniqueModel,
  18.     Thread,
  19.     User,
  20.     VotersUserCollection
  21. ) {
  22.     'use strict';
  23.  
  24.     var parent = CorePost;
  25.     var parentProto = parent.prototype;
  26.  
  27.  
  28.     var Post = CorePost.extend({
  29.  
  30.         // TODO: unify Home's VotersUserCollection with embed's
  31.         votersCollectionClass: VotersUserCollection,
  32.  
  33.         initialize: function (attrs, options) {
  34.             parentProto.initialize.call(this, attrs, options);
  35.  
  36.             this.set({ state: this._getPostState() });
  37.             this.initializeRelated(
  38.                 'thread',
  39.                 _.extend({ forum: attrs.forum }, options),
  40.                 Thread
  41.             );
  42.  
  43.             // this.author is set via the Post.withAuthor mixin from next-core
  44.         },
  45.  
  46.         toJSON: function () {
  47.             var stringifiable = parentProto.toJSON.apply(this, arguments);
  48.             stringifiable.thread = this.thread.toJSON();
  49.             return stringifiable;
  50.         },
  51.  
  52.         getLinks: _.memoize(function () {
  53.             var $wrapper = $('<div>').html(this.get('message'));
  54.             return $wrapper.find('a[href]').map(function (__, el) {
  55.                 return $(el).attr('href');
  56.             });
  57.         }, function () {
  58.             return this.id;
  59.         }),
  60.  
  61.         getThreadId: function () {
  62.             return this.thread.id;
  63.         },
  64.  
  65.         _getPostState: function () {
  66.             if (this.get('isSpam'))
  67.                 return 'spam';
  68.  
  69.             if (this.get('isDeleted'))
  70.                 return 'deleted';
  71.  
  72.             // Once a post is flagged to over the site flag threshold it is unapproved
  73.             // Flagged + approved means it's still visible
  74.             if (this.get('isFlagged') && !this.get('isApproved'))
  75.                 return 'flagged';
  76.  
  77.             if (!this.get('isApproved'))
  78.                 return 'pending';
  79.  
  80.             return 'visible';
  81.         },
  82.     });
  83.  
  84.     CorePost.withAuthor.call(Post.prototype, UniqueModel.boundModel(User));
  85.  
  86.     // TODO - apply Post.withMediaCollection mixin
  87.  
  88.     UniqueModel.addType('Post', Post);
  89.  
  90.     return Post;
  91. });
  92.  
  93. // https://c.disquscdn.com/next/82c6de3/home/js/models/Post.js

Reply to "Post.js"

Here you can reply to the paste above