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

View File

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

View File

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

View File

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