[Rt-commit] rt branch, 4.6/unread-message-count, created. rt-4.4.4-540-gc4d89b9177

Aaron Trevena ast at bestpractical.com
Fri Jan 17 16:06:39 EST 2020


The branch, 4.6/unread-message-count has been created
        at  c4d89b91774328980f66f9a371810a8333f1ff36 (commit)

- Log -----------------------------------------------------------------
commit c4d89b91774328980f66f9a371810a8333f1ff36
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..7293f26a6b 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<br/>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

-----------------------------------------------------------------------


More information about the rt-commit mailing list