Merge branch 'socket-group' of github.com:diaspora/diaspora_rails
This commit is contained in:
commit
20bc88c0bf
6 changed files with 53 additions and 19 deletions
|
|
@ -7,9 +7,9 @@ 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))
|
||||
Diaspora::WebSocket.push_to_user(uid, action_hash(uid, object, :group_id => opts[:group_id]))
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -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_id => opts[:group_id] , :html => v, :post_id => obj_id(object)}
|
||||
|
||||
if object.is_a? Photo
|
||||
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
|
||||
end
|
||||
|
||||
if object.person.owner_id == uid
|
||||
action_hash[:mine?] = true
|
||||
end
|
||||
|
||||
action_hash.to_json
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ class Album
|
|||
include MongoMapper::Document
|
||||
include ROXML
|
||||
include Diaspora::Webhooks
|
||||
include Encryptable
|
||||
|
||||
xml_reader :name
|
||||
xml_reader :person, :as => Person
|
||||
|
|
@ -26,7 +27,7 @@ class Album
|
|||
|
||||
def self.mine_or_friends(friend_param, current_user)
|
||||
if friend_param
|
||||
Album.where(:person_id => current_user.friend_ids)
|
||||
Album.find_all_by_person_id(current_user.friend_ids)
|
||||
else
|
||||
current_user.person.albums
|
||||
end
|
||||
|
|
@ -42,6 +43,24 @@ class Album
|
|||
p_photo ? p_photo : self.photos.sort(:created_at.desc).last
|
||||
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
|
||||
def destroy_photos
|
||||
photos.each{|p| p.destroy}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,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
|
||||
|
|
@ -246,14 +247,18 @@ class User
|
|||
person.save
|
||||
|
||||
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.save
|
||||
|
||||
self.posts << object
|
||||
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)
|
||||
|
||||
elsif object.is_a?(Comment) && object.verify_post_creator_signature
|
||||
|
|
@ -265,7 +270,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
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,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_id']);
|
||||
|
||||
if (obj['class']=="retractions"){
|
||||
processRetraction(obj['post_id']);
|
||||
|
|
@ -22,9 +22,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_id'], obj['mine?'])
|
||||
}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));
|
||||
}
|
||||
|
||||
function processPost(className, html){
|
||||
if(onPageForClass(className)){
|
||||
function processPost(className, html, groupId, mineBool){
|
||||
if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){
|
||||
$("#stream").prepend(
|
||||
$(html).fadeIn("fast", function(){
|
||||
$("#stream label:first").inFieldLabels();
|
||||
|
|
@ -61,8 +61,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
function processStatusMessage(className, html, messageHash){
|
||||
processPost(className, html);
|
||||
function processStatusMessage(className, html, messageHash, groupId, mineBool){
|
||||
processPost(className, html, groupId, mineBool);
|
||||
console.log(messageHash)
|
||||
if(messageHash['mine?']){
|
||||
updateMyLatestStatus(messageHash);
|
||||
|
|
@ -92,6 +92,10 @@
|
|||
return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne();
|
||||
}
|
||||
|
||||
function onPageForGroup(groupId){
|
||||
return (location.href.indexOf(groupId) != -1 )
|
||||
}
|
||||
|
||||
function onPageOne() {
|
||||
var c = document.location.search.charAt(document.location.search.length-1);
|
||||
return ((c =='') || (c== '1'));
|
||||
|
|
|
|||
|
|
@ -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_id => opts[:group_id])
|
||||
end
|
||||
|
||||
def unsocket_from_uid id
|
||||
|
|
|
|||
Loading…
Reference in a new issue