diff --git a/Koha/Patron/Messages.pm b/Koha/Patron/Messages.pm
index 7cc729ac86..063c70364b 100644
--- a/Koha/Patron/Messages.pm
+++ b/Koha/Patron/Messages.pm
@@ -34,6 +34,25 @@ Koha::Patron::Messages - Koha Message Object set class
=cut
+=head3 filter_by_unread
+
+ Returns a resultset of messages that have not been marked read by the patron
+
+=cut
+
+sub filter_by_unread {
+ my ( $self, $params ) = @_;
+
+ $params ||= {};
+
+ return $self->search(
+ {
+ patron_read_date => { is => undef },
+ %$params,
+ }
+ );
+}
+
=head3 _type
=cut
@@ -42,6 +61,10 @@ sub _type {
return 'Message';
}
+=head3 object_class
+
+=cut
+
sub object_class {
return 'Koha::Patron::Message';
}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc
index 19ba6cee80..cefe1d10a9 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc
+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc
@@ -308,6 +308,9 @@
( [% patron_message.get_column('manager_firstname') | html %] [% patron_message.get_column('manager_surname') | html %] )
[% END %]
"[% patron_message.message | html %]"
+ [% IF patron_message.patron_read_date %]
+ Read: [% patron_message.patron_read_date | $KohaDates %]
+ [% END %]
[% IF patron_message.branchcode == Branches.GetLoggedInBranchcode OR Koha.Preference('AllowAllMessageDeletion') %]
[% IF moremember %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc
index 22e6a068ce..6ed5e724f2 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-note.inc
@@ -1,12 +1,17 @@
-[% IF patron_messages.count OR opacnote %]
+[% IF patron_messages.filter_by_unread.count OR opacnote %]
Messages for you
- [% FOREACH message IN patron_messages %]
+ [% FOREACH message IN patron_messages.filter_by_unread %]
-
[% message.message | html | html_line_break %]
Written on [% message.message_date | $KohaDates %] by [% Branches.GetName(message.branchcode) | html %]
+
[% END %]
[% IF ( opacnote ) %]
[% opacnote | html | html_line_break %][% END %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
index 4ffbc8e024..cca221a4e0 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-main.tt
@@ -283,19 +283,19 @@
[% END %]
- [% IF patron_messages && patron_messages.count > 0 || opacnote %]
+ [% IF patron_messages && patron_messages.filter_by_unread.count > 0 || opacnote %]
[% IF opacnote %]
- [% patron_messages.count + 1 | html %]
- [% tn('message', 'messages', patron_messages.count + 1 ) | html %]
+ [% patron_messages.filter_by_unread.count + 1 | html %]
+ [% tn('message', 'messages', patron_messages.filter_by_unread.count + 1 ) | html %]
[% ELSE %]
- [% patron_messages.count | html %]
- [% tn('message', 'messages', patron_messages.count ) | html %]
+ [% patron_messages.filter_by_unread.count | html %]
+ [% tn('message', 'messages', patron_messages.filter_by_unread.count ) | html %]
[% END %]
diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
index 37d36399ea..c6ce700486 100644
--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-user.tt
@@ -1292,6 +1292,10 @@
$("#addNoteTitle").text("");
$("#addNote").val("");
});
+
+ $(".dismiss-message-button").click(function(e){
+ return confirmDelete(_("Are you sure you want to dismiss this message?"));
+ });
});
function submitNote( title, issue_id, note ){
diff --git a/opac/opac-dismiss-message.pl b/opac/opac-dismiss-message.pl
new file mode 100755
index 0000000000..84c5906b6a
--- /dev/null
+++ b/opac/opac-dismiss-message.pl
@@ -0,0 +1,54 @@
+#!/usr/bin/perl
+
+# Copyright 2023 Aleisha Amohia
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see .
+
+use Modern::Perl;
+use CGI qw ( -utf8 );
+use C4::Koha;
+use C4::Context;
+use C4::Output qw( output_html_with_http_headers );
+use C4::Auth qw( get_template_and_user );
+use Koha::DateUtils qw( dt_from_string );
+use Koha::Patrons;
+
+my $query = CGI->new;
+
+my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
+ {
+ template_name => "opac-user.tt",
+ query => $query,
+ type => "opac",
+ }
+);
+
+my $patron_id = $query->param('patron_id');
+my $patron = Koha::Patrons->find( $patron_id );
+my $message_id = $query->param('message_id');
+my $message = $patron->messages->find( $message_id );
+
+unless ( $message ) {
+ # exit early
+ print $query->redirect("/cgi-bin/koha/opac-user.pl");
+ exit;
+}
+
+$message->update({ patron_read_date => dt_from_string });
+
+print $query->redirect("/cgi-bin/koha/opac-user.pl");
+
+output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };