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 = \
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):

View File

@ -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,

View File

@ -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,