Checking that announces contain images

main2
Bob Mottram 2019-09-28 17:21:43 +01:00
parent 0907932a0a
commit 4e3d9e75b4
4 changed files with 53 additions and 39 deletions

View File

@ -1740,7 +1740,8 @@ class PubServer(BaseHTTPRequestHandler):
if self.path.endswith('/inbox') or '/inbox?page=' in self.path:
if '/users/' in self.path:
if authorized:
inboxFeed=personBoxJson(self.server.baseDir, \
inboxFeed=personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path, \
@ -1760,7 +1761,8 @@ class PubServer(BaseHTTPRequestHandler):
pageNumber=1
if 'page=' not in self.path:
# if no page was specified then show the first
inboxFeed=personBoxJson(self.server.baseDir, \
inboxFeed=personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path+'?page=1', \
@ -1808,7 +1810,8 @@ class PubServer(BaseHTTPRequestHandler):
if self.path.endswith('/dm') or '/dm?page=' in self.path:
if '/users/' in self.path:
if authorized:
inboxDMFeed=personBoxJson(self.server.baseDir, \
inboxDMFeed=personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path, \
@ -1828,13 +1831,14 @@ class PubServer(BaseHTTPRequestHandler):
pageNumber=1
if 'page=' not in self.path:
# if no page was specified then show the first
inboxDMFeed=personBoxJson(self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path+'?page=1', \
self.server.httpPrefix, \
maxPostsInFeed, 'dm', \
True,self.server.ocapAlways)
inboxDMFeed=personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path+'?page=1', \
self.server.httpPrefix, \
maxPostsInFeed, 'dm', \
True,self.server.ocapAlways)
msg=htmlInboxDMs(self.server.translate, \
pageNumber,maxPostsInFeed, \
self.server.session, \
@ -1877,7 +1881,8 @@ class PubServer(BaseHTTPRequestHandler):
if '/users/' in self.path:
if authorized:
inboxRepliesFeed= \
personBoxJson(self.server.baseDir, \
personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path, \
@ -1899,7 +1904,8 @@ class PubServer(BaseHTTPRequestHandler):
if 'page=' not in self.path:
# if no page was specified then show the first
inboxRepliesFeed= \
personBoxJson(self.server.baseDir, \
personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path+'?page=1', \
@ -1948,7 +1954,8 @@ class PubServer(BaseHTTPRequestHandler):
if '/users/' in self.path:
if authorized:
inboxMediaFeed= \
personBoxJson(self.server.baseDir, \
personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path, \
@ -1970,7 +1977,8 @@ class PubServer(BaseHTTPRequestHandler):
if 'page=' not in self.path:
# if no page was specified then show the first
inboxMediaFeed= \
personBoxJson(self.server.baseDir, \
personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path+'?page=1', \
@ -2015,7 +2023,8 @@ class PubServer(BaseHTTPRequestHandler):
return
# get outbox feed for a person
outboxFeed=personBoxJson(self.server.baseDir,self.server.domain, \
outboxFeed=personBoxJson(self.server.session, \
self.server.baseDir,self.server.domain, \
self.server.port,self.path, \
self.server.httpPrefix, \
maxPostsInFeed, 'outbox', \
@ -2034,7 +2043,8 @@ class PubServer(BaseHTTPRequestHandler):
pageNumber=1
if 'page=' not in self.path:
# if a page wasn't specified then show the first one
outboxFeed=personBoxJson(self.server.baseDir,self.server.domain, \
outboxFeed=personBoxJson(self.server.session, \
self.server.baseDir,self.server.domain, \
self.server.port,self.path+'?page=1', \
self.server.httpPrefix, \
maxPostsInFeed, 'outbox', \
@ -2070,7 +2080,8 @@ class PubServer(BaseHTTPRequestHandler):
if '/users/' in self.path:
if authorized:
moderationFeed= \
personBoxJson(self.server.baseDir, \
personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path, \
@ -2091,7 +2102,8 @@ class PubServer(BaseHTTPRequestHandler):
if 'page=' not in self.path:
# if no page was specified then show the first
moderationFeed= \
personBoxJson(self.server.baseDir, \
personBoxJson(self.server.session, \
self.server.baseDir, \
self.server.domain, \
self.server.port, \
self.path+'?page=1', \

View File

@ -396,7 +396,7 @@ def personLookup(domain: str,path: str,baseDir: str) -> {}:
return None
return personJson
def personBoxJson(baseDir: str,domain: str,port: int,path: str, \
def personBoxJson(session,baseDir: str,domain: str,port: int,path: str, \
httpPrefix: str,noOfItems: int,boxname: str, \
authorized: bool,ocapAlways: bool) -> []:
"""Obtain the inbox/outbox/moderation feed for the given person
@ -438,19 +438,19 @@ def personBoxJson(baseDir: str,domain: str,port: int,path: str, \
if not validNickname(domain,nickname):
return None
if boxname=='inbox':
return createInbox(baseDir,nickname,domain,port,httpPrefix, \
return createInbox(session,baseDir,nickname,domain,port,httpPrefix, \
noOfItems,headerOnly,ocapAlways,pageNumber)
if boxname=='dm':
return createDMTimeline(baseDir,nickname,domain,port,httpPrefix, \
return createDMTimeline(session,baseDir,nickname,domain,port,httpPrefix, \
noOfItems,headerOnly,ocapAlways,pageNumber)
elif boxname=='tlreplies':
return createRepliesTimeline(baseDir,nickname,domain,port,httpPrefix, \
return createRepliesTimeline(session,baseDir,nickname,domain,port,httpPrefix, \
noOfItems,headerOnly,ocapAlways,pageNumber)
elif boxname=='tlmedia':
return createMediaTimeline(baseDir,nickname,domain,port,httpPrefix, \
return createMediaTimeline(session,baseDir,nickname,domain,port,httpPrefix, \
noOfItems,headerOnly,ocapAlways,pageNumber)
elif boxname=='outbox':
return createOutbox(baseDir,nickname,domain,port,httpPrefix, \
return createOutbox(session,baseDir,nickname,domain,port,httpPrefix, \
noOfItems,headerOnly,authorized,pageNumber)
elif boxname=='moderation':
return createModeration(baseDir,nickname,domain,port,httpPrefix, \

View File

@ -1570,29 +1570,29 @@ def sendToFollowers(session,baseDir: str, \
print('DEBUG: End of sendToFollowers')
def createInbox(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
def createInbox(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,ocapAlways: bool,pageNumber=None) -> {}:
return createBoxBase(baseDir,'inbox',nickname,domain,port,httpPrefix, \
return createBoxBase(session,baseDir,'inbox',nickname,domain,port,httpPrefix, \
itemsPerPage,headerOnly,True,ocapAlways,pageNumber)
def createDMTimeline(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
def createDMTimeline(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,ocapAlways: bool,pageNumber=None) -> {}:
return createBoxBase(baseDir,'dm',nickname,domain,port,httpPrefix, \
return createBoxBase(session,baseDir,'dm',nickname,domain,port,httpPrefix, \
itemsPerPage,headerOnly,True,ocapAlways,pageNumber)
def createRepliesTimeline(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
def createRepliesTimeline(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,ocapAlways: bool,pageNumber=None) -> {}:
return createBoxBase(baseDir,'tlreplies',nickname,domain,port,httpPrefix, \
return createBoxBase(session,baseDir,'tlreplies',nickname,domain,port,httpPrefix, \
itemsPerPage,headerOnly,True,ocapAlways,pageNumber)
def createMediaTimeline(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
def createMediaTimeline(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,ocapAlways: bool,pageNumber=None) -> {}:
return createBoxBase(baseDir,'tlmedia',nickname,domain,port,httpPrefix, \
return createBoxBase(session,baseDir,'tlmedia',nickname,domain,port,httpPrefix, \
itemsPerPage,headerOnly,True,ocapAlways,pageNumber)
def createOutbox(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
def createOutbox(session,baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,authorized: bool,pageNumber=None) -> {}:
return createBoxBase(baseDir,'outbox',nickname,domain,port,httpPrefix, \
return createBoxBase(session,baseDir,'outbox',nickname,domain,port,httpPrefix, \
itemsPerPage,headerOnly,authorized,False,pageNumber)
def createModeration(baseDir: str,nickname: str,domain: str,port: int,httpPrefix: str, \
@ -1689,11 +1689,13 @@ def isDM(postJsonObject: {}) -> bool:
return False
return True
def isImageMedia(postJsonObject: {}) -> bool:
def isImageMedia(session,baseDir: str,httpPrefix: str,nickname: str,domain: str,postJsonObject: {}) -> bool:
"""Returns true if the given post has attached image media
"""
if postJsonObject['type']=='Announce':
return True
postJsonAnnounce=downloadAnnounce(session,baseDir,httpPrefix,nickname,domain,postJsonObject,__version__):
if postJsonAnnounce:
postJsonObject=postJsonAnnounce
if postJsonObject['type']!='Create':
return False
if not postJsonObject.get('object'):
@ -1729,7 +1731,7 @@ def isReply(postJsonObject: {},actor: str) -> bool:
return False
return True
def createBoxBase(baseDir: str,boxname: str, \
def createBoxBase(session,baseDir: str,boxname: str, \
nickname: str,domain: str,port: int,httpPrefix: str, \
itemsPerPage: int,headerOnly: bool,authorized :bool, \
ocapAlways: bool,pageNumber=None) -> {}:
@ -1908,7 +1910,7 @@ def createBoxBase(baseDir: str,boxname: str, \
if isDM(p) or isReply(p,boxActor):
isTimelinePost=True
elif boxname=='tlmedia':
if isImageMedia(p):
if isImageMedia(session,baseDir,httpPrefix,nickname,domain,p):
isTimelinePost=True
if isTimelinePost and currPage == pageNumber:

View File

@ -1064,7 +1064,7 @@ def htmlProfilePosts(translate: {}, \
currPage=1
while ctr<maxItems and currPage<4:
outboxFeed= \
personBoxJson(baseDir,domain, \
personBoxJson(session,baseDir,domain, \
port,'/users/'+nickname+'/outbox?page='+str(currPage), \
httpPrefix, \
10, 'outbox', \