[Rt-commit] rt branch, 4.6/unread-message-count, created. rt-4.4.4-541-gbaa67be8b2
Aaron Trevena
ast at bestpractical.com
Wed Jan 29 13:09:04 EST 2020
The branch, 4.6/unread-message-count has been created
at baa67be8b2c07157148ab86df9152174bdd34f21 (commit)
- Log -----------------------------------------------------------------
commit 62e2a9a216cab9a8b2a25b1b8f36d2945814f837
Author: Aaron Trevena <ast at bestpractical.com>
Date: Mon Dec 9 15:13:36 2019 +0000
Move unread message count to core
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 5c400464cd..f257885bc6 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1524,6 +1524,41 @@ sub TotalTimeWorkedPerUser {
return $time;
}
+=head2 SeenUpToCount
+
+Returns the number of transactions marked as seen by this user for this ticket
+
+=cut
+
+sub SeenUpToCount {
+ my $self= shift;
+ my $uid = $self->CurrentUser->id;
+ my $attr = $self->FirstAttribute( "User-". $uid ."-SeenUpTo" );
+ if( $attr && $attr->Content gt $self->LastUpdated) {
+ return ( 0, undef);
+ }
+
+ my $txns = $self->Transactions;
+ $txns->Limit( FIELD => 'Type', VALUE => 'Comment' );
+ $txns->Limit( FIELD => 'Type', VALUE => 'Correspond' );
+ $txns->Limit( FIELD => 'Creator', OPERATOR => '!=', VALUE => $uid );
+ $txns->Limit(
+ FIELD => 'Created',
+ OPERATOR => '>',
+ VALUE => $attr->Content
+ ) if $attr;
+
+ my $count = $txns->Count;
+
+ if( $count) {
+ my $first_unread = $txns->First;
+ return ($count, $first_unread);
+ } else {
+ return (0, undef);
+ }
+}
+
+
=head2 Comment
Comment on this ticket.
diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap
index 5f5d4b6b27..dea828f128 100644
--- a/share/html/Elements/RT__Ticket/ColumnMap
+++ b/share/html/Elements/RT__Ticket/ColumnMap
@@ -332,6 +332,21 @@ $COLUMN_MAP = {
return \($m->scomp("/Ticket/Elements/PopupTimerLink", id => $_[0]->id ) );
},
},
+ UnreadMessages => {
+ title => 'Unread Messages', # loc
+ attribute => 'UnreadMessages',
+ value => sub {
+ my $self = shift;
+
+ my( $count, $first_unread) = $self->SeenUpToCount;
+
+ return '0' if ! $count;
+
+ return \('<a class="unread_nb" title="jump to Unread & Mark as Seen" href="'. RT->Config->Get('WebPath') .'/Ticket/Display.html?id='
+ . $self->id .'&MarkAsSeen=1&Anchor=txn-'. $first_unread->id .'">'),
+ $count, \'</a>';
+ }
+ }
};
my %ranges = RT::Ticket->CustomDateRanges;
diff --git a/share/html/Search/Elements/BuildFormatString b/share/html/Search/Elements/BuildFormatString
index b35a81d313..0cf1cf22f5 100644
--- a/share/html/Search/Elements/BuildFormatString
+++ b/share/html/Search/Elements/BuildFormatString
@@ -96,6 +96,7 @@ my @fields = qw(
Parents Children
Bookmark Timer
+ UnreadMessages
NEWLINE
NBSP
commit baa67be8b2c07157148ab86df9152174bdd34f21
Author: Aaron Trevena <ast at bestpractical.com>
Date: Fri Jan 24 20:28:03 2020 +0000
Reworked unread message count to be consistent with core
CSS style was un-necessary, simplified to just be bold like title
Worked new unread count value into existing method in list context
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index f257885bc6..d43b0e58c8 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -1524,41 +1524,6 @@ sub TotalTimeWorkedPerUser {
return $time;
}
-=head2 SeenUpToCount
-
-Returns the number of transactions marked as seen by this user for this ticket
-
-=cut
-
-sub SeenUpToCount {
- my $self= shift;
- my $uid = $self->CurrentUser->id;
- my $attr = $self->FirstAttribute( "User-". $uid ."-SeenUpTo" );
- if( $attr && $attr->Content gt $self->LastUpdated) {
- return ( 0, undef);
- }
-
- my $txns = $self->Transactions;
- $txns->Limit( FIELD => 'Type', VALUE => 'Comment' );
- $txns->Limit( FIELD => 'Type', VALUE => 'Correspond' );
- $txns->Limit( FIELD => 'Creator', OPERATOR => '!=', VALUE => $uid );
- $txns->Limit(
- FIELD => 'Created',
- OPERATOR => '>',
- VALUE => $attr->Content
- ) if $attr;
-
- my $count = $txns->Count;
-
- if( $count) {
- my $first_unread = $txns->First;
- return ($count, $first_unread);
- } else {
- return (0, undef);
- }
-}
-
-
=head2 Comment
Comment on this ticket.
@@ -2636,6 +2601,8 @@ sub _SetTold {
=head2 SeenUpTo
+Returns the first transaction since last viewed/interacted by user
+In list context returns the first transaction and number of transactions marked as seen by this user for this ticket
=cut
@@ -2643,7 +2610,9 @@ sub SeenUpTo {
my $self = shift;
my $uid = $self->CurrentUser->id;
my $attr = $self->FirstAttribute( "User-". $uid ."-SeenUpTo" );
- return if $attr && $attr->Content gt $self->LastUpdated;
+ if ($attr && $attr->Content gt $self->LastUpdated ) {
+ return (wantarray) ? ( undef, 0 ) : undef ;
+ }
my $txns = $self->Transactions;
$txns->Limit( FIELD => 'Type', VALUE => 'Comment' );
@@ -2655,7 +2624,14 @@ sub SeenUpTo {
VALUE => $attr->Content
) if $attr;
$txns->RowsPerPage(1);
- return $txns->First;
+
+ my $next_unread_txn = $txns->First;
+ if (wantarray) {
+ my $count = $txns->Count || 0;
+ return ($next_unread_txn, $count);
+ }
+
+ return $next_unread_txn;
}
=head2 RanTransactionBatch
diff --git a/share/html/Elements/RT__Ticket/ColumnMap b/share/html/Elements/RT__Ticket/ColumnMap
index dea828f128..64d2872987 100644
--- a/share/html/Elements/RT__Ticket/ColumnMap
+++ b/share/html/Elements/RT__Ticket/ColumnMap
@@ -334,17 +334,19 @@ $COLUMN_MAP = {
},
UnreadMessages => {
title => 'Unread Messages', # loc
- attribute => 'UnreadMessages',
value => sub {
my $self = shift;
- my( $count, $first_unread) = $self->SeenUpToCount;
+ my ($first_unread, $count) = $self->SeenUpTo;
return '0' if ! $count;
- return \('<a class="unread_nb" title="jump to Unread & Mark as Seen" href="'. RT->Config->Get('WebPath') .'/Ticket/Display.html?id='
- . $self->id .'&MarkAsSeen=1&Anchor=txn-'. $first_unread->id .'">'),
- $count, \'</a>';
+ my $link = RT->Config->Get('WebPath');
+ $link .= ( $session{'CurrentUser'}->Privileged ) ? '/Ticket/Display.html?id=' : '/SelfService/Display.html?id=';
+ $link .= $self->id .'&MarkAsSeen=1&Anchor=txn-'. $first_unread->id;
+
+ return \('<a title="jump to Unread & Mark as Seen" href="'. $link .'"><b>'),
+ $count, \'</b></a>';
}
}
};
-----------------------------------------------------------------------
More information about the rt-commit
mailing list