diff --git a/daemon.py b/daemon.py index 5dc7007cf..588da28f0 100644 --- a/daemon.py +++ b/daemon.py @@ -446,7 +446,8 @@ class PubServer(BaseHTTPRequestHandler): eventTime, location, False, self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: # name field contains the answer messageJson['object']['name'] = answer @@ -13957,7 +13958,8 @@ class PubServer(BaseHTTPRequestHandler): fields['eventDate'], fields['eventTime'], fields['location'], False, self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: if fields['schedulePost']: return 1 @@ -14036,7 +14038,8 @@ class PubServer(BaseHTTPRequestHandler): fields['eventTime'], fields['location'], self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: if fields['schedulePost']: return 1 @@ -14120,7 +14123,8 @@ class PubServer(BaseHTTPRequestHandler): filename, attachmentMediaType, imgDescription, - city) + city, + self.server.lowBandwidth) replaceYouTube(postJsonObject, self.server.YTReplacementDomain, @@ -14174,7 +14178,8 @@ class PubServer(BaseHTTPRequestHandler): fields['eventTime'], fields['location'], self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: if fields['schedulePost']: return 1 @@ -14222,7 +14227,8 @@ class PubServer(BaseHTTPRequestHandler): fields['eventTime'], fields['location'], self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: if fields['schedulePost']: return 1 @@ -14274,7 +14280,8 @@ class PubServer(BaseHTTPRequestHandler): fields['eventTime'], fields['location'], self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: if fields['schedulePost']: return 1 @@ -14324,7 +14331,8 @@ class PubServer(BaseHTTPRequestHandler): fields['eventTime'], fields['location'], self.server.systemLanguage, - conversationId) + conversationId, + self.server.lowBandwidth) if messageJson: if fields['schedulePost']: return 1 @@ -14357,7 +14365,8 @@ class PubServer(BaseHTTPRequestHandler): fields['imageDescription'], city, self.server.debug, fields['subject'], - self.server.systemLanguage) + self.server.systemLanguage, + self.server.lowBandwidth) if messageJson: if self._postToOutbox(messageJson, __version__, nickname): return 1 @@ -14395,7 +14404,8 @@ class PubServer(BaseHTTPRequestHandler): city, fields['subject'], intDuration, - self.server.systemLanguage) + self.server.systemLanguage, + self.server.lowBandwidth) if messageJson: if self.server.debug: print('DEBUG: new Question') @@ -15592,7 +15602,8 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None: break -def runDaemon(maxLikeCount: int, +def runDaemon(lowBandwidth: bool, + maxLikeCount: int, sharedItemsFederatedDomains: [], userAgentsBlocked: [], logLoginFailures: bool, @@ -15722,6 +15733,9 @@ def runDaemon(maxLikeCount: int, httpd.keyShortcuts = {} loadAccessKeysForAccounts(baseDir, httpd.keyShortcuts, httpd.accessKeys) + # wheither to use low bandwidth images + httpd.lowBandwidth = lowBandwidth + # list of blocked user agent types within the User-Agent header httpd.userAgentsBlocked = userAgentsBlocked diff --git a/desktop_client.py b/desktop_client.py index 0d42b58f2..c85407273 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -416,7 +416,8 @@ def _desktopReplyToPost(session, postId: str, cachedWebfingers: {}, personCache: {}, debug: bool, subject: str, screenreader: str, systemLanguage: str, - espeak, conversationId: str) -> None: + espeak, conversationId: str, + lowBandwidth: bool) -> None: """Use the desktop client to send a reply to the most recent post """ if '://' not in postId: @@ -469,7 +470,8 @@ def _desktopReplyToPost(session, postId: str, commentsEnabled, attach, mediaType, attachedImageDescription, city, cachedWebfingers, personCache, isArticle, - systemLanguage, debug, postId, postId, + systemLanguage, lowBandwidth, + debug, postId, postId, conversationId, subject) == 0: sayStr = 'Reply sent' else: @@ -483,7 +485,7 @@ def _desktopNewPost(session, cachedWebfingers: {}, personCache: {}, debug: bool, screenreader: str, systemLanguage: str, - espeak) -> None: + espeak, lowBandwidth: bool) -> None: """Use the desktop client to create a new post """ conversationId = None @@ -532,7 +534,8 @@ def _desktopNewPost(session, commentsEnabled, attach, mediaType, attachedImageDescription, city, cachedWebfingers, personCache, isArticle, - systemLanguage, debug, None, None, + systemLanguage, lowBandwidth, + debug, None, None, conversationId, subject) == 0: sayStr = 'Post sent' else: @@ -1108,7 +1111,7 @@ def _desktopNewDM(session, toHandle: str, cachedWebfingers: {}, personCache: {}, debug: bool, screenreader: str, systemLanguage: str, - espeak) -> None: + espeak, lowBandwidth: bool) -> None: """Use the desktop client to create a new direct message which can include multiple destination handles """ @@ -1129,7 +1132,7 @@ def _desktopNewDM(session, toHandle: str, cachedWebfingers, personCache, debug, screenreader, systemLanguage, - espeak) + espeak, lowBandwidth) def _desktopNewDMbase(session, toHandle: str, @@ -1138,7 +1141,7 @@ def _desktopNewDMbase(session, toHandle: str, cachedWebfingers: {}, personCache: {}, debug: bool, screenreader: str, systemLanguage: str, - espeak) -> None: + espeak, lowBandwidth: bool) -> None: """Use the desktop client to create a new direct message """ conversationId = None @@ -1226,7 +1229,8 @@ def _desktopNewDMbase(session, toHandle: str, commentsEnabled, attach, mediaType, attachedImageDescription, city, cachedWebfingers, personCache, isArticle, - systemLanguage, debug, None, None, + systemLanguage, lowBandwidth, + debug, None, None, conversationId, subject) == 0: sayStr = 'Direct message sent' else: @@ -1292,7 +1296,7 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str, storeInboxPosts: bool, showNewPosts: bool, language: str, - debug: bool) -> None: + debug: bool, lowBandwidth: bool) -> None: """Runs the desktop and screen reader client, which announces new inbox items """ @@ -1683,7 +1687,8 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str, cachedWebfingers, personCache, debug, subject, screenreader, systemLanguage, - espeak, conversationId) + espeak, conversationId, + lowBandwidth) refreshTimeline = True print('') elif (commandStr == 'post' or commandStr == 'p' or @@ -1717,7 +1722,7 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str, cachedWebfingers, personCache, debug, screenreader, systemLanguage, - espeak) + espeak, lowBandwidth) refreshTimeline = True else: # public post @@ -1727,7 +1732,7 @@ def runDesktopClient(baseDir: str, proxyType: str, httpPrefix: str, cachedWebfingers, personCache, debug, screenreader, systemLanguage, - espeak) + espeak, lowBandwidth) refreshTimeline = True print('') elif commandStr == 'like' or commandStr.startswith('like '): diff --git a/epicyon.py b/epicyon.py index a3f74c7c4..d87c0187c 100644 --- a/epicyon.py +++ b/epicyon.py @@ -331,6 +331,11 @@ parser.add_argument("--rssIconAtTop", const=True, default=True, help="Whether to show the rss icon at teh top or bottom" + "of the timeline") +parser.add_argument("--lowBandwidth", + dest='lowBandwidth', + type=str2bool, nargs='?', + const=True, default=True, + help="Whether to use low bandwidth images") parser.add_argument("--publishButtonAtTop", dest='publishButtonAtTop', type=str2bool, nargs='?', @@ -1190,7 +1195,7 @@ if args.message: args.commentsEnabled, attach, mediaType, attachedImageDescription, city, cachedWebfingers, personCache, isArticle, - args.language, args.debug, + args.language, args.lowBandwidth, args.debug, replyTo, replyTo, args.conversationId, subject) for i in range(10): # TODO detect send success/fail @@ -2265,7 +2270,7 @@ if args.desktop: storeInboxPosts, args.notifyShowNewPosts, args.language, - args.debug) + args.debug, args.lowBandwidth) sys.exit() if federationList: @@ -2515,6 +2520,7 @@ if args.testdata: testLocation = None testIsArticle = False conversationId = None + lowBandwidth = False createPublicPost(baseDir, nickname, domain, port, httpPrefix, "like this is totally just a #test man", @@ -2527,7 +2533,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "Zoiks!!!", testFollowersOnly, @@ -2539,7 +2546,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "Hey scoob we need like a hundred more #milkshakes", testFollowersOnly, @@ -2551,7 +2559,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "Getting kinda spooky around here", testFollowersOnly, @@ -2563,7 +2572,8 @@ if args.testdata: 'someone', testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "And they would have gotten away with it too" + "if it wasn't for those pesky hackers", @@ -2576,7 +2586,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "man these centralized sites are like the worst!", testFollowersOnly, @@ -2588,7 +2599,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "another mystery solved #test", testFollowersOnly, @@ -2600,7 +2612,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) createPublicPost(baseDir, nickname, domain, port, httpPrefix, "let's go bowling", testFollowersOnly, @@ -2612,7 +2625,8 @@ if args.testdata: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, args.language, conversationId) + testIsArticle, args.language, conversationId, + lowBandwidth) domainFull = domain + ':' + str(port) clearFollows(baseDir, nickname, domain) followPerson(baseDir, nickname, domain, 'maxboardroom', domainFull, @@ -2815,7 +2829,7 @@ if args.defaultCurrency: print('Default currency set to ' + args.defaultCurrency) if __name__ == "__main__": - runDaemon(args.maxLikeCount, + runDaemon(args.lowBandwidth, args.maxLikeCount, sharedItemsFederatedDomains, userAgentsBlocked, args.logLoginFailures, diff --git a/inbox.py b/inbox.py index 86971ccc2..1c7878f64 100644 --- a/inbox.py +++ b/inbox.py @@ -2100,6 +2100,7 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str, eventTime = None location = None conversationId = None + lowBandwidth = False postJsonObject = \ createDirectMessagePost(baseDir, nickname, domain, port, httpPrefix, content, followersOnly, @@ -2110,7 +2111,7 @@ def _bounceDM(senderPostId: str, session, httpPrefix: str, inReplyTo, inReplyToAtomUri, subject, debug, schedulePost, eventDate, eventTime, location, - systemLanguage, conversationId) + systemLanguage, conversationId, lowBandwidth) if not postJsonObject: print('WARN: unable to create bounce message to ' + sendingHandle) return False diff --git a/media.py b/media.py index 423fd8fa5..e062cc773 100644 --- a/media.py +++ b/media.py @@ -114,6 +114,16 @@ def _spoofMetaData(baseDir: str, nickname: str, domain: str, return +def _convertImageToLowBandwidth(imageFilename: str) -> None: + """Converts an image to a low bandwidth version + """ + cmd = \ + '/usr/bin/convert -resize 50% +noise Multiplicative ' + \ + '-evaluate median 10% -dither Floyd-Steinberg ' + \ + '-monochrome ' + imageFilename + ' ' + imageFilename + subprocess.call(cmd, shell=True) + + def processMetaData(baseDir: str, nickname: str, domain: str, imageFilename: str, outputFilename: str, city: str) -> None: @@ -209,7 +219,7 @@ def attachMedia(baseDir: str, httpPrefix: str, nickname: str, domain: str, port: int, postJson: {}, imageFilename: str, mediaType: str, description: str, - city: str) -> {}: + city: str, lowBandwidth: bool) -> {}: """Attaches media to a json object post The description can be None """ @@ -262,6 +272,8 @@ def attachMedia(baseDir: str, httpPrefix: str, if baseDir: if mediaType.startswith('image/'): + if lowBandwidth: + _convertImageToLowBandwidth(imageFilename) processMetaData(baseDir, nickname, domain, imageFilename, mediaFilename, city) else: diff --git a/newsdaemon.py b/newsdaemon.py index 7c5b4679d..f26e6bee7 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -520,7 +520,8 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str, sendThreads: [], postLog: [], maxMirroredArticles: int, allowLocalNetworkAccess: bool, - systemLanguage: str) -> None: + systemLanguage: str, + lowBandwidth: bool) -> None: """Converts rss items in a newswire into posts """ if not newswire: @@ -602,7 +603,7 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str, attachImageFilename, mediaType, imageDescription, city, rssTitle, systemLanguage, - conversationId) + conversationId, lowBandwidth) if not blog: continue @@ -782,7 +783,8 @@ def runNewswireDaemon(baseDir: str, httpd, httpd.postLog, httpd.maxMirroredArticles, httpd.allowLocalNetworkAccess, - httpd.systemLanguage) + httpd.systemLanguage, + httpd.lowBandwidth) print('Newswire feed converted to ActivityPub') if httpd.maxNewsPosts > 0: diff --git a/posts.py b/posts.py index c436b1daa..b9f1ff86f 100644 --- a/posts.py +++ b/posts.py @@ -916,7 +916,7 @@ def _createPostS2S(baseDir: str, nickname: str, domain: str, port: int, mediaType: str, imageDescription: str, city: str, postObjectType: str, summary: str, inReplyToAtomUri: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: """Creates a new server-to-server post """ actorUrl = httpPrefix + '://' + domain + '/users/' + nickname @@ -975,7 +975,7 @@ def _createPostS2S(baseDir: str, nickname: str, domain: str, port: int, newPost['object'] = \ attachMedia(baseDir, httpPrefix, nickname, domain, port, newPost['object'], attachImageFilename, - mediaType, imageDescription, city) + mediaType, imageDescription, city, lowBandwidth) return newPost @@ -988,7 +988,7 @@ def _createPostC2S(baseDir: str, nickname: str, domain: str, port: int, mediaType: str, imageDescription: str, city: str, postObjectType: str, summary: str, inReplyToAtomUri: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: str) -> {}: """Creates a new client-to-server post """ idStr = \ @@ -1036,7 +1036,7 @@ def _createPostC2S(baseDir: str, nickname: str, domain: str, port: int, newPost = \ attachMedia(baseDir, httpPrefix, nickname, domain, port, newPost, attachImageFilename, - mediaType, imageDescription, city) + mediaType, imageDescription, city, lowBandwidth) return newPost @@ -1162,7 +1162,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int, anonymousParticipationEnabled: bool, eventStatus: str, ticketUrl: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: """Creates a message """ content = removeInvalidChars(content) @@ -1292,7 +1292,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int, mediaType, imageDescription, city, postObjectType, summary, inReplyToAtomUri, systemLanguage, - conversationId) + conversationId, lowBandwidth) else: newPost = \ _createPostC2S(baseDir, nickname, domain, port, @@ -1304,7 +1304,7 @@ def _createPostBase(baseDir: str, nickname: str, domain: str, port: int, mediaType, imageDescription, city, postObjectType, summary, inReplyToAtomUri, systemLanguage, - conversationId) + conversationId, lowBandwidth) _createPostMentions(ccUrl, newPost, toRecipients, tags) @@ -1544,7 +1544,7 @@ def createPublicPost(baseDir: str, location: str, isArticle: bool, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: """Public post """ domainFull = getFullDomain(domain, port) @@ -1575,7 +1575,7 @@ def createPublicPost(baseDir: str, repliesModerationOption, anonymousParticipationEnabled, eventStatus, ticketUrl, systemLanguage, - conversationId) + conversationId, lowBandwidth) def _appendCitationsToBlogPost(baseDir: str, @@ -1618,7 +1618,7 @@ def createBlogPost(baseDir: str, subject: str, schedulePost: bool, eventDate: str, eventTime: str, location: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: blogJson = \ createPublicPost(baseDir, nickname, domain, port, httpPrefix, @@ -1629,7 +1629,8 @@ def createBlogPost(baseDir: str, inReplyTo, inReplyToAtomUri, subject, schedulePost, eventDate, eventTime, location, - True, systemLanguage, conversationId) + True, systemLanguage, conversationId, + lowBandwidth) blogJson['object']['url'] = \ blogJson['object']['url'].replace('/@', '/users/') _appendCitationsToBlogPost(baseDir, nickname, domain, blogJson) @@ -1643,7 +1644,7 @@ def createNewsPost(baseDir: str, attachImageFilename: str, mediaType: str, imageDescription: str, city: str, subject: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: clientToServer = False inReplyTo = None inReplyToAtomUri = None @@ -1661,7 +1662,8 @@ def createNewsPost(baseDir: str, inReplyTo, inReplyToAtomUri, subject, schedulePost, eventDate, eventTime, location, - True, systemLanguage, conversationId) + True, systemLanguage, conversationId, + lowBandwidth) blog['object']['type'] = 'Article' return blog @@ -1674,7 +1676,7 @@ def createQuestionPost(baseDir: str, attachImageFilename: str, mediaType: str, imageDescription: str, city: str, subject: str, durationDays: int, - systemLanguage: str) -> {}: + systemLanguage: str, lowBandwidth: bool) -> {}: """Question post with multiple choice options """ domainFull = getFullDomain(domain, port) @@ -1691,7 +1693,7 @@ def createQuestionPost(baseDir: str, False, None, None, None, None, None, None, None, None, None, None, None, None, None, systemLanguage, - None) + None, lowBandwidth) messageJson['object']['type'] = 'Question' messageJson['object']['oneOf'] = [] messageJson['object']['votersCount'] = 0 @@ -1723,7 +1725,7 @@ def createUnlistedPost(baseDir: str, subject: str, schedulePost: bool, eventDate: str, eventTime: str, location: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: """Unlisted post. This has the #Public and followers links inverted. """ domainFull = getFullDomain(domain, port) @@ -1740,7 +1742,7 @@ def createUnlistedPost(baseDir: str, schedulePost, eventDate, eventTime, location, None, None, None, None, None, None, None, None, None, None, systemLanguage, - conversationId) + conversationId, lowBandwidth) def createFollowersOnlyPost(baseDir: str, @@ -1756,7 +1758,7 @@ def createFollowersOnlyPost(baseDir: str, subject: str, schedulePost: bool, eventDate: str, eventTime: str, location: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: """Followers only post """ domainFull = getFullDomain(domain, port) @@ -1773,7 +1775,7 @@ def createFollowersOnlyPost(baseDir: str, schedulePost, eventDate, eventTime, location, None, None, None, None, None, None, None, None, None, None, systemLanguage, - conversationId) + conversationId, lowBandwidth) def getMentionedPeople(baseDir: str, httpPrefix: str, @@ -1826,7 +1828,7 @@ def createDirectMessagePost(baseDir: str, schedulePost: bool, eventDate: str, eventTime: str, location: str, systemLanguage: str, - conversationId: str) -> {}: + conversationId: str, lowBandwidth: bool) -> {}: """Direct Message post """ content = resolvePetnames(baseDir, nickname, domain, content) @@ -1850,7 +1852,7 @@ def createDirectMessagePost(baseDir: str, schedulePost, eventDate, eventTime, location, None, None, None, None, None, None, None, None, None, None, systemLanguage, - conversationId) + conversationId, lowBandwidth) # mentioned recipients go into To rather than Cc messageJson['to'] = messageJson['object']['cc'] messageJson['object']['to'] = messageJson['to'] @@ -1868,7 +1870,8 @@ def createReportPost(baseDir: str, clientToServer: bool, commentsEnabled: bool, attachImageFilename: str, mediaType: str, imageDescription: str, city: str, - debug: bool, subject: str, systemLanguage: str) -> {}: + debug: bool, subject: str, systemLanguage: str, + lowBandwidth: bool) -> {}: """Send a report to moderators """ domainFull = getFullDomain(domain, port) @@ -1941,7 +1944,7 @@ def createReportPost(baseDir: str, False, None, None, None, None, None, None, None, None, None, None, None, None, None, systemLanguage, - None) + None, lowBandwidth) if not postJsonObject: continue @@ -2032,6 +2035,7 @@ def sendPost(projectVersion: str, isArticle: bool, systemLanguage: str, sharedItemsFederatedDomains: [], sharedItemFederationTokens: {}, + lowBandwidth: bool, debug: bool = False, inReplyTo: str = None, inReplyToAtomUri: str = None, subject: str = None) -> int: """Post to another inbox. Used by unit tests. @@ -2094,7 +2098,7 @@ def sendPost(projectVersion: str, False, None, None, None, None, None, None, None, None, None, None, None, None, None, systemLanguage, - conversationId) + conversationId, lowBandwidth) # get the senders private key privateKeyPem = _getPersonKey(nickname, domain, baseDir, 'private') @@ -2174,6 +2178,7 @@ def sendPostViaServer(projectVersion: str, imageDescription: str, city: str, cachedWebfingers: {}, personCache: {}, isArticle: bool, systemLanguage: str, + lowBandwidth: bool, debug: bool = False, inReplyTo: str = None, inReplyToAtomUri: str = None, @@ -2257,7 +2262,7 @@ def sendPostViaServer(projectVersion: str, False, None, None, None, None, None, None, None, None, None, None, None, None, None, systemLanguage, - conversationId) + conversationId, lowBandwidth) authHeader = createBasicAuthHeader(fromNickname, password) diff --git a/tests.py b/tests.py index 56a4dc333..7bc899081 100644 --- a/tests.py +++ b/tests.py @@ -491,6 +491,7 @@ def createServerAlice(path: str, domain: str, port: int, domainMaxPostsPerDay = 1000 accountMaxPostsPerDay = 1000 allowDeletion = True + lowBandwidth = True privateKeyPem, publicKeyPem, person, wfEndpoint = \ createPerson(path, nickname, domain, port, httpPrefix, True, False, password) @@ -533,7 +534,8 @@ def createServerAlice(path: str, domain: str, port: int, testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) createPublicPost(path, nickname, domain, port, httpPrefix, "Curiouser and curiouser!", testFollowersOnly, @@ -546,7 +548,8 @@ def createServerAlice(path: str, domain: str, port: int, testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) createPublicPost(path, nickname, domain, port, httpPrefix, "In the gardens of memory, in the palace " + "of dreams, that is where you and I shall meet", @@ -560,7 +563,8 @@ def createServerAlice(path: str, domain: str, port: int, testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) regenerateIndexForBox(path, nickname, domain, 'outbox') global testServerAliceRunning testServerAliceRunning = True @@ -582,7 +586,7 @@ def createServerAlice(path: str, domain: str, port: int, userAgentsBlocked = [] maxLikeCount = 10 print('Server running: Alice') - runDaemon(maxLikeCount, + runDaemon(lowBandwidth, maxLikeCount, sharedItemsFederatedDomains, userAgentsBlocked, logLoginFailures, city, @@ -626,6 +630,7 @@ def createServerBob(path: str, domain: str, port: int, domainMaxPostsPerDay = 1000 accountMaxPostsPerDay = 1000 allowDeletion = True + lowBandwidth = True privateKeyPem, publicKeyPem, person, wfEndpoint = \ createPerson(path, nickname, domain, port, httpPrefix, True, False, password) @@ -665,7 +670,8 @@ def createServerBob(path: str, domain: str, port: int, testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) createPublicPost(path, nickname, domain, port, httpPrefix, "One of the things I've realised is that " + "I am very simple", @@ -679,7 +685,8 @@ def createServerBob(path: str, domain: str, port: int, testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) createPublicPost(path, nickname, domain, port, httpPrefix, "Quantum physics is a bit of a passion of mine", testFollowersOnly, @@ -692,7 +699,8 @@ def createServerBob(path: str, domain: str, port: int, testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) regenerateIndexForBox(path, nickname, domain, 'outbox') global testServerBobRunning testServerBobRunning = True @@ -714,7 +722,7 @@ def createServerBob(path: str, domain: str, port: int, userAgentsBlocked = [] maxLikeCount = 10 print('Server running: Bob') - runDaemon(maxLikeCount, + runDaemon(lowBandwidth, maxLikeCount, sharedItemsFederatedDomains, userAgentsBlocked, logLoginFailures, city, @@ -777,8 +785,9 @@ def createServerEve(path: str, domain: str, port: int, federationList: [], logLoginFailures = False userAgentsBlocked = [] maxLikeCount = 10 + lowBandwidth = True print('Server running: Eve') - runDaemon(maxLikeCount, + runDaemon(lowBandwidth, maxLikeCount, sharedItemsFederatedDomains, userAgentsBlocked, logLoginFailures, city, @@ -843,8 +852,9 @@ def createServerGroup(path: str, domain: str, port: int, logLoginFailures = False userAgentsBlocked = [] maxLikeCount = 10 + lowBandwidth = True print('Server running: Group') - runDaemon(maxLikeCount, + runDaemon(lowBandwidth, maxLikeCount, sharedItemsFederatedDomains, userAgentsBlocked, logLoginFailures, city, @@ -967,7 +977,7 @@ def testPostMessageBetweenServers(): outboxPath = aliceDir + '/accounts/alice@' + aliceDomain + '/outbox' assert len([name for name in os.listdir(outboxPath) if os.path.isfile(os.path.join(outboxPath, name))]) == 0 - + lowBandwidth = False sendResult = \ sendPost(__version__, sessionAlice, aliceDir, 'alice', aliceDomain, alicePort, @@ -981,7 +991,7 @@ def testPostMessageBetweenServers(): aliceSendThreads, alicePostLog, aliceCachedWebfingers, alicePersonCache, isArticle, systemLanguage, aliceSharedItemsFederatedDomains, - aliceSharedItemFederationTokens, + aliceSharedItemFederationTokens, lowBandwidth, inReplyTo, inReplyToAtomUri, subject) print('sendResult: ' + str(sendResult)) @@ -1304,6 +1314,7 @@ def testFollowBetweenServers(): alicePostLog = [] isArticle = False city = 'London, England' + lowBandwidth = False sendResult = \ sendPost(__version__, sessionAlice, aliceDir, 'alice', aliceDomain, alicePort, @@ -1314,7 +1325,7 @@ def testFollowBetweenServers(): aliceSendThreads, alicePostLog, aliceCachedWebfingers, alicePersonCache, isArticle, systemLanguage, aliceSharedItemsFederatedDomains, - aliceSharedItemFederationTokens, + aliceSharedItemFederationTokens, lowBandwidth, inReplyTo, inReplyToAtomUri, subject) print('sendResult: ' + str(sendResult)) @@ -1621,6 +1632,7 @@ def testSharedItemsFederation(): alicePostLog = [] isArticle = False city = 'London, England' + lowBandwidth = False sendResult = \ sendPost(__version__, sessionAlice, aliceDir, 'alice', aliceDomain, alicePort, @@ -1631,7 +1643,7 @@ def testSharedItemsFederation(): aliceSendThreads, alicePostLog, aliceCachedWebfingers, alicePersonCache, isArticle, systemLanguage, aliceSharedItemsFederatedDomains, - aliceSharedItemFederationTokens, True, + aliceSharedItemFederationTokens, lowBandwidth, True, inReplyTo, inReplyToAtomUri, subject) print('sendResult: ' + str(sendResult)) @@ -2012,6 +2024,7 @@ def testGroupFollow(): alicePostLog = [] isArticle = False city = 'London, England' + lowBandwidth = False sendResult = \ sendPost(__version__, sessionAlice, aliceDir, 'alice', aliceDomain, alicePort, @@ -2022,7 +2035,7 @@ def testGroupFollow(): aliceSendThreads, alicePostLog, aliceCachedWebfingers, alicePersonCache, isArticle, systemLanguage, aliceSharedItemsFederatedDomains, - aliceSharedItemFederationTokens, + aliceSharedItemFederationTokens, lowBandwidth, inReplyTo, inReplyToAtomUri, subject) print('sendResult: ' + str(sendResult)) @@ -2363,6 +2376,7 @@ def _testCreatePerson(): attachImageFilename = None mediaType = None conversationId = None + lowBandwidth = True createPublicPost(baseDir, nickname, domain, port, httpPrefix, content, followersOnly, saveToFile, clientToServer, commentsEnabled, attachImageFilename, mediaType, @@ -2370,7 +2384,8 @@ def _testCreatePerson(): testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) os.chdir(currDir) shutil.rmtree(baseDir) @@ -2428,6 +2443,7 @@ def testClientToServer(): httpPrefix = 'http' proxyType = None federationList = [] + lowBandwidth = False baseDir = os.getcwd() if os.path.isdir(baseDir + '/.tests'): @@ -2522,7 +2538,8 @@ def testClientToServer(): attachedImageFilename, mediaType, attachedImageDescription, city, cachedWebfingers, personCache, isArticle, - systemLanguage, True, None, None, + systemLanguage, lowBandwidth, + True, None, None, conversationId, None) print('sendResult: ' + str(sendResult)) @@ -3766,6 +3783,7 @@ def _testReplyToPublicPost() -> None: testLocation = None testIsArticle = False conversationId = None + lowBandwidth = True reply = \ createPublicPost(baseDir, nickname, domain, port, httpPrefix, content, followersOnly, saveToFile, @@ -3775,7 +3793,8 @@ def _testReplyToPublicPost() -> None: testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) # print(str(reply)) assert reply['object']['content'] == \ '

' + \ @@ -4297,6 +4316,7 @@ def _testLinksWithinPost() -> None: testLocation = None testIsArticle = False conversationId = None + lowBandwidth = True postJsonObject = \ createPublicPost(baseDir, nickname, domain, port, httpPrefix, @@ -4307,7 +4327,8 @@ def _testLinksWithinPost() -> None: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) assert postJsonObject['object']['content'] == \ '

This is a test post with links.

' + \ @@ -4343,7 +4364,8 @@ def _testLinksWithinPost() -> None: testInReplyTo, testInReplyToAtomUri, testSubject, testSchedulePost, testEventDate, testEventTime, testLocation, - testIsArticle, systemLanguage, conversationId) + testIsArticle, systemLanguage, conversationId, + lowBandwidth) assert postJsonObject['object']['content'] == content assert postJsonObject['object']['contentMap'][systemLanguage] == content