Unverified Commit ce5e42c4 authored by Benjamin Neff's avatar Benjamin Neff
Browse files

Merge pull request #7182 from svbergerem/spv-load-initial-interactions

Single post view interaction refactorings
parents 339dd276 04735ce9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ If so, please delete it since it will prevent the federation from working proper
* Use id as fallback when sorting posts [#7523](https://github.com/diaspora/diaspora/pull/7523)
* Remove no-posts-info when adding posts to the stream [#7523](https://github.com/diaspora/diaspora/pull/7523)
* Upgrade to rails 5.1 [#7514](https://github.com/diaspora/diaspora/pull/7514)
* Refactoring single post view interactions [#7182](https://github.com/diaspora/diaspora/pull/7182)

## Bug fixes

+0 −6
Original line number Diff line number Diff line
@@ -48,12 +48,6 @@ app.models.Post = Backbone.Model.extend(_.extend({}, app.models.formatDateMixin,
    var body = this.get("text").trim()
      , newlineIdx = body.indexOf("\n");
    return (newlineIdx > 0 ) ? body.substr(newlineIdx+1, body.length) : "";
  },

  //returns a promise
  preloadOrFetch : function(){
    var action = app.hasPreload("post") ? this.set(app.parsePreload("post")) : this.fetch();
    return $.when(action);
  }
}));
// @license-end
+3 −24
Original line number Diff line number Diff line
@@ -3,10 +3,6 @@
//require ../post

app.models.Post.Interactions = Backbone.Model.extend({
  url : function(){
    return this.post.url() + "/interactions";
  },

  initialize : function(options){
    this.post = options.post;
    this.comments = new app.collections.Comments(this.get("comments"), {post : this.post});
@@ -14,33 +10,16 @@ app.models.Post.Interactions = Backbone.Model.extend({
    this.reshares = new app.collections.Reshares(this.get("reshares"), {post : this.post});
  },

  parse : function(resp){
    this.comments.reset(resp.comments);
    this.likes.reset(resp.likes);
    this.reshares.reset(resp.reshares);

    var comments = this.comments
      , likes = this.likes
      , reshares = this.reshares;

    return {
      comments : comments,
      likes : likes,
      reshares : reshares,
      fetched : true
    };
  },

  likesCount : function(){
    return this.get("fetched") ? this.likes.models.length : this.get("likes_count");
    return this.get("likes_count");
  },

  resharesCount : function(){
    return this.get("fetched") ? this.reshares.models.length : this.get("reshares_count");
    return this.get("reshares_count");
  },

  commentsCount : function(){
    return this.get("fetched") ? this.comments.models.length : this.get("comments_count");
    return this.get("comments_count");
  },

  userLike : function(){
+2 −3
Original line number Diff line number Diff line
@@ -9,9 +9,8 @@ app.pages.SinglePostViewer = app.views.Base.extend({
  },

  initialize : function() {
    this.model = new app.models.Post({ id : gon.post.id });
    this.model.preloadOrFetch().done(_.bind(this.initViews, this));
    this.model.interactions.fetch(); //async, yo, might want to throttle this later.
    this.model = new app.models.Post(gon.post);
    this.initViews();
  },

  initViews : function() {
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ app.Router = Backbone.Router.extend({
  },

  singlePost: function(id) {
    this.renderPage(function() { return new app.pages.SinglePostViewer({id: id}); });
    this.renderPage(function() { return new app.pages.SinglePostViewer({id: id, el: $("#container")}); });
  },

  spotlight: function() {
Loading