forked from indymedia/epicyon
Show recent shared items in left column
parent
f5c1b7bec2
commit
11458f73e4
|
@ -11,6 +11,7 @@ from shutil import copyfile
|
|||
from utils import getConfigParam
|
||||
from utils import getNicknameFromActor
|
||||
from utils import isEditor
|
||||
from webapp_utils import sharesTimelineJson
|
||||
from webapp_utils import htmlPostSeparator
|
||||
from webapp_utils import getLeftImageFile
|
||||
from webapp_utils import getImageFile
|
||||
|
@ -28,6 +29,40 @@ def linksExist(baseDir: str) -> bool:
|
|||
return os.path.isfile(linksFilename)
|
||||
|
||||
|
||||
def getLeftColumnShares(baseDir: str,
|
||||
httpPrefix: str, domainFull: str,
|
||||
nickname: str,
|
||||
maxSharesInLeftColumn: int,
|
||||
translate: {}) -> []:
|
||||
"""get any shares and turn them into the left column links format
|
||||
"""
|
||||
pageNumber = 1
|
||||
actor = httpPrefix + '://' + domainFull + '/users/' + nickname
|
||||
sharesJson, lastPage = \
|
||||
sharesTimelineJson(actor, pageNumber,
|
||||
maxSharesInLeftColumn,
|
||||
baseDir, maxSharesInLeftColumn)
|
||||
if not sharesJson:
|
||||
return []
|
||||
|
||||
linksList = []
|
||||
ctr = 0
|
||||
for published, item in sharesJson.items():
|
||||
sharedesc = item['displayName']
|
||||
contactActor = item['actor']
|
||||
shareLink = actor + \
|
||||
'?replydm=sharedesc:' + sharedesc + \
|
||||
'?mention=' + contactActor
|
||||
linksList.append(sharedesc + ' ' + shareLink)
|
||||
ctr += 1
|
||||
if ctr >= maxSharesInLeftColumn:
|
||||
break
|
||||
|
||||
if linksList:
|
||||
linksList = ['* ' + translate['Shares']] + linksList
|
||||
return linksList
|
||||
|
||||
|
||||
def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
|
||||
httpPrefix: str, translate: {},
|
||||
iconsPath: str, editor: bool,
|
||||
|
@ -136,10 +171,20 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str,
|
|||
|
||||
linksFilename = baseDir + '/accounts/links.txt'
|
||||
linksFileContainsEntries = False
|
||||
if os.path.isfile(linksFilename):
|
||||
linksList = None
|
||||
if os.path.isfile(linksFilename):
|
||||
with open(linksFilename, "r") as f:
|
||||
linksList = f.readlines()
|
||||
|
||||
# show a number of shares
|
||||
maxSharesInLeftColumn = 3
|
||||
sharesList = \
|
||||
getLeftColumnShares(baseDir,
|
||||
httpPrefix, domainFull, nickname,
|
||||
maxSharesInLeftColumn, translate)
|
||||
if linksList and sharesList:
|
||||
linksList += sharesList
|
||||
|
||||
if linksList:
|
||||
for lineStr in linksList:
|
||||
if ' ' not in lineStr:
|
||||
|
|
Loading…
Reference in New Issue