diff --git a/daemon.py b/daemon.py index 1de1cef12..fbee5112d 100644 --- a/daemon.py +++ b/daemon.py @@ -4657,6 +4657,82 @@ class PubServer(BaseHTTPRequestHandler): 'follow approve shown') self.server.GETbusy = False + def _newswireVote(self, callingDomain: str, path: str, + cookie: str, + baseDir: str, httpPrefix: str, + domain: str, domainFull: str, port: int, + onionDomain: str, i2pDomain: str, + GETstartTime, GETtimings: {}, + proxyType: str, debug: bool): + """Vote for a newswire item + """ + originPathStr = path.split('/newswirevote=')[0] + dateStr = path.split('/newswirevote=')[1].replace('T', ' ') + '+00:00' + nickname = originPathStr.split('/users/')[1] + if '/' in nickname: + nickname = nickname.split('/')[0] + if self.newswire.get(dateStr): + if isModerator(baseDir, nickname): + if 'vote:' + nickname not in self.newswire[dateStr][2]: + self.newswire[dateStr][2].append('vote:' + nickname) + filename = self.newswire[dateStr][3] + if filename: + saveJson(self.newswire[dateStr][2], + filename + '.votes') + + originPathStrAbsolute = \ + httpPrefix + '://' + domainFull + originPathStr + if callingDomain.endswith('.onion') and onionDomain: + originPathStrAbsolute = \ + 'http://' + onionDomain + originPathStr + elif (callingDomain.endswith('.i2p') and i2pDomain): + originPathStrAbsolute = \ + 'http://' + i2pDomain + originPathStr + self._redirect_headers(originPathStrAbsolute, + cookie, callingDomain) + self._benchmarkGETtimings(GETstartTime, GETtimings, + 'unannounce done', + 'follow approve shown') + self.server.GETbusy = False + + def _newswireUnvote(self, callingDomain: str, path: str, + cookie: str, + baseDir: str, httpPrefix: str, + domain: str, domainFull: str, port: int, + onionDomain: str, i2pDomain: str, + GETstartTime, GETtimings: {}, + proxyType: str, debug: bool): + """Remove vote for a newswire item + """ + originPathStr = path.split('/newswirevote=')[0] + dateStr = path.split('/newswirevote=')[1].replace('T', ' ') + '+00:00' + nickname = originPathStr.split('/users/')[1] + if '/' in nickname: + nickname = nickname.split('/')[0] + if self.newswire.get(dateStr): + if isModerator(baseDir, nickname): + if 'vote:' + nickname in self.newswire[dateStr][2]: + self.newswire[dateStr][2].remove('vote:' + nickname) + filename = self.newswire[dateStr][3] + if filename: + saveJson(self.newswire[dateStr][2], + filename + '.votes') + + originPathStrAbsolute = \ + httpPrefix + '://' + domainFull + originPathStr + if callingDomain.endswith('.onion') and onionDomain: + originPathStrAbsolute = \ + 'http://' + onionDomain + originPathStr + elif (callingDomain.endswith('.i2p') and i2pDomain): + originPathStrAbsolute = \ + 'http://' + i2pDomain + originPathStr + self._redirect_headers(originPathStrAbsolute, + cookie, callingDomain) + self._benchmarkGETtimings(GETstartTime, GETtimings, + 'unannounce done', + 'follow approve shown') + self.server.GETbusy = False + def _followDenyButton(self, callingDomain: str, path: str, cookie: str, baseDir: str, httpPrefix: str, @@ -8688,21 +8764,55 @@ class PubServer(BaseHTTPRequestHandler): 'show announce done', 'unannounce done') - # send a newswire moderation approval from the web interface - if authorized and '/newswireapprove=' in self.path and \ + # send a newswire moderation vote from the web interface + if authorized and '/newswirevote=' in self.path and \ self.path.startswith('/users/'): - self._moderationApproveButton(callingDomain, self.path, - cookie, - self.server.baseDir, - self.server.httpPrefix, - self.server.domain, - self.server.domainFull, - self.server.port, - self.server.onionDomain, - self.server.i2pDomain, - GETstartTime, GETtimings, - self.server.proxyType, - self.server.debug) + self._newswireVote(callingDomain, self.path, + cookie, + self.server.baseDir, + self.server.httpPrefix, + self.server.domain, + self.server.domainFull, + self.server.port, + self.server.onionDomain, + self.server.i2pDomain, + GETstartTime, GETtimings, + self.server.proxyType, + self.server.debug) + return + + # send a newswire moderation unvote from the web interface + if authorized and '/newswireunvote=' in self.path and \ + self.path.startswith('/users/'): + self._newswireUnvote(callingDomain, self.path, + cookie, + self.server.baseDir, + self.server.httpPrefix, + self.server.domain, + self.server.domainFull, + self.server.port, + self.server.onionDomain, + self.server.i2pDomain, + GETstartTime, GETtimings, + self.server.proxyType, + self.server.debug) + return + + # send a follow request approval from the web interface + if authorized and '/followapprove=' in self.path and \ + self.path.startswith('/users/'): + self._followApproveButton(callingDomain, self.path, + cookie, + self.server.baseDir, + self.server.httpPrefix, + self.server.domain, + self.server.domainFull, + self.server.port, + self.server.onionDomain, + self.server.i2pDomain, + GETstartTime, GETtimings, + self.server.proxyType, + self.server.debug) return self._benchmarkGETtimings(GETstartTime, GETtimings, diff --git a/newswire.py b/newswire.py index 1c1aee157..7b720b69f 100644 --- a/newswire.py +++ b/newswire.py @@ -79,7 +79,7 @@ def xml2StrToDict(xmlStr: str) -> {}: try: publishedDate = \ datetime.strptime(pubDate, "%a, %d %b %Y %H:%M:%S %z") - result[str(publishedDate)] = [title, link, []] + result[str(publishedDate)] = [title, link, [], ''] parsed = True except BaseException: pass @@ -230,9 +230,13 @@ def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str, published = postJsonObject['object']['published'] published = published.replace('T', ' ') published = published.replace('Z', '+00:00') + votes = [] + if os.path.isfile(fullPostFilename + '.votes'): + votes = loadJson(fullPostFilename + '.votes') newswire[published] = \ [postJsonObject['object']['summary'], - postJsonObject['object']['url'], []] + postJsonObject['object']['url'], votes, + fullPostFilename] ctr += 1 if ctr >= maxBlogsPerAccount: diff --git a/webinterface.py b/webinterface.py index 4e57e0127..a235a409c 100644 --- a/webinterface.py +++ b/webinterface.py @@ -5352,7 +5352,7 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool) -> str: # count the total votes for this item totalVotes = 0 for line in item[2]: - if '[vote:' in line: + if 'vote:' in line: totalVotes += 1 if totalVotes > 0: totalVotesStr = ' +' + str(totalVotes) @@ -5376,7 +5376,7 @@ def htmlNewswire(newswire: str, nickname: str, moderator: bool) -> str: # count the total votes for this item totalVotes = 0 for line in item[2]: - if '[vote:' in line: + if 'vote:' in line: totalVotes += 1 if totalVotes > 0: totalVotesStr = ' +' + str(totalVotes)