Implement LAST, NEXT commands
This commit is contained in:
		
							parent
							
								
									ee1adcf1ac
								
							
						
					
					
						commit
						97078ffede
					
				
					 1 changed files with 56 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -191,6 +191,60 @@ class Session():
 | 
			
		|||
 | 
			
		||||
        return self.respond(ResponseCode.NNTP_GROUP_LISTING, text)
 | 
			
		||||
 | 
			
		||||
    def _cmd_last(self):
 | 
			
		||||
        if self.newsgroup is None:
 | 
			
		||||
            return self.respond(ResponseCode.NNTP_NEWSGROUP_NOT_SELECTED)
 | 
			
		||||
 | 
			
		||||
        if self.article_id is None:
 | 
			
		||||
            return self.respond(ResponseCode.NNTP_ARTICLE_INVALID_NUMBER)
 | 
			
		||||
 | 
			
		||||
        sql = """
 | 
			
		||||
            select
 | 
			
		||||
                max(id)
 | 
			
		||||
            from
 | 
			
		||||
                newsgroup_message
 | 
			
		||||
            where
 | 
			
		||||
                newsgroup_id = ?
 | 
			
		||||
                and id < ?
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        cr  = self.db.execute(sql, (self.newsgroup.id, self.article_id))
 | 
			
		||||
        row = cr.fetchone()
 | 
			
		||||
 | 
			
		||||
        if row is None or row[0] is None:
 | 
			
		||||
            return self.respond(ResponseCode.NNTP_ARTICLE_NO_PREVIOUS)
 | 
			
		||||
 | 
			
		||||
        self.article_id = row[0]
 | 
			
		||||
 | 
			
		||||
        return self.respond(ResponseCode.NNTP_ARTICLE_STAT_RESPONSE)
 | 
			
		||||
 | 
			
		||||
    def _cmd_next(self):
 | 
			
		||||
        if self.newsgroup is None:
 | 
			
		||||
            return self.respond(ResponseCode.NNTP_NEWSGROUP_NOT_SELECTED)
 | 
			
		||||
 | 
			
		||||
        if self.article_id is None:
 | 
			
		||||
            return self.respond(ResponseCode.NNTP_ARTICLE_INVALID_NUMBER)
 | 
			
		||||
 | 
			
		||||
        sql = """
 | 
			
		||||
            select
 | 
			
		||||
                min(id)
 | 
			
		||||
            from
 | 
			
		||||
                newsgroup_message
 | 
			
		||||
            where
 | 
			
		||||
                newsgroup_id = ?
 | 
			
		||||
                and id > ?
 | 
			
		||||
        """
 | 
			
		||||
 | 
			
		||||
        cr  = self.db.execute(sql, (self.newsgroup.id, self.article_id))
 | 
			
		||||
        row = cr.fetchone()
 | 
			
		||||
 | 
			
		||||
        if row is None or row[0] is None:
 | 
			
		||||
            return self.respond(ResponseCode.NNTP_ARTICLE_NO_NEXT)
 | 
			
		||||
 | 
			
		||||
        self.article_id = row[0]
 | 
			
		||||
 | 
			
		||||
        return self.respond(ResponseCode.NNTP_ARTICLE_STAT_RESPONSE)
 | 
			
		||||
 | 
			
		||||
    def _newsgroup_summary(self, newsgroup: Newsgroup) -> str:
 | 
			
		||||
        sql = """
 | 
			
		||||
            select
 | 
			
		||||
| 
						 | 
				
			
			@ -587,6 +641,8 @@ class Session():
 | 
			
		|||
        'CAPABILITIES': _cmd_capabilities,
 | 
			
		||||
        'MODE':         _cmd_mode,
 | 
			
		||||
        'GROUP':        _cmd_group,
 | 
			
		||||
        'LAST':         _cmd_last,
 | 
			
		||||
        'NEXT':         _cmd_next,
 | 
			
		||||
        'LISTGROUP':    _cmd_listgroup,
 | 
			
		||||
        'LIST':         _cmd_list,
 | 
			
		||||
        'NEWNEWS':      _cmd_newnews,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue