Render nothing on status_messages create, Websockets now honestly
support multiple groups.
This commit is contained in:
parent
abf48cefd4
commit
db33d94f07
8 changed files with 79 additions and 77 deletions
|
|
@ -3,8 +3,10 @@ class GroupsController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :order => 'created_at DESC'
|
@posts = current_user.visible_posts(:by_members_of => :all).paginate :page => params[:page], :order => 'created_at DESC'
|
||||||
@group = :all
|
|
||||||
@friends = current_user.friends
|
@friends = current_user.friends
|
||||||
|
|
||||||
|
@groups = current_user.groups.find_all_by_id(params[:group_ids]) if params[:group_ids]
|
||||||
|
@groups ||= current_user.groups
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class SocketsController < ApplicationController
|
||||||
|
|
||||||
def outgoing(uid,object,opts={})
|
def outgoing(uid,object,opts={})
|
||||||
@_request = ActionDispatch::Request.new({})
|
@_request = ActionDispatch::Request.new({})
|
||||||
Diaspora::WebSocket.push_to_user(uid, action_hash(uid, object, :group_id => opts[:group_id]))
|
Diaspora::WebSocket.push_to_user(uid, action_hash(uid, object, opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ class StatusMessagesController < ApplicationController
|
||||||
|
|
||||||
if @status_message.created_at
|
if @status_message.created_at
|
||||||
flash[:notice] = "Successfully created status message."
|
flash[:notice] = "Successfully created status message."
|
||||||
|
render :nothing => true
|
||||||
else
|
else
|
||||||
render :action => 'new'
|
render :action => 'new'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ 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, :group_id => opts[:group_id] , :html => v, :post_id => obj_id(object)}
|
action_hash = {:class =>object.class.to_s.underscore.pluralize, :html => v, :post_id => obj_id(object)}
|
||||||
|
action_hash.merge! opts
|
||||||
if object.is_a? Photo
|
if object.is_a? Photo
|
||||||
action_hash[:photo_hash] = object.thumb_hash
|
action_hash[:photo_hash] = object.thumb_hash
|
||||||
elsif object.is_a? StatusMessage
|
elsif object.is_a? StatusMessage
|
||||||
|
|
|
||||||
|
|
@ -62,10 +62,10 @@ class User
|
||||||
group.save
|
group.save
|
||||||
target_people = target_people | group.people
|
target_people = target_people | group.people
|
||||||
}
|
}
|
||||||
|
|
||||||
|
post.socket_to_uid(id, :group_ids => groups.map{|g| g.id}) if post.respond_to?(:socket_to_uid)
|
||||||
post.push_to( target_people )
|
post.push_to( target_people )
|
||||||
|
|
||||||
post.socket_to_uid(id) if post.respond_to?(:socket_to_uid)
|
|
||||||
|
|
||||||
self.raw_visible_posts << post
|
self.raw_visible_posts << post
|
||||||
self.save
|
self.save
|
||||||
post
|
post
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@
|
||||||
//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'] + " for group " + obj['group_id']);
|
console.log(obj)
|
||||||
|
debug("got a " + obj['class'] + " for groups " + obj['group_ids']);
|
||||||
|
|
||||||
if (obj['class']=="retractions"){
|
if (obj['class']=="retractions"){
|
||||||
processRetraction(obj['post_id']);
|
processRetraction(obj['post_id']);
|
||||||
|
|
@ -19,10 +20,8 @@
|
||||||
|
|
||||||
}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'){
|
|
||||||
processStatusMessage(obj['class'], obj['html'], obj['status_message_hash'], obj['group_id'], obj['mine?'])
|
|
||||||
}else{
|
}else{
|
||||||
processPost(obj['class'], obj['html'], obj['group_id'], obj['mine?'])
|
processPost(obj['class'], obj['html'], obj['group_ids'])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,69 +32,68 @@
|
||||||
debug("connected...");
|
debug("connected...");
|
||||||
};
|
};
|
||||||
|
|
||||||
function processRetraction(post_id){
|
|
||||||
$('#' + post_id ).fadeOut(500, function(){
|
|
||||||
$(this).remove;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function processComment(post_id, html){
|
|
||||||
post = $('#' + post_id)[0]
|
|
||||||
$(' .comment_set li:last', post ).before(
|
|
||||||
$(html).fadeIn("fast", function(){})
|
|
||||||
);
|
|
||||||
toggler = $('.show_post_comments', post)
|
|
||||||
toggler.html(
|
|
||||||
toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1));
|
|
||||||
}
|
|
||||||
|
|
||||||
function processPost(className, html, groupId, mineBool){
|
|
||||||
if(mineBool || onPageForClass(className) || onPageForGroup(groupId)){
|
|
||||||
$("#stream").prepend(
|
|
||||||
$(html).fadeIn("fast", function(){
|
|
||||||
$("#stream label:first").inFieldLabels();
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function processStatusMessage(className, html, messageHash, groupId, mineBool){
|
|
||||||
processPost(className, html, groupId, mineBool);
|
|
||||||
console.log(messageHash)
|
|
||||||
if(messageHash['mine?']){
|
|
||||||
updateMyLatestStatus(messageHash);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateMyLatestStatus(messageHash){
|
|
||||||
$("#latest_message").text(messageHash['text']);
|
|
||||||
$("#latest_message_time").text(' - just now');
|
|
||||||
}
|
|
||||||
|
|
||||||
function processPhotoInAlbum(photoHash){
|
|
||||||
if (location.href.indexOf(photoHash['album_id']) == -1){
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
|
||||||
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
|
||||||
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
|
||||||
</a> </div>"
|
|
||||||
$("#thumbnails").append( $(html) )
|
|
||||||
$("#"+ photoHash['id'] + " img").load( function() {
|
|
||||||
$(this).fadeIn("slow");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function onPageForClass(className){
|
|
||||||
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'));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
function processRetraction(post_id){
|
||||||
|
$('#' + post_id ).fadeOut(500, function(){
|
||||||
|
$(this).remove;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function processComment(post_id, html){
|
||||||
|
post = $('#' + post_id)[0]
|
||||||
|
$(' .comment_set li:last', post ).before(
|
||||||
|
$(html).fadeIn("fast", function(){})
|
||||||
|
);
|
||||||
|
toggler = $('.show_post_comments', post)
|
||||||
|
toggler.html(
|
||||||
|
toggler.html().replace(/\d/,$('.comment_set', post)[0].childElementCount -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
function processPost(className, html, groupIds){
|
||||||
|
if(onPageForGroups(groupIds)){
|
||||||
|
$("#stream").prepend(
|
||||||
|
$(html).fadeIn("fast", function(){
|
||||||
|
$("#stream label:first").inFieldLabels();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function processPhotoInAlbum(photoHash){
|
||||||
|
if (location.href.indexOf(photoHash['album_id']) == -1){
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
||||||
|
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
||||||
|
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
||||||
|
</a> </div>"
|
||||||
|
$("#thumbnails").append( $(html) )
|
||||||
|
$("#"+ photoHash['id'] + " img").load( function() {
|
||||||
|
$(this).fadeIn("slow");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPageForClass(className){
|
||||||
|
return ((location.href.indexOf(className) != -1 ) || (location.pathname == '/')) && onPageOne();
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPageForGroups(groupIds){
|
||||||
|
if(location.pathname == '/' && onPageOne()){
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
var found = false;
|
||||||
|
$.each(groupIds, function(index, value) {
|
||||||
|
if(onPageForGroup(value)){ found = true };
|
||||||
|
});
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
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'));
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
development:
|
development:
|
||||||
debug: false
|
debug: false
|
||||||
socket_debug : false
|
socket_debug : true
|
||||||
socket_port: 8080
|
socket_port: 8080
|
||||||
pubsub_server: 'https://pubsubhubbub.appspot.com/'
|
pubsub_server: 'https://pubsubhubbub.appspot.com/'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ module Diaspora
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.subscribe(uid, ws)
|
def self.subscribe(uid, ws)
|
||||||
Rails.logger.debug "Subscribing socket to #{User.first(:id => uid).email}"
|
Rails.logger.debug "Subscribing socket to #{uid}"
|
||||||
self.ensure_channel(uid)
|
self.ensure_channel(uid)
|
||||||
@channels[uid][0].subscribe{ |msg| ws.send msg }
|
@channels[uid][0].subscribe{ |msg| ws.send msg }
|
||||||
@channels[uid][1] += 1
|
@channels[uid][1] += 1
|
||||||
|
|
@ -32,7 +32,8 @@ module Diaspora
|
||||||
|
|
||||||
module Socketable
|
module Socketable
|
||||||
def socket_to_uid(id, opts={})
|
def socket_to_uid(id, opts={})
|
||||||
SocketsController.new.outgoing(id, self, :group_id => opts[:group_id])
|
puts "#{id}, #{self}, #{opts}"
|
||||||
|
SocketsController.new.outgoing(id, self, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def unsocket_from_uid id
|
def unsocket_from_uid id
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue