DG IZ added group id to the action hash

This commit is contained in:
ilya 2010-08-17 15:27:12 -07:00
parent fd539926c2
commit 87bc9dad1d
5 changed files with 25 additions and 16 deletions

View file

@ -7,7 +7,7 @@ class SocketsController < ApplicationController
Rails.logger.info("Socket received connection to: #{msg}")
end
def outgoing(uid,object)
def outgoing(uid,object,opts={})
@_request = ActionDispatch::Request.new({})
Diaspora::WebSocket.push_to_user(uid, action_hash(uid, object))
end

View file

@ -5,7 +5,7 @@ module SocketsHelper
(object.is_a? Post) ? object.id : object.post_id
end
def action_hash(uid, object)
def action_hash(uid, object, opts={})
begin
user = User.find_by_id(uid)
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
@ -13,7 +13,7 @@ module SocketsHelper
Rails.logger.error("web socket view rendering failed for object #{object.inspect}.")
raise e
end
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
action_hash = {:class =>object.class.to_s.underscore.pluralize, :group => opts[:group] , :html => v, :post_id => obj_id(object)}
if object.is_a? Photo
action_hash[:photo_hash] = object.thumb_hash
@ -21,7 +21,7 @@ module SocketsHelper
action_hash[:status_message_hash] = object.latest_hash
action_hash[:status_message_hash][:mine?] = true if object.person.owner_id == uid
end
action_hash.to_json
end

View file

@ -45,7 +45,8 @@ class User
post.creator_signature = post.sign_with_key(encryption_key)
post.save
post.notify_people
post.socket_to_uid owner.id if (owner_id && post.respond_to?(:socket_to_uid))
post.socket_to_uid(id) if post.respond_to?(:socket_to_uid)
self.posts << post
self.save
@ -252,7 +253,9 @@ class User
self.posts << object
self.save
object.socket_to_uid(id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
group = groups.find_by_person_id(object.person.id)
object.socket_to_uid(id, :group_id => group.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
dispatch_comment object if object.is_a?(Comment) && !owns?(object)
elsif object.is_a?(Comment) && object.verify_post_creator_signature
@ -264,7 +267,9 @@ class User
elsif object.verify_creator_signature == true
Rails.logger.debug("Saving object: #{object}")
object.save
object.socket_to_uid(id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
group = groups.find_by_person_id(object.person.id)
object.socket_to_uid(id, :group_id => group.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
end
end

View file

@ -12,7 +12,7 @@
//Attach onmessage to websocket
ws.onmessage = function(evt) {
var obj = jQuery.parseJSON(evt.data);
debug("got a " + obj['class']);
debug("got a " + obj['class'] + 'for group' + obj['group']);
if (obj['class']=="retractions"){
processRetraction(obj['post_id']);
@ -23,9 +23,9 @@
}else if (obj['class']=='photos' && onPageForClass('albums')){
processPhotoInAlbum(obj['photo_hash'])
}else if (obj['class']=='status_messages'){
processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'])
processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'], obj['group'])
}else{
processPost(obj['class'], obj['html'])
processPost(obj['class'], obj['html'], obj['group'])
}
@ -52,8 +52,8 @@
toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1));
}
function processPost(className, html){
if(onPageForClass(className)){
function processPost(className, html, groupId){
if(onPageForClass(className) || onPageForGroup(groupId)){
$("#stream").prepend(
$(html).fadeIn("fast", function(){
$("#stream label:first").inFieldLabels();
@ -62,8 +62,8 @@
}
}
function processStatusMessage(className, html, messageHash){
processPost(className, html);
function processStatusMessage(className, html, messageHash, group_id){
processPost(className, html, group_id);
console.log(messageHash)
if(messageHash['mine?']){
updateMyLatestStatus(messageHash);
@ -92,6 +92,10 @@
function onPageForClass(className){
return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne();
}
function onPageForGroup(groupId){
alert( groupId);
}
function onPageOne() {
var c = document.location.search.charAt(document.location.search.length-1);

View file

@ -31,8 +31,8 @@ module Diaspora
end
module Socketable
def socket_to_uid id
SocketsController.new.outgoing(id, self)
def socket_to_uid(id, opts={})
SocketsController.new.outgoing(id, self, :group => opts[:group_id])
end
def unsocket_from_uid id