RS MS comments propagate, and show up IN REAL TIME
This commit is contained in:
parent
40697167da
commit
9631977597
6 changed files with 36 additions and 13 deletions
|
|
@ -9,7 +9,6 @@ class Comment
|
||||||
xml_accessor :post_id
|
xml_accessor :post_id
|
||||||
|
|
||||||
key :text, String
|
key :text, String
|
||||||
key :target, String
|
|
||||||
timestamps!
|
timestamps!
|
||||||
|
|
||||||
key :post_id, ObjectId
|
key :post_id, ObjectId
|
||||||
|
|
@ -19,6 +18,8 @@ class Comment
|
||||||
belongs_to :person, :class_name => "Person"
|
belongs_to :person, :class_name => "Person"
|
||||||
|
|
||||||
after_save :send_friends_comments_on_my_posts
|
after_save :send_friends_comments_on_my_posts
|
||||||
|
after_save :send_to_view
|
||||||
|
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
(self.message == other.message) && (self.person.email == other.person.email)
|
(self.message == other.message) && (self.person.email == other.person.email)
|
||||||
|
|
@ -32,4 +33,9 @@ class Comment
|
||||||
self.push_to(self.post.friends_with_permissions)
|
self.push_to(self.post.friends_with_permissions)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def send_to_view
|
||||||
|
WebSocket.update_clients(self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
%li.comment{:id => comment.id}
|
%li.comment{:id => post.id}
|
||||||
%span.from
|
%span.from
|
||||||
= link_to_person comment.person
|
= link_to_person post.person
|
||||||
= auto_link comment.text
|
= auto_link post.text
|
||||||
%div.time
|
%div.time
|
||||||
= "#{time_ago_in_words(comment.updated_at)} ago"
|
= "#{time_ago_in_words(post.updated_at)} ago"
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
%div.comments
|
%div.comments
|
||||||
%ul.comment_set
|
%ul.comment_set{:id => post.id}
|
||||||
- for comment in post.comments
|
- for comment in post.comments
|
||||||
= render "comments/comment", :comment => comment
|
= render 'comments/comment', :post => comment
|
||||||
%li.comment
|
%li.comment
|
||||||
= render "comments/new_comment", :post => post
|
= render 'comments/new_comment', :post => post
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,13 @@
|
||||||
ws.onmessage = function(evt) {
|
ws.onmessage = function(evt) {
|
||||||
var obj = jQuery.parseJSON(evt.data);
|
var obj = jQuery.parseJSON(evt.data);
|
||||||
debug("got a " + obj['class']);
|
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(
|
$("#stream").prepend(
|
||||||
$(obj['html']).fadeIn("fast", function(){
|
$(obj['html']).fadeIn("fast", function(){
|
||||||
$("#stream label:first").inFieldLabels();
|
$("#stream label:first").inFieldLabels();
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
/= javascript_include_tag"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
|
/= 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 'jquery142', 'rails', 'view', 'publisher'
|
||||||
= javascript_include_tag 'tiny_mce/tiny_mce.js','jquery.infieldlabel'
|
= javascript_include_tag 'tiny_mce/tiny_mce.js','jquery.infieldlabel'
|
||||||
= render "js/google_a_js"
|
= render 'js/google_a_js'
|
||||||
= render "js/websocket_js"
|
= render 'js/websocket_js'
|
||||||
|
|
||||||
= csrf_meta_tag
|
= csrf_meta_tag
|
||||||
= yield(:head)
|
= yield(:head)
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,22 @@ module SocketRenderer
|
||||||
puts e.message
|
puts e.message
|
||||||
raise e
|
raise e
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
def self.view_for(object)
|
def self.view_for(object)
|
||||||
|
puts object.inspect
|
||||||
|
puts @view.type_partial(object)
|
||||||
|
|
||||||
@view.render @view.type_partial(object), :post => object
|
@view.render @view.type_partial(object), :post => object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.obj_id(object)
|
||||||
|
if object.is_a? Post
|
||||||
|
object.id
|
||||||
|
else
|
||||||
|
object.post.id
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue