-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8203 from tclaus/2999-likes-comment
Re-introduce likes on comments
- Loading branch information
Showing
64 changed files
with
908 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later | ||
|
||
app.models.Comment = Backbone.Model.extend({ | ||
urlRoot: "/comments" | ||
urlRoot: "/comments", | ||
|
||
initialize: function(model, options) { | ||
options = options || {}; | ||
this.post = model.post || options.post || this.collection.post; | ||
this.interactions = new app.models.LikeInteractions( | ||
_.extend({comment: this, post: this.post}, this.get("interactions")) | ||
); | ||
this.likes = this.interactions.likes; | ||
this.likesCount = this.attributes.likes_count; | ||
this.userLike = this.interactions.userLike(); | ||
} | ||
}); | ||
// @license-end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// This class contains code extracted from interactions.js to factorize likes management between posts and comments | ||
|
||
app.models.LikeInteractions = Backbone.Model.extend({ | ||
|
||
initialize: function(options) { | ||
this.likes = new app.collections.Likes(this.get("likes"), options); | ||
this.post = options.post; | ||
}, | ||
|
||
likesCount: function() { | ||
return this.get("likes_count"); | ||
}, | ||
|
||
userLike: function() { | ||
return this.likes.select(function(like) { | ||
return like.get("author") && like.get("author").guid === app.currentUser.get("guid"); | ||
})[0]; | ||
}, | ||
|
||
toggleLike: function() { | ||
if (this.userLike()) { | ||
this.unlike(); | ||
} else { | ||
this.like(); | ||
} | ||
}, | ||
|
||
like: function() { | ||
var self = this; | ||
this.likes.create({}, { | ||
success: function() { | ||
self.post.set({participation: true}); | ||
self.trigger("change"); | ||
self.set({"likes_count": self.get("likes_count") + 1}); | ||
self.likes.trigger("change"); | ||
}, | ||
error: function(model, response) { | ||
app.flashMessages.handleAjaxError(response); | ||
} | ||
}); | ||
}, | ||
|
||
unlike: function() { | ||
var self = this; | ||
this.userLike().destroy({ | ||
success: function() { | ||
// TODO: unlike always sets participation to false in the UI, even if there are more participations left | ||
// in the backend (from manually participating, other likes or comments) | ||
self.post.set({participation: false}); | ||
self.trigger("change"); | ||
self.set({"likes_count": self.get("likes_count") - 1}); | ||
self.likes.trigger("change"); | ||
}, | ||
error: function(model, response) { | ||
app.flashMessages.handleAjaxError(response); | ||
}}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.