RS MS comments propagate, and show up IN REAL TIME

This commit is contained in:
maxwell 2010-06-30 17:29:32 -07:00
parent 40697167da
commit 9631977597
6 changed files with 36 additions and 13 deletions

View file

@ -9,7 +9,6 @@ class Comment
xml_accessor :post_id
key :text, String
key :target, String
timestamps!
key :post_id, ObjectId
@ -19,6 +18,8 @@ class Comment
belongs_to :person, :class_name => "Person"
after_save :send_friends_comments_on_my_posts
after_save :send_to_view
def ==(other)
(self.message == other.message) && (self.person.email == other.person.email)
@ -32,4 +33,9 @@ class Comment
self.push_to(self.post.friends_with_permissions)
end
end
def send_to_view
WebSocket.update_clients(self)
end
end

View file

@ -1,6 +1,6 @@
%li.comment{:id => comment.id}
%li.comment{:id => post.id}
%span.from
= link_to_person comment.person
= auto_link comment.text
= link_to_person post.person
= auto_link post.text
%div.time
= "#{time_ago_in_words(comment.updated_at)} ago"
= "#{time_ago_in_words(post.updated_at)} ago"

View file

@ -1,7 +1,7 @@
%div.comments
%ul.comment_set
%ul.comment_set{:id => post.id}
- for comment in post.comments
= render "comments/comment", :comment => comment
= render 'comments/comment', :post => comment
%li.comment
= render "comments/new_comment", :post => post
= render 'comments/new_comment', :post => post

View file

@ -11,7 +11,13 @@
ws.onmessage = function(evt) {
var obj = jQuery.parseJSON(evt.data);
debug("got a " + obj['class']);
if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
if (obj['class']=="comments"){
var post_id = obj['post_id']
$('#'+ obj['post_id'] + ' .comment_set li:last' ).before(
$(obj['html']).fadeIn("fast", function(){})
)
}else if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
$("#stream").prepend(
$(obj['html']).fadeIn("fast", function(){
$("#stream label:first").inFieldLabels();
@ -24,4 +30,4 @@
ws.onopen = function() {
ws.send(location.pathname);
debug("connected...");
};});
};});

View file

@ -12,8 +12,8 @@
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
= javascript_include_tag 'jquery142', 'rails', 'view', 'publisher'
= javascript_include_tag 'tiny_mce/tiny_mce.js','jquery.infieldlabel'
= render "js/google_a_js"
= render "js/websocket_js"
= render 'js/google_a_js'
= render 'js/websocket_js'
= csrf_meta_tag
= yield(:head)

View file

@ -22,11 +22,22 @@ module SocketRenderer
puts e.message
raise e
end
{:class =>object.class.to_s.underscore.pluralize, :html => v}
{:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
end
def self.view_for(object)
puts object.inspect
puts @view.type_partial(object)
@view.render @view.type_partial(object), :post => object
end
def self.obj_id(object)
if object.is_a? Post
object.id
else
object.post.id
end
end
end