diff --git a/daemon.py b/daemon.py index ce2d0166c..0dc818288 100644 --- a/daemon.py +++ b/daemon.py @@ -15547,8 +15547,10 @@ class PubServer(BaseHTTPRequestHandler): contentStr = \ getBaseContentFromPost(messageJson, self.server.systemLanguage) + followersOnly = False pinPost(self.server.baseDir, - nickname, self.server.domain, contentStr) + nickname, self.server.domain, contentStr, + followersOnly) return 1 if self._postToOutbox(messageJson, self.server.projectVersion, @@ -15791,6 +15793,16 @@ class PubServer(BaseHTTPRequestHandler): else: return -1 elif postType == 'newfollowers': + if not fields.get('pinToProfile'): + pinToProfile = False + else: + pinToProfile = True + # is the post message empty? + if not fields['message']: + # remove the pinned content from profile screen + undoPinnedPost(self.server.baseDir, + nickname, self.server.domain) + return 1 city = getSpoofedCity(self.server.city, self.server.baseDir, nickname, @@ -15830,6 +15842,15 @@ class PubServer(BaseHTTPRequestHandler): if messageJson: if fields['schedulePost']: return 1 + if pinToProfile: + contentStr = \ + getBaseContentFromPost(messageJson, + self.server.systemLanguage) + followersOnly = True + pinPost(self.server.baseDir, + nickname, self.server.domain, contentStr, + followersOnly) + return 1 if self._postToOutbox(messageJson, self.server.projectVersion, nickname): diff --git a/posts.py b/posts.py index 3d519221b..e3acde056 100644 --- a/posts.py +++ b/posts.py @@ -1562,7 +1562,7 @@ def _postIsAddressedToFollowers(baseDir: str, def pinPost(baseDir: str, nickname: str, domain: str, - pinnedContent: str) -> None: + pinnedContent: str, followersOnly: bool) -> None: """Pins the given post Id to the profile of then given account """ accountDir = acctDir(baseDir, nickname, domain) @@ -1570,6 +1570,18 @@ def pinPost(baseDir: str, nickname: str, domain: str, with open(pinnedFilename, 'w+') as pinFile: pinFile.write(pinnedContent) + privatePinnedFilename = accountDir + '/pinToProfile.private' + if followersOnly: + with open(privatePinnedFilename, 'w+') as pinFile: + pinFile.write('\n') + else: + if os.path.isfile(privatePinnedFilename): + try: + os.remove(privatePinnedFilename) + except BaseException: + print('EX: pinPost unable to delete private ' + + privatePinnedFilename) + def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None: """Removes pinned content for then given account @@ -1581,7 +1593,14 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None: os.remove(pinnedFilename) except BaseException: print('EX: undoPinnedPost unable to delete ' + pinnedFilename) - pass + + privatePinnedFilename = accountDir + '/pinToProfile.private' + if os.path.isfile(privatePinnedFilename): + try: + os.remove(privatePinnedFilename) + except BaseException: + print('EX: undoPinnedPost unable to delete private ' + + privatePinnedFilename) def getPinnedPostAsJson(baseDir: str, httpPrefix: str, diff --git a/webapp_profile.py b/webapp_profile.py index 269851597..e11a0a096 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -811,10 +811,12 @@ def htmlProfile(signingPrivateKeyPem: str, # get pinned post content accountDir = acctDir(baseDir, nickname, domain) pinnedFilename = accountDir + '/pinToProfile.txt' + privatePinnedFilename = accountDir + '/pinToProfile.private' pinnedContent = None if os.path.isfile(pinnedFilename): - with open(pinnedFilename, 'r') as pinFile: - pinnedContent = pinFile.read() + if not os.path.isfile(privatePinnedFilename): + with open(pinnedFilename, 'r') as pinFile: + pinnedContent = pinFile.read() profileHeaderStr = \ _getProfileHeader(baseDir, httpPrefix,