Followers only posts can be pinned

main
Bob Mottram 2021-11-09 18:03:17 +00:00
parent 7d9a31ab91
commit c5b18b436c
3 changed files with 47 additions and 5 deletions

View File

@ -15547,8 +15547,10 @@ class PubServer(BaseHTTPRequestHandler):
contentStr = \ contentStr = \
getBaseContentFromPost(messageJson, getBaseContentFromPost(messageJson,
self.server.systemLanguage) self.server.systemLanguage)
followersOnly = False
pinPost(self.server.baseDir, pinPost(self.server.baseDir,
nickname, self.server.domain, contentStr) nickname, self.server.domain, contentStr,
followersOnly)
return 1 return 1
if self._postToOutbox(messageJson, if self._postToOutbox(messageJson,
self.server.projectVersion, self.server.projectVersion,
@ -15791,6 +15793,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
return -1 return -1
elif postType == 'newfollowers': 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, city = getSpoofedCity(self.server.city,
self.server.baseDir, self.server.baseDir,
nickname, nickname,
@ -15830,6 +15842,15 @@ class PubServer(BaseHTTPRequestHandler):
if messageJson: if messageJson:
if fields['schedulePost']: if fields['schedulePost']:
return 1 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, if self._postToOutbox(messageJson,
self.server.projectVersion, self.server.projectVersion,
nickname): nickname):

View File

@ -1562,7 +1562,7 @@ def _postIsAddressedToFollowers(baseDir: str,
def pinPost(baseDir: str, nickname: str, domain: 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 """Pins the given post Id to the profile of then given account
""" """
accountDir = acctDir(baseDir, nickname, domain) accountDir = acctDir(baseDir, nickname, domain)
@ -1570,6 +1570,18 @@ def pinPost(baseDir: str, nickname: str, domain: str,
with open(pinnedFilename, 'w+') as pinFile: with open(pinnedFilename, 'w+') as pinFile:
pinFile.write(pinnedContent) 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: def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
"""Removes pinned content for then given account """Removes pinned content for then given account
@ -1581,7 +1593,14 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None:
os.remove(pinnedFilename) os.remove(pinnedFilename)
except BaseException: except BaseException:
print('EX: undoPinnedPost unable to delete ' + pinnedFilename) 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, def getPinnedPostAsJson(baseDir: str, httpPrefix: str,

View File

@ -811,10 +811,12 @@ def htmlProfile(signingPrivateKeyPem: str,
# get pinned post content # get pinned post content
accountDir = acctDir(baseDir, nickname, domain) accountDir = acctDir(baseDir, nickname, domain)
pinnedFilename = accountDir + '/pinToProfile.txt' pinnedFilename = accountDir + '/pinToProfile.txt'
privatePinnedFilename = accountDir + '/pinToProfile.private'
pinnedContent = None pinnedContent = None
if os.path.isfile(pinnedFilename): if os.path.isfile(pinnedFilename):
with open(pinnedFilename, 'r') as pinFile: if not os.path.isfile(privatePinnedFilename):
pinnedContent = pinFile.read() with open(pinnedFilename, 'r') as pinFile:
pinnedContent = pinFile.read()
profileHeaderStr = \ profileHeaderStr = \
_getProfileHeader(baseDir, httpPrefix, _getProfileHeader(baseDir, httpPrefix,