]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - js/util.js
Merge branch '1.0.x' of git://gitorious.org/statusnet/mainline
[quix0rs-gnu-social.git] / js / util.js
index 60eeb418f6f2719b82a6b9d96197a840a3e3de48..6a67da4bcd25ac82bac1cc13a1854b59dd1c0129 100644 (file)
@@ -84,7 +84,7 @@ var SN = { // StatusNet
                 form.find('#'+SN.C.S.NoticeTextCount).text(jQuery.data(form[0], 'ElementData').MaxLength);
             }
 
-            if ($('body')[0].id != 'conversation' && window.location.hash.length === 0) {
+            if ($('body')[0].id != 'conversation' && window.location.hash.length === 0 && $(window).scrollTop() == 0) {
                 form.find('textarea').focus();
             }
         },
@@ -258,9 +258,10 @@ var SN = { // StatusNet
                             form.append('<p class="form_response success">'+result+'</p>');
                         }
                         else {
+                            // New notice post was successful. If on our timeline, show it!
+                            var notice = document._importNode($('li', data)[0], true);
                             var notices = $('#notices_primary .notices');
-                            if (notices.length > 0) {
-                                var notice = document._importNode($('li', data)[0], true);
+                            if (notices.length > 0 && SN.U.belongsOnTimeline(notice)) {
                                 if ($('#'+notice.id).length === 0) {
                                     var notice_irt_value = $('#'+SN.C.S.NoticeInReplyTo).val();
                                     var notice_irt = '#notices_primary #notice-'+notice_irt_value;
@@ -281,6 +282,8 @@ var SN = { // StatusNet
                                 }
                             }
                             else {
+                                // Not on a timeline that this belongs on?
+                                // Just show a success message.
                                 result = document._importNode($('title', data)[0], true);
                                 result_title = result.textContent || result.innerHTML;
                                 form.append('<p class="form_response success">'+result_title+'</p>');
@@ -401,10 +404,11 @@ var SN = { // StatusNet
 
             var attachment_more = notice.find('.attachment.more');
             if (attachment_more.length > 0) {
-                attachment_more.click(function() {
-                    $(this).addClass(SN.C.S.Processing);
-                    $.get($(this).attr('href')+'/ajax', null, function(data) {
-                        notice.find('.entry-title .entry-content').html($(data).find('#attachment_view .entry-content').html());
+                $(attachment_more[0]).click(function() {
+                    var m = $(this);
+                    m.addClass(SN.C.S.Processing);
+                    $.get(m.attr('href')+'/ajax', null, function(data) {
+                        m.parent('.entry-content').html($(data).find('#attachment_view .entry-content').html());
                     });
 
                     return false;
@@ -706,6 +710,38 @@ var SN = { // StatusNet
             Delete: function() {
                 $.cookie(SN.C.S.StatusNetInstance, null);
             }
+        },
+
+        /**
+         * Check if the current page is a timeline where the current user's
+         * posts should be displayed immediately on success.
+         *
+         * @fixme this should be done in a saner way, with machine-readable
+         * info about what page we're looking at.
+         */
+        belongsOnTimeline: function(notice) {
+            var action = $("body").attr('id');
+            if (action == 'public') {
+                return true;
+            }
+
+            var profileLink = $('#nav_profile a').attr('href');
+            if (profileLink) {
+                var authorUrl = $(notice).find('.entry-title .author a.url').attr('href');
+                if (authorUrl == profileLink) {
+                    if (action == 'all' || action == 'showstream') {
+                        // Posts always show on your own friends and profile streams.
+                        return true;
+                    }
+                }
+            }
+
+            // @fixme tag, group, reply timelines should be feasible as well.
+            // Mismatch between id-based and name-based user/group links currently complicates
+            // the lookup, since all our inline mentions contain the absolute links but the
+            // UI links currently on the page use malleable names.
+
+            return false;
         }
     },