Apply voting threshold to timeline

main
Bob Mottram 2020-10-08 20:47:23 +01:00
parent 72b5db2d9e
commit cc642557f4
5 changed files with 124 additions and 42 deletions

View File

@ -5990,7 +5990,9 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInFeed, 'inbox',
authorized)
authorized,
0,
self.server.positiveVoting)
if inboxFeed:
if GETstartTime:
self._benchmarkGETtimings(GETstartTime, GETtimings,
@ -6018,7 +6020,9 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInFeed, 'inbox',
authorized)
authorized,
0,
self.server.positiveVoting)
if GETstartTime:
self._benchmarkGETtimings(GETstartTime,
GETtimings,
@ -6106,7 +6110,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInFeed, 'dm',
authorized)
authorized,
0, self.server.positiveVoting)
if inboxDMFeed:
if self._requestHTTP():
nickname = path.replace('/users/', '')
@ -6130,7 +6135,9 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInFeed, 'dm',
authorized)
authorized,
0,
self.server.positiveVoting)
msg = \
htmlInboxDMs(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6207,7 +6214,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInFeed, 'tlreplies',
True)
True,
0, self.server.positiveVoting)
if not inboxRepliesFeed:
inboxRepliesFeed = []
if self._requestHTTP():
@ -6232,7 +6240,8 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInFeed, 'tlreplies',
True)
True,
0, self.server.positiveVoting)
msg = \
htmlInboxReplies(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6309,7 +6318,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInMediaFeed, 'tlmedia',
True)
True,
0, self.server.positiveVoting)
if not inboxMediaFeed:
inboxMediaFeed = []
if self._requestHTTP():
@ -6334,7 +6344,8 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInMediaFeed, 'tlmedia',
True)
True,
0, self.server.positiveVoting)
msg = \
htmlInboxMedia(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6411,7 +6422,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInBlogsFeed, 'tlblogs',
True)
True,
0, self.server.positiveVoting)
if not inboxBlogsFeed:
inboxBlogsFeed = []
if self._requestHTTP():
@ -6436,7 +6448,8 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInBlogsFeed, 'tlblogs',
True)
True,
0, self.server.positiveVoting)
msg = \
htmlInboxBlogs(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6514,7 +6527,9 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInNewsFeed, 'tlnews',
True)
True,
self.server.newswireVotesThreshold,
self.server.positiveVoting)
if not inboxNewsFeed:
inboxNewsFeed = []
if self._requestHTTP():
@ -6540,7 +6555,9 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInBlogsFeed, 'tlnews',
True)
True,
self.server.newswireVotesThreshold,
self.server.positiveVoting)
currNickname = path.split('/users/')[1]
if '/' in currNickname:
currNickname = currNickname.split('/')[0]
@ -6686,7 +6703,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInFeed, 'tlbookmarks',
authorized)
authorized,
0, self.server.positiveVoting)
if bookmarksFeed:
if self._requestHTTP():
nickname = path.replace('/users/', '')
@ -6712,7 +6730,8 @@ class PubServer(BaseHTTPRequestHandler):
httpPrefix,
maxPostsInFeed,
'tlbookmarks',
authorized)
authorized,
0, self.server.positiveVoting)
msg = \
htmlBookmarks(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6791,7 +6810,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInFeed, 'tlevents',
authorized)
authorized,
0, self.server.positiveVoting)
print('eventsFeed: ' + str(eventsFeed))
if eventsFeed:
if self._requestHTTP():
@ -6817,7 +6837,8 @@ class PubServer(BaseHTTPRequestHandler):
httpPrefix,
maxPostsInFeed,
'tlevents',
authorized)
authorized,
0, self.server.positiveVoting)
msg = \
htmlEvents(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6888,7 +6909,9 @@ class PubServer(BaseHTTPRequestHandler):
port, path,
httpPrefix,
maxPostsInFeed, 'outbox',
authorized)
authorized,
self.server.newswireVotesThreshold,
self.server.positiveVoting)
if outboxFeed:
if self._requestHTTP():
nickname = \
@ -6912,7 +6935,9 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInFeed, 'outbox',
authorized)
authorized,
self.server.newswireVotesThreshold,
self.server.positiveVoting)
msg = \
htmlOutbox(self.server.defaultTimeline,
self.server.recentPostsCache,
@ -6976,7 +7001,8 @@ class PubServer(BaseHTTPRequestHandler):
path,
httpPrefix,
maxPostsInFeed, 'moderation',
True)
True,
0, self.server.positiveVoting)
if moderationFeed:
if self._requestHTTP():
nickname = path.replace('/users/', '')
@ -7000,7 +7026,8 @@ class PubServer(BaseHTTPRequestHandler):
path + '?page=1',
httpPrefix,
maxPostsInFeed, 'moderation',
True)
True,
0, self.server.positiveVoting)
msg = \
htmlModeration(self.server.defaultTimeline,
self.server.recentPostsCache,

View File

@ -595,7 +595,8 @@ def personLookup(domain: str, path: str, baseDir: str) -> {}:
def personBoxJson(recentPostsCache: {},
session, baseDir: str, domain: str, port: int, path: str,
httpPrefix: str, noOfItems: int, boxname: str,
authorized: bool) -> {}:
authorized: bool,
newswireVotesThreshold: int, positiveVoting: bool) -> {}:
"""Obtain the inbox/outbox/moderation feed for the given person
"""
if boxname != 'inbox' and boxname != 'dm' and \
@ -671,6 +672,7 @@ def personBoxJson(recentPostsCache: {},
elif boxname == 'tlnews':
return createNewsTimeline(session, baseDir, nickname, domain, port,
httpPrefix, noOfItems, headerOnly,
newswireVotesThreshold, positiveVoting,
pageNumber)
elif boxname == 'tlblogs':
return createBlogsTimeline(session, baseDir, nickname, domain, port,

View File

@ -46,6 +46,8 @@ from utils import locatePost
from utils import loadJson
from utils import saveJson
from utils import getConfigParam
from utils import locateNewsVotes
from utils import votesOnNewswireItem
from media import attachMedia
from media import replaceYouTube
from content import removeHtml
@ -2477,7 +2479,7 @@ def createInbox(recentPostsCache: {},
session, baseDir, 'inbox',
nickname, domain, port, httpPrefix,
itemsPerPage, headerOnly, True,
pageNumber)
0, False, pageNumber)
def createBookmarksTimeline(session, baseDir: str, nickname: str, domain: str,
@ -2486,7 +2488,7 @@ def createBookmarksTimeline(session, baseDir: str, nickname: str, domain: str,
return createBoxIndexed({}, session, baseDir, 'tlbookmarks',
nickname, domain,
port, httpPrefix, itemsPerPage, headerOnly,
True, pageNumber)
True, 0, False, pageNumber)
def createEventsTimeline(recentPostsCache: {},
@ -2496,7 +2498,7 @@ def createEventsTimeline(recentPostsCache: {},
return createBoxIndexed(recentPostsCache, session, baseDir, 'tlevents',
nickname, domain,
port, httpPrefix, itemsPerPage, headerOnly,
True, pageNumber)
True, 0, False, pageNumber)
def createDMTimeline(recentPostsCache: {},
@ -2506,7 +2508,7 @@ def createDMTimeline(recentPostsCache: {},
return createBoxIndexed(recentPostsCache,
session, baseDir, 'dm', nickname,
domain, port, httpPrefix, itemsPerPage,
headerOnly, True, pageNumber)
headerOnly, True, 0, False, pageNumber)
def createRepliesTimeline(recentPostsCache: {},
@ -2516,7 +2518,7 @@ def createRepliesTimeline(recentPostsCache: {},
return createBoxIndexed(recentPostsCache, session, baseDir, 'tlreplies',
nickname, domain, port, httpPrefix,
itemsPerPage, headerOnly, True,
pageNumber)
0, False, pageNumber)
def createBlogsTimeline(session, baseDir: str, nickname: str, domain: str,
@ -2525,7 +2527,7 @@ def createBlogsTimeline(session, baseDir: str, nickname: str, domain: str,
return createBoxIndexed({}, session, baseDir, 'tlblogs', nickname,
domain, port, httpPrefix,
itemsPerPage, headerOnly, True,
pageNumber)
0, False, pageNumber)
def createMediaTimeline(session, baseDir: str, nickname: str, domain: str,
@ -2534,15 +2536,17 @@ def createMediaTimeline(session, baseDir: str, nickname: str, domain: str,
return createBoxIndexed({}, session, baseDir, 'tlmedia', nickname,
domain, port, httpPrefix,
itemsPerPage, headerOnly, True,
pageNumber)
0, False, pageNumber)
def createNewsTimeline(session, baseDir: str, nickname: str, domain: str,
port: int, httpPrefix: str, itemsPerPage: int,
headerOnly: bool, pageNumber=None) -> {}:
headerOnly: bool, newswireVotesThreshold: int,
positiveVoting: bool, pageNumber=None) -> {}:
return createBoxIndexed({}, session, baseDir, 'outbox', 'news',
domain, port, httpPrefix,
itemsPerPage, headerOnly, True,
newswireVotesThreshold, positiveVoting,
pageNumber)
@ -2553,7 +2557,7 @@ def createOutbox(session, baseDir: str, nickname: str, domain: str,
return createBoxIndexed({}, session, baseDir, 'outbox',
nickname, domain, port, httpPrefix,
itemsPerPage, headerOnly, authorized,
pageNumber)
0, False, pageNumber)
def createModeration(baseDir: str, nickname: str, domain: str, port: int,
@ -2846,6 +2850,7 @@ def createBoxIndexed(recentPostsCache: {},
session, baseDir: str, boxname: str,
nickname: str, domain: str, port: int, httpPrefix: str,
itemsPerPage: int, headerOnly: bool, authorized: bool,
newswireVotesThreshold: int, positiveVoting: bool,
pageNumber=None) -> {}:
"""Constructs the box feed for a person with the given nickname
"""
@ -2915,6 +2920,30 @@ def createBoxIndexed(recentPostsCache: {},
if not postFilename:
break
# apply votes within this timeline
if newswireVotesThreshold > 0:
# if there a votes file for this post?
votesFilename = \
locateNewsVotes(baseDir, domain, postFilename)
if votesFilename:
# load the votes file and count the votes
votesJson = loadJson(votesFilename, 0, 2)
if votesJson:
if not positiveVoting:
if votesOnNewswireItem >= \
newswireVotesThreshold:
# Too many veto votes.
# Continue without incrementing the
# posts counter
continue
else:
if votesOnNewswireItem < \
newswireVotesThreshold:
# Not enough votes.
# Continue without incrementing the
# posts counter
continue
# Skip through any posts previous to the current page
if postsCtr < int((pageNumber - 1) * itemsPerPage):
postsCtr += 1

View File

@ -500,6 +500,39 @@ def followPerson(baseDir: str, nickname: str, domain: str,
return True
def votesOnNewswireItem(status: []) -> int:
"""Returns the number of votes on a newswire item
"""
totalVotes = 0
for line in status:
if 'vote:' in line:
totalVotes += 1
return totalVotes
def locateNewsVotes(baseDir: str, domain: str,
postUrl: str) -> str:
"""Returns the votes filename for a news post
within the news user account
"""
postUrl = \
postUrl.strip().replace('\n', '').replace('\r', '')
# if this post in the shared inbox?
postUrl = removeIdEnding(postUrl.strip()).replace('/', '#')
if postUrl.endswith('.json'):
postUrl = postUrl + '.votes'
else:
postUrl = postUrl + '.json.votes'
accountDir = baseDir + '/accounts/news' + '@' + domain + '/'
postFilename = accountDir + 'outbox/' + postUrl
if os.path.isfile(postFilename):
return postFilename
return None
def locatePost(baseDir: str, nickname: str, domain: str,
postUrl: str, replies=False) -> str:
"""Returns the filename for the given status post url
@ -525,7 +558,7 @@ def locatePost(baseDir: str, nickname: str, domain: str,
# check news posts
accountDir = baseDir + '/accounts/news' + '@' + domain + '/'
postFilename = accountDir + boxName + '/' + postUrl
postFilename = accountDir + 'outbox/' + postUrl
if os.path.isfile(postFilename):
return postFilename

View File

@ -43,6 +43,7 @@ from utils import getCachedPostDirectory
from utils import getCachedPostFilename
from utils import loadJson
from utils import getConfigParam
from utils import votesOnNewswireItem
from follow import isFollowingActor
from webfinger import webfingerHandle
from posts import isDM
@ -2861,7 +2862,7 @@ def htmlProfilePosts(recentPostsCache: {}, maxRecentPosts: int,
str(currPage),
httpPrefix,
10, 'outbox',
authorized)
authorized, 0, False)
if not outboxFeed:
break
if len(outboxFeed['orderedItems']) == 0:
@ -5367,16 +5368,6 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
return htmlStr
def votesOnNewswireItem(status: []) -> int:
"""Returns the number of votes on a newswire item
"""
totalVotes = 0
for line in status:
if 'vote:' in line:
totalVotes += 1
return totalVotes
def votesIndicator(totalVotes: int, positiveVoting: bool) -> str:
"""Returns an indicator of the number of votes on a newswire item
"""