From 94bc18e467197e63cbf91490473f839748a72ac2 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Mon, 2 May 2011 17:12:18 -0700 Subject: [PATCH] Make websocket closed message less disruptive --- config/locales/javascript/javascript.en.yml | 4 +--- public/javascripts/web-socket-receiver.js | 25 +++++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/config/locales/javascript/javascript.en.yml b/config/locales/javascript/javascript.en.yml index 921e07227..97e3552f2 100644 --- a/config/locales/javascript/javascript.en.yml +++ b/config/locales/javascript/javascript.en.yml @@ -35,6 +35,4 @@ en: infinite_scroll: no_more: "No more posts." web_sockets: - disconnected: - title: "You have been disconnected." - body: "Posts will no longer be streamed live." \ No newline at end of file + disconnected: "The websocket is closed; posts will no longer be streamed live." diff --git a/public/javascripts/web-socket-receiver.js b/public/javascripts/web-socket-receiver.js index d398939f9..c0bfdc578 100644 --- a/public/javascripts/web-socket-receiver.js +++ b/public/javascripts/web-socket-receiver.js @@ -6,11 +6,12 @@ var WebSocketReceiver = { //Attach onmessage to websocket ws.onmessage = WSR.onMessage; ws.onclose = function() { - Diaspora.widgets.alert.alert( - Diaspora.widgets.i18n.t("web_sockets.disconnected.title"), - Diaspora.widgets.i18n.t("web_sockets.disconnected.body") - ); - + Diaspora.widgets.notifications.showNotification({ + html: '
' + + Diaspora.widgets.i18n.t("web_sockets.disconnected") + + '
' + }); + WSR.debug("socket closed"); }; ws.onopen = function() { @@ -42,7 +43,7 @@ var WebSocketReceiver = { }); } else if (obj['class']=="likes") { - WebSocketReceiver.processLike(obj.post_id, obj.html) + WebSocketReceiver.processLike(obj.post_id, obj.html); } else { WebSocketReceiver.processPost(obj['class'], obj.post_id, obj.html, obj.aspect_ids); @@ -60,7 +61,7 @@ var WebSocketReceiver = { } else { $('#people_stream').prepend(response.html).slideDown('slow', function(){}); var first_li = result_ul.find('li:first'); - first_li.hide() + first_li.hide(); first_li.after(response.html); result_ul.find("[name='request[into]']").val(result_ul.attr('aspect_id')); result_ul.children(':nth-child(2)').slideDown('fast', function(){}); @@ -76,14 +77,14 @@ var WebSocketReceiver = { $("*[data-guid='" + post_id + "']").fadeOut(400, function() { $(this).remove(); }); - if($("#main_stream")[0].childElementCount == 0) { + if($("#main_stream")[0].childElementCount === 0) { $("#no_posts").fadeIn(200); } }, processComment: function(postId, commentId, html, opts) { - if( $(".comment[data-guid='"+commentId+"']").length == 0 ) { + if( $(".comment[data-guid='"+commentId+"']").length === 0 ) { var post = $("*[data-guid='"+postId+"']'"), prevComments = $('.comment.posted', post); @@ -131,7 +132,7 @@ var WebSocketReceiver = { }, addPostToStream: function(postId, html) { - if( $(".stream_element[data-guid='" + postId + "']").length == 0 ) { + if( $(".stream_element[data-guid='" + postId + "']").length === 0 ) { var streamElement = $(html); var showMessage = function() { @@ -164,7 +165,7 @@ var WebSocketReceiver = { if(WebSocketReceiver.onStreamForAspect(value, streamIds)) { found = true; return false; - }; + } }); return found; }, @@ -175,7 +176,7 @@ var WebSocketReceiver = { onPageOne: function() { var c = document.location.search.charAt(document.location.search.length-1); - return ((c =='') || (c== '1')); + return ((c === '') || (c === '1')); }, debug: function(str) { $("#debug").append("

" + str);