From 737e2fb8df32ea80e30dbd220ae70e7542d2e4a3 Mon Sep 17 00:00:00 2001 From: John Burwell Date: Sun, 30 Apr 2023 20:20:07 -0500 Subject: [PATCH] mark messages as read in r and rm --- rsbbs/plugins/readm/plugin.py | 6 ++++++ rsbbs/plugins/readnew/plugin.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/rsbbs/plugins/readm/plugin.py b/rsbbs/plugins/readm/plugin.py index 47cda8c..5a68814 100644 --- a/rsbbs/plugins/readm/plugin.py +++ b/rsbbs/plugins/readm/plugin.py @@ -60,6 +60,12 @@ class Plugin(): self.api.write_output(f"Reading {count} messages:") for message in messages: self.api.print_message(message) + with self.api.controller.session() as session: + user = session.get(User, self.api.user.id) + user.messages.append(message[0]) + session.commit() + logging.info(f"User {self.api.user.id} " + f"read message {message[0].id }") self.api.read_enter("Enter to continue...") else: self.api.write_output(f"No messages to read.") diff --git a/rsbbs/plugins/readnew/plugin.py b/rsbbs/plugins/readnew/plugin.py index 5a01708..6b1b5ff 100644 --- a/rsbbs/plugins/readnew/plugin.py +++ b/rsbbs/plugins/readnew/plugin.py @@ -40,9 +40,11 @@ class Plugin(): def list_mine(self, args) -> sqlalchemy.ChunkedIteratorResult: with self.api.controller.session() as session: try: + callsign = self.api.config.calling_station statement = sqlalchemy.select(Message).where( - Message.recipient == self.api.config.calling_station - and self.api.user.id not in Message.read_by) + Message.recipient == callsign).where( + ~Message.read_by.any(User.id == self.api.user.id) + ) result = session.execute( statement, execution_options={"prebuffer_rows": True}) @@ -61,6 +63,12 @@ class Plugin(): self.api.write_output(f"Reading {count} messages:") for message in messages: self.api.print_message(message) + with self.api.controller.session() as session: + user = session.get(User, self.api.user.id) + user.messages.append(message[0]) + session.commit() + logging.info(f"User {self.api.user.id} " + f"read message {message[0].id }") self.api.read_enter("Enter to continue...") else: self.api.write_output(f"No messages to read.")