Support language within contentMap

merge-requests/30/head
Bob Mottram 2021-07-18 10:55:49 +01:00
parent eb567ec92d
commit f5cbc7f8ee
8 changed files with 110 additions and 73 deletions

View File

@ -421,7 +421,8 @@ class PubServer(BaseHTTPRequestHandler):
schedulePost, schedulePost,
eventDate, eventDate,
eventTime, eventTime,
location, False) location, False,
self.server.systemLanguage)
if messageJson: if messageJson:
# name field contains the answer # name field contains the answer
messageJson['object']['name'] = answer messageJson['object']['name'] = answer
@ -13085,7 +13086,8 @@ class PubServer(BaseHTTPRequestHandler):
fields['replyTo'], fields['replyTo'], fields['replyTo'], fields['replyTo'],
fields['subject'], fields['schedulePost'], fields['subject'], fields['schedulePost'],
fields['eventDate'], fields['eventTime'], fields['eventDate'], fields['eventTime'],
fields['location'], False) fields['location'], False,
self.server.systemLanguage)
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -13157,7 +13159,8 @@ class PubServer(BaseHTTPRequestHandler):
fields['schedulePost'], fields['schedulePost'],
fields['eventDate'], fields['eventDate'],
fields['eventTime'], fields['eventTime'],
fields['location']) fields['location'],
self.server.systemLanguage)
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -13284,7 +13287,8 @@ class PubServer(BaseHTTPRequestHandler):
fields['schedulePost'], fields['schedulePost'],
fields['eventDate'], fields['eventDate'],
fields['eventTime'], fields['eventTime'],
fields['location']) fields['location'],
self.server.systemLanguage)
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -13325,7 +13329,8 @@ class PubServer(BaseHTTPRequestHandler):
fields['schedulePost'], fields['schedulePost'],
fields['eventDate'], fields['eventDate'],
fields['eventTime'], fields['eventTime'],
fields['location']) fields['location'],
self.server.systemLanguage)
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -13370,7 +13375,8 @@ class PubServer(BaseHTTPRequestHandler):
True, fields['schedulePost'], True, fields['schedulePost'],
fields['eventDate'], fields['eventDate'],
fields['eventTime'], fields['eventTime'],
fields['location']) fields['location'],
self.server.systemLanguage)
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -13417,7 +13423,8 @@ class PubServer(BaseHTTPRequestHandler):
True, fields['schedulePost'], True, fields['schedulePost'],
fields['eventDate'], fields['eventDate'],
fields['eventTime'], fields['eventTime'],
fields['location']) fields['location'],
self.server.systemLanguage)
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -13449,7 +13456,8 @@ class PubServer(BaseHTTPRequestHandler):
filename, attachmentMediaType, filename, attachmentMediaType,
fields['imageDescription'], fields['imageDescription'],
city, city,
self.server.debug, fields['subject']) self.server.debug, fields['subject'],
self.server.systemLanguage)
if messageJson: if messageJson:
if self._postToOutbox(messageJson, __version__, nickname): if self._postToOutbox(messageJson, __version__, nickname):
return 1 return 1
@ -13472,6 +13480,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.baseDir, self.server.baseDir,
nickname, nickname,
self.server.domain) self.server.domain)
intDuration = int(fields['duration'])
messageJson = \ messageJson = \
createQuestionPost(self.server.baseDir, createQuestionPost(self.server.baseDir,
nickname, nickname,
@ -13485,7 +13494,8 @@ class PubServer(BaseHTTPRequestHandler):
fields['imageDescription'], fields['imageDescription'],
city, city,
fields['subject'], fields['subject'],
int(fields['duration'])) intDuration,
self.server.systemLanguage)
if messageJson: if messageJson:
if self.server.debug: if self.server.debug:
print('DEBUG: new Question') print('DEBUG: new Question')
@ -15013,7 +15023,8 @@ def runDaemon(userAgentsBlocked: [],
httpd.allowLocalNetworkAccess, httpd.allowLocalNetworkAccess,
httpd.peertubeInstances, httpd.peertubeInstances,
verifyAllSignatures, verifyAllSignatures,
httpd.themeName), daemon=True) httpd.themeName,
httpd.systemLanguage), daemon=True)
print('Creating scheduled post thread') print('Creating scheduled post thread')
httpd.thrPostSchedule = \ httpd.thrPostSchedule = \

View File

@ -468,7 +468,8 @@ def _desktopReplyToPost(session, postId: str,
commentsEnabled, attach, mediaType, commentsEnabled, attach, mediaType,
attachedImageDescription, city, attachedImageDescription, city,
cachedWebfingers, personCache, isArticle, cachedWebfingers, personCache, isArticle,
debug, postId, postId, subject) == 0: systemLanguage, debug, postId, postId,
subject) == 0:
sayStr = 'Reply sent' sayStr = 'Reply sent'
else: else:
sayStr = 'Reply failed' sayStr = 'Reply failed'
@ -529,7 +530,8 @@ def _desktopNewPost(session,
commentsEnabled, attach, mediaType, commentsEnabled, attach, mediaType,
attachedImageDescription, city, attachedImageDescription, city,
cachedWebfingers, personCache, isArticle, cachedWebfingers, personCache, isArticle,
debug, None, None, subject) == 0: systemLanguage, debug, None, None,
subject) == 0:
sayStr = 'Post sent' sayStr = 'Post sent'
else: else:
sayStr = 'Post failed' sayStr = 'Post failed'
@ -1217,7 +1219,8 @@ def _desktopNewDMbase(session, toHandle: str,
commentsEnabled, attach, mediaType, commentsEnabled, attach, mediaType,
attachedImageDescription, city, attachedImageDescription, city,
cachedWebfingers, personCache, isArticle, cachedWebfingers, personCache, isArticle,
debug, None, None, subject) == 0: systemLanguage, debug, None, None,
subject) == 0:
sayStr = 'Direct message sent' sayStr = 'Direct message sent'
else: else:
sayStr = 'Direct message failed' sayStr = 'Direct message failed'

View File

@ -892,6 +892,8 @@ if not args.language:
languageCode = getConfigParam(baseDir, 'language') languageCode = getConfigParam(baseDir, 'language')
if languageCode: if languageCode:
args.language = languageCode args.language = languageCode
else:
args.language = 'en'
# maximum number of new registrations # maximum number of new registrations
if not args.maxRegistrations: if not args.maxRegistrations:
@ -1124,7 +1126,8 @@ if args.message:
args.commentsEnabled, attach, mediaType, args.commentsEnabled, attach, mediaType,
attachedImageDescription, city, attachedImageDescription, city,
cachedWebfingers, personCache, isArticle, cachedWebfingers, personCache, isArticle,
args.debug, replyTo, replyTo, subject) args.language, args.debug,
replyTo, replyTo, subject)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -2245,6 +2248,7 @@ if args.unfilterStr:
sys.exit() sys.exit()
if args.testdata: if args.testdata:
args.language = 'en'
city = 'London, England' city = 'London, England'
nickname = 'testuser567' nickname = 'testuser567'
password = 'boringpassword' password = 'boringpassword'
@ -2334,7 +2338,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"Zoiks!!!", "Zoiks!!!",
testFollowersOnly, testFollowersOnly,
@ -2346,7 +2350,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"Hey scoob we need like a hundred more #milkshakes", "Hey scoob we need like a hundred more #milkshakes",
testFollowersOnly, testFollowersOnly,
@ -2358,7 +2362,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"Getting kinda spooky around here", "Getting kinda spooky around here",
testFollowersOnly, testFollowersOnly,
@ -2370,7 +2374,7 @@ if args.testdata:
'someone', testInReplyToAtomUri, 'someone', testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"And they would have gotten away with it too" + "And they would have gotten away with it too" +
"if it wasn't for those pesky hackers", "if it wasn't for those pesky hackers",
@ -2383,7 +2387,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"man these centralized sites are like the worst!", "man these centralized sites are like the worst!",
testFollowersOnly, testFollowersOnly,
@ -2395,7 +2399,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"another mystery solved #test", "another mystery solved #test",
testFollowersOnly, testFollowersOnly,
@ -2407,7 +2411,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
createPublicPost(baseDir, nickname, domain, port, httpPrefix, createPublicPost(baseDir, nickname, domain, port, httpPrefix,
"let's go bowling", "let's go bowling",
testFollowersOnly, testFollowersOnly,
@ -2419,7 +2423,7 @@ if args.testdata:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, args.language)
domainFull = domain + ':' + str(port) domainFull = domain + ':' + str(port)
clearFollows(baseDir, nickname, domain) clearFollows(baseDir, nickname, domain)
followPerson(baseDir, nickname, domain, 'maxboardroom', domainFull, followPerson(baseDir, nickname, domain, 'maxboardroom', domainFull,

View File

@ -13,6 +13,7 @@ import os
def _dirAcct(baseDir: str, nickname: str, domain: str) -> str: def _dirAcct(baseDir: str, nickname: str, domain: str) -> str:
return baseDir + '/accounts/' + nickname + '@' + domain return baseDir + '/accounts/' + nickname + '@' + domain
def _portDomainRemove(domain: str) -> str: def _portDomainRemove(domain: str) -> str:
"""If the domain has a port appended then remove it """If the domain has a port appended then remove it
eg. mydomain.com:80 becomes mydomain.com eg. mydomain.com:80 becomes mydomain.com

View File

@ -2107,7 +2107,7 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
sendThreads: [], postLog: [], sendThreads: [], postLog: [],
cachedWebfingers: {}, personCache: {}, cachedWebfingers: {}, personCache: {},
translate: {}, debug: bool, translate: {}, debug: bool,
lastBounceMessage: []) -> bool: lastBounceMessage: [], systemLanguage: str) -> bool:
"""Sends a bounce message back to the sending handle """Sends a bounce message back to the sending handle
if a DM has been rejected if a DM has been rejected
""" """
@ -2159,7 +2159,8 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str,
imageDescription, city, imageDescription, city,
inReplyTo, inReplyToAtomUri, inReplyTo, inReplyToAtomUri,
subject, debug, schedulePost, subject, debug, schedulePost,
eventDate, eventTime, location) eventDate, eventTime, location,
systemLanguage)
if not postJsonObject: if not postJsonObject:
print('WARN: unable to create bounce message to ' + sendingHandle) print('WARN: unable to create bounce message to ' + sendingHandle)
return False return False
@ -2183,7 +2184,7 @@ def _isValidDM(baseDir: str, nickname: str, domain: str, port: int,
personCache: {}, personCache: {},
translate: {}, debug: bool, translate: {}, debug: bool,
lastBounceMessage: [], lastBounceMessage: [],
handle: str) -> bool: handle: str, systemLanguage: str) -> bool:
"""Is the given message a valid DM? """Is the given message a valid DM?
""" """
if nickname == 'inbox': if nickname == 'inbox':
@ -2258,7 +2259,8 @@ def _isValidDM(baseDir: str, nickname: str, domain: str, port: int,
cachedWebfingers, cachedWebfingers,
personCache, personCache,
translate, debug, translate, debug,
lastBounceMessage) lastBounceMessage,
systemLanguage)
return False return False
# dm index will be updated # dm index will be updated
@ -2284,7 +2286,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
allowLocalNetworkAccess: bool, allowLocalNetworkAccess: bool,
peertubeInstances: [], peertubeInstances: [],
lastBounceMessage: [], lastBounceMessage: [],
themeName: str) -> bool: themeName: str, systemLanguage: str) -> bool:
""" Anything which needs to be done after initial checks have passed """ Anything which needs to be done after initial checks have passed
""" """
actor = keyId actor = keyId
@ -2488,7 +2490,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int,
personCache, personCache,
translate, debug, translate, debug,
lastBounceMessage, lastBounceMessage,
handle): handle, systemLanguage):
return False return False
# get the actor being replied to # get the actor being replied to
@ -2850,7 +2852,7 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
maxFollowers: int, allowLocalNetworkAccess: bool, maxFollowers: int, allowLocalNetworkAccess: bool,
peertubeInstances: [], peertubeInstances: [],
verifyAllSignatures: bool, verifyAllSignatures: bool,
themeName: str) -> None: themeName: str, systemLanguage: str) -> None:
"""Processes received items and moves them to the appropriate """Processes received items and moves them to the appropriate
directories directories
""" """
@ -3255,7 +3257,7 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int,
allowLocalNetworkAccess, allowLocalNetworkAccess,
peertubeInstances, peertubeInstances,
lastBounceMessage, lastBounceMessage,
themeName) themeName, systemLanguage)
if debug: if debug:
pprint(queueJson['post']) pprint(queueJson['post'])
print('Queue: Queue post accepted') print('Queue: Queue post accepted')

View File

@ -516,7 +516,8 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str,
federationList: [], federationList: [],
sendThreads: [], postLog: [], sendThreads: [], postLog: [],
maxMirroredArticles: int, maxMirroredArticles: int,
allowLocalNetworkAccess: bool) -> None: allowLocalNetworkAccess: bool,
systemLanguage: str) -> None:
"""Converts rss items in a newswire into posts """Converts rss items in a newswire into posts
""" """
if not newswire: if not newswire:
@ -596,7 +597,7 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str,
followersOnly, saveToFile, followersOnly, saveToFile,
attachImageFilename, mediaType, attachImageFilename, mediaType,
imageDescription, city, imageDescription, city,
rssTitle) rssTitle, systemLanguage)
if not blog: if not blog:
continue continue
@ -773,7 +774,8 @@ def runNewswireDaemon(baseDir: str, httpd,
httpd.sendThreads, httpd.sendThreads,
httpd.postLog, httpd.postLog,
httpd.maxMirroredArticles, httpd.maxMirroredArticles,
httpd.allowLocalNetworkAccess) httpd.allowLocalNetworkAccess,
httpd.systemLanguage)
print('Newswire feed converted to ActivityPub') print('Newswire feed converted to ActivityPub')
if httpd.maxNewsPosts > 0: if httpd.maxNewsPosts > 0:

View File

@ -838,7 +838,7 @@ def _createPostS2S(baseDir: str, nickname: str, domain: str, port: int,
tags: [], attachImageFilename: str, tags: [], attachImageFilename: str,
mediaType: str, imageDescription: str, city: str, mediaType: str, imageDescription: str, city: str,
postObjectType: str, summary: str, postObjectType: str, summary: str,
inReplyToAtomUri: str) -> {}: inReplyToAtomUri: str, systemLanguage: str) -> {}:
"""Creates a new server-to-server post """Creates a new server-to-server post
""" """
actorUrl = httpPrefix + '://' + domain + '/users/' + nickname actorUrl = httpPrefix + '://' + domain + '/users/' + nickname
@ -875,7 +875,7 @@ def _createPostS2S(baseDir: str, nickname: str, domain: str, port: int,
'mediaType': 'text/html', 'mediaType': 'text/html',
'content': content, 'content': content,
'contentMap': { 'contentMap': {
'en': content systemLanguage: content
}, },
'attachment': [], 'attachment': [],
'tag': tags, 'tag': tags,
@ -906,7 +906,7 @@ def _createPostC2S(baseDir: str, nickname: str, domain: str, port: int,
tags: [], attachImageFilename: str, tags: [], attachImageFilename: str,
mediaType: str, imageDescription: str, city: str, mediaType: str, imageDescription: str, city: str,
postObjectType: str, summary: str, postObjectType: str, summary: str,
inReplyToAtomUri: str) -> {}: inReplyToAtomUri: str, systemLanguage: str) -> {}:
"""Creates a new client-to-server post """Creates a new client-to-server post
""" """
idStr = \ idStr = \
@ -933,7 +933,7 @@ def _createPostC2S(baseDir: str, nickname: str, domain: str, port: int,
'mediaType': 'text/html', 'mediaType': 'text/html',
'content': content, 'content': content,
'contentMap': { 'contentMap': {
'en': content systemLanguage: content
}, },
'attachment': [], 'attachment': [],
'tag': tags, 'tag': tags,
@ -1075,7 +1075,8 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int,
maximumAttendeeCapacity: int, maximumAttendeeCapacity: int,
repliesModerationOption: str, repliesModerationOption: str,
anonymousParticipationEnabled: bool, anonymousParticipationEnabled: bool,
eventStatus: str, ticketUrl: str) -> {}: eventStatus: str, ticketUrl: str,
systemLanguage: str) -> {}:
"""Creates a message """Creates a message
""" """
content = removeInvalidChars(content) content = removeInvalidChars(content)
@ -1206,7 +1207,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int,
tags, attachImageFilename, tags, attachImageFilename,
mediaType, imageDescription, city, mediaType, imageDescription, city,
postObjectType, summary, postObjectType, summary,
inReplyToAtomUri) inReplyToAtomUri, systemLanguage)
else: else:
newPost = \ newPost = \
_createPostC2S(baseDir, nickname, domain, port, _createPostC2S(baseDir, nickname, domain, port,
@ -1217,7 +1218,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int,
tags, attachImageFilename, tags, attachImageFilename,
mediaType, imageDescription, city, mediaType, imageDescription, city,
postObjectType, summary, postObjectType, summary,
inReplyToAtomUri) inReplyToAtomUri, systemLanguage)
_createPostMentions(ccUrl, newPost, toRecipients, tags) _createPostMentions(ccUrl, newPost, toRecipients, tags)
@ -1424,7 +1425,8 @@ def createPublicPost(baseDir: str,
schedulePost: bool, schedulePost: bool,
eventDate: str, eventTime: str, eventDate: str, eventTime: str,
location: str, location: str,
isArticle: bool) -> {}: isArticle: bool,
systemLanguage: str) -> {}:
"""Public post """Public post
""" """
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
@ -1454,7 +1456,7 @@ def createPublicPost(baseDir: str,
maximumAttendeeCapacity, maximumAttendeeCapacity,
repliesModerationOption, repliesModerationOption,
anonymousParticipationEnabled, anonymousParticipationEnabled,
eventStatus, ticketUrl) eventStatus, ticketUrl, systemLanguage)
def _appendCitationsToBlogPost(baseDir: str, def _appendCitationsToBlogPost(baseDir: str,
@ -1496,7 +1498,7 @@ def createBlogPost(baseDir: str,
inReplyTo: str, inReplyToAtomUri: str, inReplyTo: str, inReplyToAtomUri: str,
subject: str, schedulePost: bool, subject: str, schedulePost: bool,
eventDate: str, eventTime: str, eventDate: str, eventTime: str,
location: str) -> {}: location: str, systemLanguage: str) -> {}:
blogJson = \ blogJson = \
createPublicPost(baseDir, createPublicPost(baseDir,
nickname, domain, port, httpPrefix, nickname, domain, port, httpPrefix,
@ -1506,7 +1508,8 @@ def createBlogPost(baseDir: str,
imageDescription, city, imageDescription, city,
inReplyTo, inReplyToAtomUri, subject, inReplyTo, inReplyToAtomUri, subject,
schedulePost, schedulePost,
eventDate, eventTime, location, True) eventDate, eventTime, location,
True, systemLanguage)
blogJson['object']['url'] = \ blogJson['object']['url'] = \
blogJson['object']['url'].replace('/@', '/users/') blogJson['object']['url'].replace('/@', '/users/')
_appendCitationsToBlogPost(baseDir, nickname, domain, blogJson) _appendCitationsToBlogPost(baseDir, nickname, domain, blogJson)
@ -1519,7 +1522,7 @@ def createNewsPost(baseDir: str,
content: str, followersOnly: bool, saveToFile: bool, content: str, followersOnly: bool, saveToFile: bool,
attachImageFilename: str, mediaType: str, attachImageFilename: str, mediaType: str,
imageDescription: str, city: str, imageDescription: str, city: str,
subject: str) -> {}: subject: str, systemLanguage: str) -> {}:
clientToServer = False clientToServer = False
inReplyTo = None inReplyTo = None
inReplyToAtomUri = None inReplyToAtomUri = None
@ -1536,7 +1539,8 @@ def createNewsPost(baseDir: str,
imageDescription, city, imageDescription, city,
inReplyTo, inReplyToAtomUri, subject, inReplyTo, inReplyToAtomUri, subject,
schedulePost, schedulePost,
eventDate, eventTime, location, True) eventDate, eventTime, location,
True, systemLanguage)
blog['object']['type'] = 'Article' blog['object']['type'] = 'Article'
return blog return blog
@ -1548,7 +1552,8 @@ def createQuestionPost(baseDir: str,
clientToServer: bool, commentsEnabled: bool, clientToServer: bool, commentsEnabled: bool,
attachImageFilename: str, mediaType: str, attachImageFilename: str, mediaType: str,
imageDescription: str, city: str, imageDescription: str, city: str,
subject: str, durationDays: int) -> {}: subject: str, durationDays: int,
systemLanguage: str) -> {}:
"""Question post with multiple choice options """Question post with multiple choice options
""" """
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
@ -1564,7 +1569,7 @@ def createQuestionPost(baseDir: str,
False, False, None, None, subject, False, False, None, None, subject,
False, None, None, None, None, None, False, None, None, None, None, None,
None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
messageJson['object']['type'] = 'Question' messageJson['object']['type'] = 'Question'
messageJson['object']['oneOf'] = [] messageJson['object']['oneOf'] = []
messageJson['object']['votersCount'] = 0 messageJson['object']['votersCount'] = 0
@ -1595,7 +1600,7 @@ def createUnlistedPost(baseDir: str,
inReplyTo: str, inReplyToAtomUri: str, inReplyTo: str, inReplyToAtomUri: str,
subject: str, schedulePost: bool, subject: str, schedulePost: bool,
eventDate: str, eventTime: str, eventDate: str, eventTime: str,
location: str) -> {}: location: str, systemLanguage: str) -> {}:
"""Unlisted post. This has the #Public and followers links inverted. """Unlisted post. This has the #Public and followers links inverted.
""" """
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
@ -1611,7 +1616,7 @@ def createUnlistedPost(baseDir: str,
inReplyTo, inReplyToAtomUri, subject, inReplyTo, inReplyToAtomUri, subject,
schedulePost, eventDate, eventTime, location, schedulePost, eventDate, eventTime, location,
None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
def createFollowersOnlyPost(baseDir: str, def createFollowersOnlyPost(baseDir: str,
@ -1626,7 +1631,7 @@ def createFollowersOnlyPost(baseDir: str,
inReplyToAtomUri: str, inReplyToAtomUri: str,
subject: str, schedulePost: bool, subject: str, schedulePost: bool,
eventDate: str, eventTime: str, eventDate: str, eventTime: str,
location: str) -> {}: location: str, systemLanguage: str) -> {}:
"""Followers only post """Followers only post
""" """
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
@ -1642,7 +1647,7 @@ def createFollowersOnlyPost(baseDir: str,
inReplyTo, inReplyToAtomUri, subject, inReplyTo, inReplyToAtomUri, subject,
schedulePost, eventDate, eventTime, location, schedulePost, eventDate, eventTime, location,
None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
def getMentionedPeople(baseDir: str, httpPrefix: str, def getMentionedPeople(baseDir: str, httpPrefix: str,
@ -1694,7 +1699,7 @@ def createDirectMessagePost(baseDir: str,
subject: str, debug: bool, subject: str, debug: bool,
schedulePost: bool, schedulePost: bool,
eventDate: str, eventTime: str, eventDate: str, eventTime: str,
location: str) -> {}: location: str, systemLanguage: str) -> {}:
"""Direct Message post """Direct Message post
""" """
content = resolvePetnames(baseDir, nickname, domain, content) content = resolvePetnames(baseDir, nickname, domain, content)
@ -1717,7 +1722,7 @@ def createDirectMessagePost(baseDir: str,
inReplyTo, inReplyToAtomUri, subject, inReplyTo, inReplyToAtomUri, subject,
schedulePost, eventDate, eventTime, location, schedulePost, eventDate, eventTime, location,
None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
# mentioned recipients go into To rather than Cc # mentioned recipients go into To rather than Cc
messageJson['to'] = messageJson['object']['cc'] messageJson['to'] = messageJson['object']['cc']
messageJson['object']['to'] = messageJson['to'] messageJson['object']['to'] = messageJson['to']
@ -1735,7 +1740,7 @@ def createReportPost(baseDir: str,
clientToServer: bool, commentsEnabled: bool, clientToServer: bool, commentsEnabled: bool,
attachImageFilename: str, mediaType: str, attachImageFilename: str, mediaType: str,
imageDescription: str, city: str, imageDescription: str, city: str,
debug: bool, subject: str = None) -> {}: debug: bool, subject: str, systemLanguage: str) -> {}:
"""Send a report to moderators """Send a report to moderators
""" """
domainFull = getFullDomain(domain, port) domainFull = getFullDomain(domain, port)
@ -1807,7 +1812,7 @@ def createReportPost(baseDir: str,
True, False, None, None, subject, True, False, None, None, subject,
False, None, None, None, None, None, False, None, None, None, None, None,
None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
if not postJsonObject: if not postJsonObject:
continue continue
@ -1891,7 +1896,7 @@ def sendPost(projectVersion: str,
imageDescription: str, city: str, imageDescription: str, city: str,
federationList: [], sendThreads: [], postLog: [], federationList: [], sendThreads: [], postLog: [],
cachedWebfingers: {}, personCache: {}, cachedWebfingers: {}, personCache: {},
isArticle: bool, isArticle: bool, systemLanguage: str,
debug: bool = False, inReplyTo: str = None, debug: bool = False, inReplyTo: str = None,
inReplyToAtomUri: str = None, subject: str = None) -> int: inReplyToAtomUri: str = None, subject: str = None) -> int:
"""Post to another inbox """Post to another inbox
@ -1952,7 +1957,7 @@ def sendPost(projectVersion: str,
inReplyToAtomUri, subject, inReplyToAtomUri, subject,
False, None, None, None, None, None, False, None, None, None, None, None,
None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
# get the senders private key # get the senders private key
privateKeyPem = _getPersonKey(nickname, domain, baseDir, 'private') privateKeyPem = _getPersonKey(nickname, domain, baseDir, 'private')
@ -2011,7 +2016,8 @@ def sendPostViaServer(projectVersion: str,
attachImageFilename: str, mediaType: str, attachImageFilename: str, mediaType: str,
imageDescription: str, city: str, imageDescription: str, city: str,
cachedWebfingers: {}, personCache: {}, cachedWebfingers: {}, personCache: {},
isArticle: bool, debug: bool = False, isArticle: bool, systemLanguage: str,
debug: bool = False,
inReplyTo: str = None, inReplyTo: str = None,
inReplyToAtomUri: str = None, inReplyToAtomUri: str = None,
subject: str = None) -> int: subject: str = None) -> int:
@ -2093,7 +2099,7 @@ def sendPostViaServer(projectVersion: str,
inReplyToAtomUri, subject, inReplyToAtomUri, subject,
False, None, None, None, None, None, False, None, None, None, None, None,
None, None, None, None, None, None,
None, None, None, None, None) None, None, None, None, None, systemLanguage)
authHeader = createBasicAuthHeader(fromNickname, password) authHeader = createBasicAuthHeader(fromNickname, password)

View File

@ -452,6 +452,7 @@ def createServerAlice(path: str, domain: str, port: int,
shutil.rmtree(path) shutil.rmtree(path)
os.mkdir(path) os.mkdir(path)
os.chdir(path) os.chdir(path)
systemLanguage = 'en'
nickname = 'alice' nickname = 'alice'
httpPrefix = 'http' httpPrefix = 'http'
proxyType = None proxyType = None
@ -501,7 +502,7 @@ def createServerAlice(path: str, domain: str, port: int,
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
createPublicPost(path, nickname, domain, port, httpPrefix, createPublicPost(path, nickname, domain, port, httpPrefix,
"Curiouser and curiouser!", "Curiouser and curiouser!",
testFollowersOnly, testFollowersOnly,
@ -514,7 +515,7 @@ def createServerAlice(path: str, domain: str, port: int,
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
createPublicPost(path, nickname, domain, port, httpPrefix, createPublicPost(path, nickname, domain, port, httpPrefix,
"In the gardens of memory, in the palace " + "In the gardens of memory, in the palace " +
"of dreams, that is where you and I shall meet", "of dreams, that is where you and I shall meet",
@ -528,7 +529,7 @@ def createServerAlice(path: str, domain: str, port: int,
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
global testServerAliceRunning global testServerAliceRunning
testServerAliceRunning = True testServerAliceRunning = True
maxMentions = 10 maxMentions = 10
@ -579,6 +580,7 @@ def createServerBob(path: str, domain: str, port: int,
shutil.rmtree(path) shutil.rmtree(path)
os.mkdir(path) os.mkdir(path)
os.chdir(path) os.chdir(path)
systemLanguage = 'en'
nickname = 'bob' nickname = 'bob'
httpPrefix = 'http' httpPrefix = 'http'
proxyType = None proxyType = None
@ -626,7 +628,7 @@ def createServerBob(path: str, domain: str, port: int,
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
createPublicPost(path, nickname, domain, port, httpPrefix, createPublicPost(path, nickname, domain, port, httpPrefix,
"One of the things I've realised is that " + "One of the things I've realised is that " +
"I am very simple", "I am very simple",
@ -640,7 +642,7 @@ def createServerBob(path: str, domain: str, port: int,
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
createPublicPost(path, nickname, domain, port, httpPrefix, createPublicPost(path, nickname, domain, port, httpPrefix,
"Quantum physics is a bit of a passion of mine", "Quantum physics is a bit of a passion of mine",
testFollowersOnly, testFollowersOnly,
@ -653,7 +655,7 @@ def createServerBob(path: str, domain: str, port: int,
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
global testServerBobRunning global testServerBobRunning
testServerBobRunning = True testServerBobRunning = True
maxMentions = 10 maxMentions = 10
@ -761,6 +763,7 @@ def testPostMessageBetweenServers():
testServerAliceRunning = False testServerAliceRunning = False
testServerBobRunning = False testServerBobRunning = False
systemLanguage = 'en'
httpPrefix = 'http' httpPrefix = 'http'
proxyType = None proxyType = None
@ -861,7 +864,7 @@ def testPostMessageBetweenServers():
attachedImageFilename, mediaType, attachedImageFilename, mediaType,
attachedImageDescription, city, federationList, attachedImageDescription, city, federationList,
aliceSendThreads, alicePostLog, aliceCachedWebfingers, aliceSendThreads, alicePostLog, aliceCachedWebfingers,
alicePersonCache, isArticle, inReplyTo, alicePersonCache, isArticle, systemLanguage, inReplyTo,
inReplyToAtomUri, subject) inReplyToAtomUri, subject)
print('sendResult: ' + str(sendResult)) print('sendResult: ' + str(sendResult))
@ -1052,6 +1055,7 @@ def testFollowBetweenServers():
testServerAliceRunning = False testServerAliceRunning = False
testServerBobRunning = False testServerBobRunning = False
systemLanguage = 'en'
httpPrefix = 'http' httpPrefix = 'http'
proxyType = None proxyType = None
federationList = [] federationList = []
@ -1185,7 +1189,7 @@ def testFollowBetweenServers():
clientToServer, True, clientToServer, True,
None, None, None, city, federationList, None, None, None, city, federationList,
aliceSendThreads, alicePostLog, aliceCachedWebfingers, aliceSendThreads, alicePostLog, aliceCachedWebfingers,
alicePersonCache, isArticle, inReplyTo, alicePersonCache, isArticle, systemLanguage, inReplyTo,
inReplyToAtomUri, subject) inReplyToAtomUri, subject)
print('sendResult: ' + str(sendResult)) print('sendResult: ' + str(sendResult))
@ -1456,6 +1460,7 @@ def _testFollows():
def _testCreatePerson(): def _testCreatePerson():
print('testCreatePerson') print('testCreatePerson')
systemLanguage = 'en'
currDir = os.getcwd() currDir = os.getcwd()
nickname = 'test382' nickname = 'test382'
domain = 'badgerdomain.com' domain = 'badgerdomain.com'
@ -1500,7 +1505,7 @@ def _testCreatePerson():
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
os.chdir(currDir) os.chdir(currDir)
shutil.rmtree(baseDir) shutil.rmtree(baseDir)
@ -1554,6 +1559,7 @@ def testClientToServer():
testServerAliceRunning = False testServerAliceRunning = False
testServerBobRunning = False testServerBobRunning = False
systemLanguage = 'en'
httpPrefix = 'http' httpPrefix = 'http'
proxyType = None proxyType = None
federationList = [] federationList = []
@ -1650,7 +1656,7 @@ def testClientToServer():
attachedImageFilename, mediaType, attachedImageFilename, mediaType,
attachedImageDescription, city, attachedImageDescription, city,
cachedWebfingers, personCache, isArticle, cachedWebfingers, personCache, isArticle,
True, None, None, None) systemLanguage, True, None, None, None)
print('sendResult: ' + str(sendResult)) print('sendResult: ' + str(sendResult))
for i in range(30): for i in range(30):
@ -2869,6 +2875,7 @@ def _testGetMentionedPeople() -> None:
def _testReplyToPublicPost() -> None: def _testReplyToPublicPost() -> None:
baseDir = os.getcwd() baseDir = os.getcwd()
systemLanguage = 'en'
nickname = 'test7492362' nickname = 'test7492362'
domain = 'other.site' domain = 'other.site'
port = 443 port = 443
@ -2899,7 +2906,7 @@ def _testReplyToPublicPost() -> None:
testInReplyToAtomUri, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
# print(str(reply)) # print(str(reply))
assert reply['object']['content'] == \ assert reply['object']['content'] == \
'<p><span class=\"h-card\">' + \ '<p><span class=\"h-card\">' + \
@ -3391,6 +3398,7 @@ def _testFunctions():
def _testLinksWithinPost() -> None: def _testLinksWithinPost() -> None:
baseDir = os.getcwd() baseDir = os.getcwd()
systemLanguage = 'en'
nickname = 'test27636' nickname = 'test27636'
domain = 'rando.site' domain = 'rando.site'
port = 443 port = 443
@ -3423,7 +3431,7 @@ def _testLinksWithinPost() -> None:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
assert postJsonObject['object']['content'] == \ assert postJsonObject['object']['content'] == \
'<p>This is a test post with links.<br><br>' + \ '<p>This is a test post with links.<br><br>' + \
@ -3457,7 +3465,7 @@ def _testLinksWithinPost() -> None:
testInReplyTo, testInReplyToAtomUri, testInReplyTo, testInReplyToAtomUri,
testSubject, testSchedulePost, testSubject, testSchedulePost,
testEventDate, testEventTime, testLocation, testEventDate, testEventTime, testLocation,
testIsArticle) testIsArticle, systemLanguage)
assert postJsonObject['object']['content'] == content assert postJsonObject['object']['content'] == content