]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
no bug - correctly collapse orange factor bot comments
authorIsrael Madueme <purelogiq@gmail.com>
Wed, 14 Nov 2018 18:45:40 +0000 (13:45 -0500)
committerGitHub <noreply@github.com>
Wed, 14 Nov 2018 18:45:40 +0000 (13:45 -0500)
Fixes a regression where orange factor bot comments where not being
collapsed by default and also not being collapsed by the 'Show/Hide
Treeherder Comments' button.

This also fixes a bug where the 'Show CC Changes' and 'Show/Hide
Treeherder Comments' buttons would not toggle their text after being
clicked.

extensions/BugModal/Extension.pm
extensions/BugModal/lib/ActivityStream.pm
extensions/BugModal/lib/MonkeyPatches.pm
extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl
extensions/BugModal/web/comments.js

index 1291fca215128c72e649f8ced561dc8c722e4262..b4b14fbe20feed390a9dfe28bed8356990b880bb 100644 (file)
@@ -289,10 +289,11 @@ sub template_before_process {
     $vars->{tracking_flags_table} = \@tracking_table;
 
     # for the "view -> hide treeherder comments" menu item
-    my $treeherder_id = Bugzilla->treeherder_user->id;
+    my @treeherder_ids = map { $_->id } @{Bugzilla->treeherder_users};
     foreach my $change_set (@{ $bug->activity_stream }) {
-        if ($change_set->{comment} && $change_set->{comment}->author->id == $treeherder_id) {
-            $vars->{treeherder} = Bugzilla->treeherder_user;
+        if ($change_set->{comment} &&
+              any { $change_set->{comment}->author->id == $_ } @treeherder_ids){
+            $vars->{treeherder_user_ids} = \@treeherder_ids;
             last;
         }
     }
index 098c5df3321484873c59076990be1ed2cf5542db..29b76d5d03817796921ea588c1fb9a8a1990ba60 100644 (file)
@@ -17,6 +17,7 @@ use warnings;
 use Bugzilla::Extension::BugModal::Util qw(date_str_to_time);
 use Bugzilla::User;
 use Bugzilla::Constants;
+use List::MoreUtils qw(any);
 
 # returns an arrayref containing all changes to the bug - comments, field
 # changes, and duplicates
@@ -162,7 +163,7 @@ sub _add_activity_to_stream {
 sub _add_comments_to_stream {
     my ($bug, $stream) = @_;
     my $user = Bugzilla->user;
-    my $treeherder_id = Bugzilla->treeherder_user->id;
+    my @treeherder_ids = map { $_->id } @{Bugzilla->treeherder_users};
 
     my $raw_comments = $bug->comments();
     foreach my $comment (@$raw_comments) {
@@ -172,10 +173,11 @@ sub _add_comments_to_stream {
         next if $comment->body eq '' && ($comment->work_time - 0) != 0 && $user->is_timetracker;
 
         # treeherder is so spammy we hide its comments by default
-        if ($author_id == $treeherder_id) {
+        if (any { $_ == $author_id  } @treeherder_ids) {
             $comment->{collapsed} = 1;
             $comment->{collapsed_reason} = $comment->author->name;
         }
+
         if ($comment->type != CMT_ATTACHMENT_CREATED && $comment->count == 0 && length($comment->body) == 0) {
             $comment->{collapsed} = 1;
             $comment->{collapsed_reason} = 'empty';
index 54bd6e5607e03ce45e4f10f10be33ca03e726e53..478e29368d8e111fb96748e0f261e40de04a1aac 100644 (file)
@@ -16,11 +16,12 @@ use warnings;
 
 use Bugzilla::User;
 
-sub treeherder_user {
-    return Bugzilla->process_cache->{treeherder_user} //=
-        Bugzilla::User->new({ name => 'tbplbot@gmail.com', cache => 1 })
-        || Bugzilla::User->new({ name => 'orangefactor@bots.tld', cache => 1 })
-        || Bugzilla::User->new();
+sub treeherder_users {
+    return Bugzilla->process_cache->{treeherder_users} //=
+        [grep { defined $_ } (
+          Bugzilla::User->new({ name => 'tbplbot@gmail.com', cache => 1 }),
+          Bugzilla::User->new({ name => 'orangefactor@bots.tld', cache => 1 }),
+        )];
 }
 
 package Bugzilla::Bug;
index 1c99f5c11b83c00912f5ce1bbc0d36faf236b286..33a38209fee3654d97fc78c4a3f531e61b942039 100644 (file)
@@ -42,9 +42,9 @@
       <li role="presentation">
         <a id="view-toggle-cc" role="menuitem" tabindex="-1">Show CC Changes</a>
       </li>
-      [% IF treeherder %]
+      [% IF treeherder_user_ids.size %]
         <li role="presentation">
-          <a id="view-toggle-treeherder" role="menuitem" data-userid="[% treeherder.id FILTER none %]">Hide Treeherder Comments</a>
+          <a id="view-toggle-treeherder" role="menuitem" data-userids="[[% treeherder_user_ids.join(',') FILTER none %]]">Show Treeherder Comments</a>
         </li>
       [% END %]
     </ul>
index 57a6a5103eaed0932de1949f87606153cdf8db6b..b09cd851fe88016437b9b213e62d9732d0fabb6e 100644 (file)
@@ -159,15 +159,14 @@ $(function() {
     $('#view-toggle-cc')
         .click(function() {
             var that = $(this);
-            var item = $('.context-menu-item.hover');
             if (that.data('shown') === '1') {
                 that.data('shown', '0');
-                item.text('Show CC Changes');
+                that.text('Show CC Changes');
                 $('.cc-only').hide();
             }
             else {
                 that.data('shown', '1');
-                item.text('Hide CC Changes');
+                that.text('Hide CC Changes');
                 $('.cc-only').show();
             }
         });
@@ -175,17 +174,24 @@ $(function() {
     $('#view-toggle-treeherder')
         .click(function() {
             var that = $(this);
-            console.log(that.data('userid'));
-            var item = $('.context-menu-item.hover');
-            if (that.data('hidden') === '1') {
-                that.data('hidden', '0');
-                item.text('Hide Treeherder Comments');
-                $('.ca-' + that.data('userid')).show();
+            var userids = that.data('userids');
+            if (that.data('hidden') === '0') {
+                that.data('hidden', '1');
+                that.text('Show Treeherder Comments');
+                userids.forEach((id) => {
+                    $('.ca-' + id).each(function() {
+                        toggleChange($(this).find('.default-collapsed .change-spinner').first(), 'hide');
+                    });
+                });
             }
             else {
-                that.data('hidden', '1');
-                item.text('Show Treeherder Comments');
-                $('.ca-' + that.data('userid')).hide();
+                that.data('hidden', '0');
+                that.text('Hide Treeherder Comments');
+                userids.forEach((id) => {
+                    $('.ca-' + id).each(function() {
+                        toggleChange($(this).find('.default-collapsed .change-spinner').first(), 'show');
+                    });
+                });
             }
         });