Merge branch 'socket-group' of github.com:diaspora/diaspora_rails

This commit is contained in:
Raphael 2010-08-17 20:19:29 -07:00
commit 20bc88c0bf
6 changed files with 53 additions and 19 deletions

View file

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

View file

@ -5,7 +5,7 @@ module SocketsHelper
(object.is_a? Post) ? object.id : object.post_id (object.is_a? Post) ? object.id : object.post_id
end end
def action_hash(uid, object) def action_hash(uid, object, opts={})
begin begin
user = User.find_by_id(uid) 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 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}.") Rails.logger.error("web socket view rendering failed for object #{object.inspect}.")
raise e raise e
end 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_id => opts[:group_id] , :html => v, :post_id => obj_id(object)}
if object.is_a? Photo if object.is_a? Photo
action_hash[:photo_hash] = object.thumb_hash action_hash[:photo_hash] = object.thumb_hash
@ -22,6 +22,10 @@ module SocketsHelper
action_hash[:status_message_hash][:mine?] = true if object.person.owner_id == uid action_hash[:status_message_hash][:mine?] = true if object.person.owner_id == uid
end end
if object.person.owner_id == uid
action_hash[:mine?] = true
end
action_hash.to_json action_hash.to_json
end end

View file

@ -3,6 +3,7 @@ class Album
include MongoMapper::Document include MongoMapper::Document
include ROXML include ROXML
include Diaspora::Webhooks include Diaspora::Webhooks
include Encryptable
xml_reader :name xml_reader :name
xml_reader :person, :as => Person xml_reader :person, :as => Person
@ -26,7 +27,7 @@ class Album
def self.mine_or_friends(friend_param, current_user) def self.mine_or_friends(friend_param, current_user)
if friend_param if friend_param
Album.where(:person_id => current_user.friend_ids) Album.find_all_by_person_id(current_user.friend_ids)
else else
current_user.person.albums current_user.person.albums
end end
@ -42,6 +43,24 @@ class Album
p_photo ? p_photo : self.photos.sort(:created_at.desc).last p_photo ? p_photo : self.photos.sort(:created_at.desc).last
end end
#ENCRYPTION
xml_accessor :creator_signature
key :creator_signature, String
def signable_accessors
accessors = self.class.roxml_attrs.collect{|definition|
definition.accessor}
accessors.delete 'person'
accessors.delete 'creator_signature'
accessors
end
def signable_string
signable_accessors.collect{|accessor|
(self.send accessor.to_sym).to_s}.join ';'
end
protected protected
def destroy_photos def destroy_photos
photos.each{|p| p.destroy} photos.each{|p| p.destroy}

View file

@ -46,7 +46,8 @@ class User
post.creator_signature = post.sign_with_key(encryption_key) post.creator_signature = post.sign_with_key(encryption_key)
post.save post.save
post.notify_people 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.posts << post
self.save self.save
@ -246,14 +247,18 @@ class User
person.save person.save
elsif object.is_a?(Post) && object.verify_creator_signature == true elsif object.is_a?(Post) && object.verify_creator_signature == true
Rails.logger.debug("Saving post: #{object}") Rails.logger.debug("Saving post: #{object.inspect}")
object.user_refs += 1 object.user_refs += 1
object.save object.save
self.posts << object self.posts << object
self.save self.save
object.socket_to_uid(id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object))
group = groups.first
Rails.logger.info("pushing a message to group: #{group.name}")
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) dispatch_comment object if object.is_a?(Comment) && !owns?(object)
elsif object.is_a?(Comment) && object.verify_post_creator_signature elsif object.is_a?(Comment) && object.verify_post_creator_signature
@ -265,7 +270,9 @@ class User
elsif object.verify_creator_signature == true elsif object.verify_creator_signature == true
Rails.logger.debug("Saving object: #{object}") Rails.logger.debug("Saving object: #{object}")
object.save 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
end end

View file

@ -11,7 +11,7 @@
//Attach onmessage to websocket //Attach onmessage to websocket
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'] + " for group " + obj['group_id']);
if (obj['class']=="retractions"){ if (obj['class']=="retractions"){
processRetraction(obj['post_id']); processRetraction(obj['post_id']);
@ -22,9 +22,9 @@
}else if (obj['class']=='photos' && onPageForClass('albums')){ }else if (obj['class']=='photos' && onPageForClass('albums')){
processPhotoInAlbum(obj['photo_hash']) processPhotoInAlbum(obj['photo_hash'])
}else if (obj['class']=='status_messages'){ }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_id'], obj['mine?'])
}else{ }else{
processPost(obj['class'], obj['html']) processPost(obj['class'], obj['html'], obj['group_id'], obj['mine?'])
} }
@ -51,8 +51,8 @@
toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1)); toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1));
} }
function processPost(className, html){ function processPost(className, html, groupId, mineBool){
if(onPageForClass(className)){ if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){
$("#stream").prepend( $("#stream").prepend(
$(html).fadeIn("fast", function(){ $(html).fadeIn("fast", function(){
$("#stream label:first").inFieldLabels(); $("#stream label:first").inFieldLabels();
@ -61,8 +61,8 @@
} }
} }
function processStatusMessage(className, html, messageHash){ function processStatusMessage(className, html, messageHash, groupId, mineBool){
processPost(className, html); processPost(className, html, groupId, mineBool);
console.log(messageHash) console.log(messageHash)
if(messageHash['mine?']){ if(messageHash['mine?']){
updateMyLatestStatus(messageHash); updateMyLatestStatus(messageHash);
@ -92,6 +92,10 @@
return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne(); return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne();
} }
function onPageForGroup(groupId){
return (location.href.indexOf(groupId) != -1 )
}
function onPageOne() { function onPageOne() {
var c = document.location.search.charAt(document.location.search.length-1); var c = document.location.search.charAt(document.location.search.length-1);
return ((c =='') || (c== '1')); return ((c =='') || (c== '1'));

View file

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