Commit e3b3da40 authored by Steffen van Bergerem's avatar Steffen van Bergerem Committed by Benjamin Neff
Browse files

Fetch comments, likes and reshares separately

Fixes #7165

closes #7167
parent 98b34530
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
## Refactor

## Bug fixes
* Fix fetching comments after fetching likes [#7167](https://github.com/diaspora/diaspora/pull/7167)

## Features

+4 −1
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@

app.collections.Reshares = Backbone.Collection.extend({
  model: app.models.Reshare,
  url : "/reshares"

  initialize: function(models, options) {
    this.url = "/posts/" + options.post.id + "/reshares";
  }
});
// @license-end
+4 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
        self.post.set({participation: true});
        self.trigger("change");
        self.set({"likes_count" : self.get("likes_count") + 1});
        self.likes.trigger("change");
      },
      error: function() {
        app.flashMessages.error(Diaspora.I18n.t("failed_to_like"));
@@ -84,6 +85,7 @@ app.models.Post.Interactions = Backbone.Model.extend({
    this.userLike().destroy({success : function() {
      self.trigger('change');
      self.set({"likes_count" : self.get("likes_count") - 1});
      self.likes.trigger("change");
    }});

    app.instrument("track", "Unlike");
@@ -116,6 +118,8 @@ app.models.Post.Interactions = Backbone.Model.extend({
          app.stream.addNow(reshare);
        }
        interactions.trigger("change");
        interactions.set({"reshares_count": interactions.get("reshares_count") + 1});
        interactions.reshares.trigger("change");
      })
      .fail(function(){
        app.flashMessages.error(Diaspora.I18n.t("reshares.duplicate"));
+5 −7
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ app.views.LikesInfo = app.views.Base.extend({
  tooltipSelector : ".avatar",

  initialize : function() {
    this.model.interactions.bind('change', this.render, this);
    this.model.interactions.likes.on("change", this.render, this);
    this.displayAvatars = false;
  },

@@ -19,18 +19,16 @@ app.views.LikesInfo = app.views.Base.extend({
    return _.extend(this.defaultPresenter(), {
      likes : this.model.interactions.likes.toJSON(),
      likesCount : this.model.interactions.likesCount(),
      displayAvatars : this.model.interactions.get("fetched") && this.displayAvatars
      displayAvatars: this.displayAvatars
    });
  },

  showAvatars : function(evt){
    if(evt) { evt.preventDefault() }
    this.displayAvatars = true;
    if(!this.model.interactions.get("fetched")){
      this.model.interactions.fetch();
    } else {
      this.model.interactions.trigger("change");
    }
    this.model.interactions.likes.fetch({success: function() {
      this.model.interactions.likes.trigger("change");
    }.bind(this)});
  }
});
// @license-end
+5 −7
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ app.views.ResharesInfo = app.views.Base.extend({
  tooltipSelector : ".avatar",

  initialize : function() {
    this.model.interactions.bind("change", this.render, this);
    this.model.interactions.reshares.bind("change", this.render, this);
    this.displayAvatars = false;
  },

@@ -19,18 +19,16 @@ app.views.ResharesInfo = app.views.Base.extend({
    return _.extend(this.defaultPresenter(), {
      reshares : this.model.interactions.reshares.toJSON(),
      resharesCount : this.model.interactions.resharesCount(),
      displayAvatars : this.model.interactions.get("fetched") && this.displayAvatars
      displayAvatars: this.displayAvatars
    });
  },

  showAvatars : function(evt){
    if(evt) { evt.preventDefault() }
    this.displayAvatars = true;
    if(!this.model.interactions.get("fetched")){
      this.model.interactions.fetch();
    } else {
      this.model.interactions.trigger("change");
    }
    this.model.interactions.reshares.fetch({success: function() {
      this.model.interactions.reshares.trigger("change");
    }.bind(this)});
  }
});
// @license-end
Loading