RS; posted statuses now use the websocket to update latest, time is now styled right

This commit is contained in:
Raphael 2010-08-02 11:13:21 -07:00
parent b8ae6b44a2
commit d503c6541f
6 changed files with 29 additions and 9 deletions

View file

@ -22,6 +22,8 @@ module SocketsHelper
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
action_hash[:status_message_hash] = object.latest_hash
end end
action_hash.to_json action_hash.to_json

View file

@ -21,9 +21,8 @@ class StatusMessage < Post
XML XML
end end
def ==(other) def latest_hash
(self.message == other.message) && (self.person.email == other.person.email) {:mine? => self.person == User.owner, :text => message}
end end
end end

View file

@ -20,9 +20,13 @@
}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'])
}else{ }else{
processPost(obj['class'], obj['html']) processPost(obj['class'], obj['html'])
} }
}; };
ws.onclose = function() { debug("socket closed"); }; ws.onclose = function() { debug("socket closed"); };
ws.onopen = function() { ws.onopen = function() {
@ -56,6 +60,18 @@
} }
} }
function processStatusMessage(className, html, messageHash){
processPost(className, html);
if(messageHash['mine?']){
updateMyLatestStatus(messageHash);
}
}
function updateMyLatestStatus(messageHash){
$("#latest_message").text(messageHash['text']);
$("#latest_message_time").text(' - just now');
}
function processPhotoInAlbum(photoHash){ function processPhotoInAlbum(photoHash){
if (location.href.indexOf(photoHash['album_id']) == -1){ if (location.href.indexOf(photoHash['album_id']) == -1){
return ; return ;
@ -65,7 +81,7 @@
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \ <img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
</a> </div>" </a> </div>"
$("#thumbnails").append( $(html) ) $("#thumbnails").append( $(html) )
$(".image_thumb img").load( function() { $("#"+ photoHash['id'] + " img").load( function() {
$(this).fadeIn("slow"); $(this).fadeIn("slow");
}); });
} }

View file

@ -50,9 +50,9 @@
= link_to current_user.real_name, root_path = link_to current_user.real_name, root_path
%span#latest_message %span#latest_message
= my_latest_message = my_latest_message
- unless @latest_status_message.nil? - unless @latest_status_message.nil?
%span{:style => "font-size: small"} %span{:style => "font-size: small", :id => 'latest_message_time'}
= " - #{how_long_ago @latest_status_message}" = " - #{how_long_ago @latest_status_message}"
%ul.nav %ul.nav
%li= link_to "home", root_path %li= link_to "home", root_path

View file

@ -7,8 +7,6 @@
$("#new_status_message").submit(function() { $("#new_status_message").submit(function() {
var new_status = $('#status_message_message').val() + " - just now";
$('#latest_message').text( new_status );
}); });
function selectPublisherTab(evt){ function selectPublisherTab(evt){

View file

@ -177,6 +177,11 @@ form {
#user_name #latest_message span { #user_name #latest_message span {
size: small; size: small;
font-style: italic; } font-style: italic; }
#user_name #latest_message_time{
font-weight: normal;
color: #999999;
size: small;
font-style: italic; }
#user_name ul { #user_name ul {
display: inline; display: inline;
margin: 0; margin: 0;