Implement LIST ACTIVE
This commit is contained in:
parent
02e6550b6a
commit
0dc58bcd88
1 changed files with 33 additions and 0 deletions
|
@ -263,8 +263,41 @@ class Session():
|
|||
|
||||
return self.end()
|
||||
|
||||
def _newsgroup_last_active(self, newsgroup: Newsgroup):
|
||||
sql = """
|
||||
select
|
||||
max(created_on)
|
||||
from
|
||||
newsgroup_message
|
||||
where
|
||||
newsgroup_id = ?
|
||||
"""
|
||||
|
||||
cr = self.db.execute(sql, (newsgroup.id,))
|
||||
row = cr.fetchone()
|
||||
|
||||
if row is None:
|
||||
return
|
||||
|
||||
return datetime.datetime.fromisoformat(row[0])
|
||||
|
||||
def _cmd_list_active(self):
|
||||
now = datetime.datetime.now(datetime.UTC)
|
||||
|
||||
self.respond(ResponseCode.NNTP_INFORMATION_FOLLOWS)
|
||||
|
||||
for name in self.server.newsgroups:
|
||||
newsgroup = self.server.newsgroups[name]
|
||||
last_active = self._newsgroup_last_active(newsgroup)
|
||||
|
||||
if now - last_active < datetime.timedelta(days=1):
|
||||
self.print_newsgroup(newsgroup)
|
||||
|
||||
return self.end()
|
||||
|
||||
LIST_SUBCOMMANDS = {
|
||||
'NEWSGROUPS': _cmd_list_newsgroups,
|
||||
'ACTIVE': _cmd_list_active,
|
||||
}
|
||||
|
||||
def _cmd_list(self, *args):
|
||||
|
|
Loading…
Add table
Reference in a new issue