DG DH; made acts_as_api play nice with backbonejs. comments are semi-functional; stream elements use the StreamElement js widget (for now).
This commit is contained in:
parent
aa7343d759
commit
19db5519c0
13 changed files with 104 additions and 31 deletions
|
|
@ -145,6 +145,12 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
# @param stream_klass [Constant]
|
||||
# @return [String] JSON representation of posts given a [Stream] constant.
|
||||
def stream_json(stream_klass)
|
||||
render_for_api :backbone, :json => stream(stream_klass).stream_posts, :root => :posts
|
||||
end
|
||||
|
||||
def stream(stream_klass)
|
||||
authenticate_user!
|
||||
save_sort_order
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@ class CommentStreamController < ApplicationController
|
|||
|
||||
def index
|
||||
@backbone = true
|
||||
stream_klass = Stream::Comments
|
||||
|
||||
respond_with do |format|
|
||||
format.html{ default_stream_action(Stream::Comments) }
|
||||
format.json{ render :json => stream(Stream::Comments).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
|
||||
format.html{ default_stream_action(stream_klass) }
|
||||
format.json{ stream_json(stream_klass) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,10 +10,11 @@ class MentionsController < ApplicationController
|
|||
|
||||
def index
|
||||
@backbone = true
|
||||
stream_klass = Stream::Mention
|
||||
|
||||
respond_with do |format|
|
||||
format.html{ default_stream_action(Stream::Mention) }
|
||||
format.json{ render :json => stream(Stream::Mention).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
|
||||
format.html{ default_stream_action(stream_klass) }
|
||||
format.json{ stream_json(stream_klass) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ class MultisController < ApplicationController
|
|||
|
||||
def index
|
||||
@backbone = true
|
||||
stream_klass = Stream::Multi
|
||||
|
||||
respond_with do |format|
|
||||
format.html{ default_stream_action(Stream::Multi) }
|
||||
format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
|
||||
#format.json{ render_for_api :backbone, :json => stream(Stream::Multi).stream_posts }
|
||||
format.html{ default_stream_action(stream_klass) }
|
||||
format.json{ stream_json(stream_klass) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ class PeopleController < ApplicationController
|
|||
else
|
||||
respond_to do |format|
|
||||
format.all { respond_with @person, :locals => {:post_type => :all} }
|
||||
format.json{ render :json => @stream.stream_posts.to_json(:include => {:author => {:include => :profile}}) }
|
||||
format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,10 +11,11 @@ class TagFollowingsController < ApplicationController
|
|||
|
||||
def index
|
||||
@backbone = true
|
||||
stream_klass = Stream::FollowedTag
|
||||
|
||||
respond_with do |format|
|
||||
format.html{ default_stream_action(Stream::FollowedTag) }
|
||||
format.json{ render :json => stream(Stream::FollowedTag).stream_posts.to_json(:include => {:author => {:include => :profile}}) }
|
||||
format.html{ default_stream_action(stream_klass) }
|
||||
format.json{ stream_json(stream_klass) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class TagsController < ApplicationController
|
|||
return
|
||||
end
|
||||
end
|
||||
format.json{ render :json => @stream.stream_posts.to_json(:include => {:author => {:include => :profile}}) }
|
||||
format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,16 @@ class Comment < ActiveRecord::Base
|
|||
extract_tags_from :text
|
||||
before_create :build_tags
|
||||
|
||||
# NOTE API V1 to be extracted
|
||||
acts_as_api
|
||||
api_accessible :backbone do |t|
|
||||
t.add :id
|
||||
t.add :guid
|
||||
t.add :text
|
||||
t.add :author, :template => :post
|
||||
end
|
||||
|
||||
|
||||
xml_attr :text
|
||||
xml_attr :diaspora_handle
|
||||
|
||||
|
|
@ -55,7 +65,7 @@ class Comment < ActiveRecord::Base
|
|||
|
||||
def notification_type(user, person)
|
||||
if self.post.author == user.person
|
||||
return Notifications::CommentOnPost
|
||||
|
||||
elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id
|
||||
return Notifications::AlsoCommented
|
||||
else
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ class Post < ActiveRecord::Base
|
|||
t.add :guid
|
||||
t.add :text
|
||||
t.add :created_at
|
||||
t.add :comments_count
|
||||
t.add :last_three_comments
|
||||
t.add :provider_display_name
|
||||
t.add :author, :template => :post
|
||||
end
|
||||
|
||||
|
|
@ -33,6 +36,12 @@ class Post < ActiveRecord::Base
|
|||
#scopes
|
||||
scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message
|
||||
|
||||
# gives the last three comments on the post
|
||||
def last_three_comments
|
||||
return if self.comments_count == 0
|
||||
self.comments.last(3)
|
||||
end
|
||||
|
||||
def self.excluding_blocks(user)
|
||||
people = user.blocks.includes(:person).map{|b| b.person}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
<% var post = typeof(status_message) === "undefined" ? (typeof(reshare) === "undefined" ? photo : reshare) : status_message; %>
|
||||
|
||||
<div id="<%= post.guid %>" class="stream_element">
|
||||
<div id="<%= guid %>" class="stream_element">
|
||||
<div class="right controls">
|
||||
<a href="#" class="block_user control_icon">
|
||||
<img src="/images/icons/ignoreuser.png">
|
||||
|
|
@ -15,37 +13,82 @@
|
|||
|
||||
<div class="sm_body">
|
||||
|
||||
<a href="/people/<%= post.author.id %>">
|
||||
<img src="<%= post.author.profile.image_url_small %>" class="avatar" data-person-id="<%= post.author.id %>"/>
|
||||
<a href="/people/<%= author.id %>">
|
||||
<img src="<%= author.avatar.small %>" class="avatar" data-person-id="<%= author.id %>"/>
|
||||
</a>
|
||||
|
||||
<div class="content">
|
||||
<div class="post_initial_info">
|
||||
<span class="from">
|
||||
<a href="/people/<%= post.author.id %>">
|
||||
<%= post.author.profile.full_name %>
|
||||
<a href="/people/<%= author.id %>">
|
||||
<%= author.name %>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<span class="details">
|
||||
-
|
||||
<a href="/posts/<%= post.id %>">
|
||||
<time class="timeago" datetime="<%= post.created_at %>"/>
|
||||
<a href="/posts/<%= id %>">
|
||||
<time class="timeago" datetime="<%= created_at %>"/>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<p>
|
||||
<%= post.text %>
|
||||
<%= text %>
|
||||
</p>
|
||||
|
||||
<div class="info">
|
||||
<span class="via">
|
||||
via <%= post.provider_display_name %>
|
||||
via <%= provider_display_name %>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="comments">
|
||||
comments
|
||||
<div class="comment_stream">
|
||||
<ul class="comments" >
|
||||
|
||||
<% _.each(last_three_comments, function(comment) { %>
|
||||
<li id="<%= comment.guid %>" class="comment">
|
||||
|
||||
<a href="/people/<%= author.id %>">
|
||||
<img src="<%= comment.author.avatar.small %>" class="avatar" data-person-id="<%= comment.author.id %>"/>
|
||||
</a>
|
||||
|
||||
<div class="content">
|
||||
<span class="from">
|
||||
<a href="/people/<%= comment.author.id %>">
|
||||
<%= comment.author.name %>
|
||||
</a>
|
||||
</span>
|
||||
|
||||
<p>
|
||||
<%= comment.text %>
|
||||
</p>
|
||||
|
||||
<div class="comment_info">
|
||||
<time class="timeago" datetime="<%= comment.created_at %>"/>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
<% }) %>
|
||||
|
||||
</ul>
|
||||
|
||||
<div class="new_comment_form_wrapper">
|
||||
<form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" data-remote="true" id="new_comment_on_<%= id %>" method="post">
|
||||
<!-- <img alt="Bob Grimm" class="avatar" data-person_id="2" src="http://localhost:3000/images/user/wolf.jpg" title="Bob Grimm"> -->
|
||||
|
||||
<p>
|
||||
<label for="comment_text_on_<%= id %>">Comment</label>
|
||||
<textarea class="comment_box" id="comment_text_on_<%= id %>" name="text" rows="2" />
|
||||
</p>
|
||||
<div class="submit_button">
|
||||
<input class="comment_submit button creation" data-disable-with="Commenting..." id="comment_submit_<%= id %>" name="commit" type="submit" value="Comment" />
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -10,5 +10,9 @@ var BackboneStream = Backbone.Collection.extend({
|
|||
}
|
||||
},
|
||||
|
||||
model: Post
|
||||
model: Post,
|
||||
|
||||
parse: function(resp){
|
||||
return resp.posts;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
var Post = Backbone.Model.extend({
|
||||
url: "/posts/:id",
|
||||
intTime: function(){
|
||||
return +new Date(this.postAttributes().created_at) / 1000;
|
||||
},
|
||||
|
||||
postAttributes: function() {
|
||||
return this.attributes[_.keys(this.attributes)[0]];
|
||||
return +new Date(this.get("created_at")) / 1000;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ $(function() {
|
|||
},
|
||||
|
||||
appendPost: function(model) {
|
||||
$(this.el).append(this.template(model.toJSON()));
|
||||
var post = $(this.template(model.toJSON()));
|
||||
$(this.el).append(post);
|
||||
Diaspora.BaseWidget.instantiate("StreamElement", post);
|
||||
},
|
||||
|
||||
collectionFetched: function() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue