From 3a601656f62c902ae71836daad381dfcd6376cb5 Mon Sep 17 00:00:00 2001 From: Israel Madueme Date: Wed, 14 Nov 2018 13:45:40 -0500 Subject: [PATCH] no bug - correctly collapse orange factor bot comments 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 | 7 +++-- extensions/BugModal/lib/ActivityStream.pm | 6 ++-- extensions/BugModal/lib/MonkeyPatches.pm | 11 +++---- .../bug_modal/activity_stream.html.tmpl | 4 +-- extensions/BugModal/web/comments.js | 30 +++++++++++-------- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/extensions/BugModal/Extension.pm b/extensions/BugModal/Extension.pm index 1291fca21..b4b14fbe2 100644 --- a/extensions/BugModal/Extension.pm +++ b/extensions/BugModal/Extension.pm @@ -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; } } diff --git a/extensions/BugModal/lib/ActivityStream.pm b/extensions/BugModal/lib/ActivityStream.pm index 098c5df33..29b76d5d0 100644 --- a/extensions/BugModal/lib/ActivityStream.pm +++ b/extensions/BugModal/lib/ActivityStream.pm @@ -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'; diff --git a/extensions/BugModal/lib/MonkeyPatches.pm b/extensions/BugModal/lib/MonkeyPatches.pm index 54bd6e560..478e29368 100644 --- a/extensions/BugModal/lib/MonkeyPatches.pm +++ b/extensions/BugModal/lib/MonkeyPatches.pm @@ -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; diff --git a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl index 1c99f5c11..33a38209f 100644 --- a/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl +++ b/extensions/BugModal/template/en/default/bug_modal/activity_stream.html.tmpl @@ -42,9 +42,9 @@
  • Show CC Changes
  • - [% IF treeherder %] + [% IF treeherder_user_ids.size %]
  • - Hide Treeherder Comments + Show Treeherder Comments
  • [% END %] diff --git a/extensions/BugModal/web/comments.js b/extensions/BugModal/web/comments.js index 57a6a5103..b09cd851f 100644 --- a/extensions/BugModal/web/comments.js +++ b/extensions/BugModal/web/comments.js @@ -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'); + }); + }); } }); -- 2.47.3