Make NEWGROUPS honor date, time
This commit is contained in:
		
							parent
							
								
									b6225bb329
								
							
						
					
					
						commit
						0d41ea1d2b
					
				
					 2 changed files with 23 additions and 10 deletions
				
			
		|  | @ -3,10 +3,13 @@ import socket | |||
| import ssl | ||||
| import datetime | ||||
| 
 | ||||
| from typing import Optional | ||||
| 
 | ||||
| from nntp.tiny.socket   import Connection | ||||
| from nntp.tiny.host     import Host | ||||
| from nntp.tiny.response import Response, ResponseCode | ||||
| from nntp.tiny.remote   import RemoteNewsgroup | ||||
| from nntp.tiny.message  import MessageRange | ||||
| 
 | ||||
| class ClientException(Exception): | ||||
|     pass | ||||
|  |  | |||
|  | @ -199,19 +199,27 @@ class Session(Connection): | |||
| 
 | ||||
|         return self.respond(ResponseCode.NNTP_ARTICLE_STAT_RESPONSE) | ||||
| 
 | ||||
|     def _newsgroup_summary(self, newsgroup: Newsgroup) -> str: | ||||
|     def _newsgroup_summary(self, newsgroup: Newsgroup, since: Optional[datetime.datetime]=None) -> str: | ||||
|         sql = """ | ||||
|             select | ||||
|                 count(message_id), | ||||
|                 min(message_id), | ||||
|                 max(message_id) | ||||
|                 count(newsgroup_message.message_id), | ||||
|                 min(newsgroup_message.message_id), | ||||
|                 max(newsgroup_message.message_id) | ||||
|             from | ||||
|                 newsgroup_message | ||||
|                 newsgroup_message, | ||||
|                 message | ||||
|             where | ||||
|                 newsgroup_id = ? | ||||
|                 message.id = newsgroup_message.message_id | ||||
|                 and newsgroup_message.newsgroup_id = ? | ||||
|         """ | ||||
| 
 | ||||
|         cr  = self.db.execute(sql, (newsgroup.id,)) | ||||
|         values = [newsgroup.id] | ||||
| 
 | ||||
|         if since is not None: | ||||
|             sql += " and message.created_on >= ?" | ||||
|             values.append(since.isoformat()) | ||||
| 
 | ||||
|         cr  = self.db.execute(sql, values) | ||||
|         row = cr.fetchone() | ||||
| 
 | ||||
|         return { | ||||
|  | @ -269,8 +277,8 @@ class Session(Connection): | |||
| 
 | ||||
|         return self.end() | ||||
| 
 | ||||
|     def print_newsgroup(self, newsgroup: Newsgroup): | ||||
|         summary = self._newsgroup_summary(newsgroup) | ||||
|     def print_newsgroup(self, newsgroup: Newsgroup, since: Optional[datetime.datetime]=None): | ||||
|         summary = self._newsgroup_summary(newsgroup, since) | ||||
| 
 | ||||
|         return self.print("%s %d %d %s" % ( | ||||
|             summary['name'], | ||||
|  | @ -485,13 +493,15 @@ class Session(Connection): | |||
|         elif len(args) > 1: | ||||
|             return self.respond(ResponseCode.NNTP_SYNTAX_ERROR, "Too many arguments") | ||||
| 
 | ||||
|         timestamp = self._parse_date_time(datestr, timestr) | ||||
| 
 | ||||
|         self.respond(ResponseCode.NNTP_GROUPS_NEW_FOLLOW) | ||||
| 
 | ||||
|         for name in self.server.newsgroups: | ||||
|             if fnmatch.fnmatch(name, wildmat): | ||||
|                 newsgroup = self.server.newsgroups[name] | ||||
| 
 | ||||
|                 self.print_newsgroup(newsgroup) | ||||
|                 self.print_newsgroup(newsgroup, timestamp) | ||||
| 
 | ||||
|         return self.end() | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue