Skip to content

Commit

Permalink
move getMentions into its own function and ensureCached less often
Browse files Browse the repository at this point in the history
  • Loading branch information
enkiv2 committed Jul 14, 2022
1 parent bdfd10d commit 6cd155d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions fern
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,11 @@ def getTimeline(which=None, **kw_args):
tl=[]
tl2=[]
if(which=="notifications"):
tl2=ensureCached([x["status"] for x in mastodon.notifications(mentions_only=myAccountId) if x["type"]=="mention"])
tl2=getMentions(mastodon.notifications())
else: tl2=mastodon.timeline(timeline=which, **kw_args)
tl.extend(ensureCached(tl2, verbose=True))
tl.extend(tl2)
saveBase()
return [x for x in tl if x!=None]
return ensureCached([x for x in tl if x!=None])

def expandThreads(tids, verbose=False):
if verbose:
Expand Down Expand Up @@ -577,7 +577,7 @@ def importHistory(src="all", verbose=False):
return []
toots=allPages(page, True, "Getting "+src+"...")
if src in ["notifications", "mentions"]:
toots=ensureCached([x["status"] for x in toots if x["type"]=="mention"])
toots=ensureCached(getMentions(toots))
return expandThreads(list(map(lambda x: gTid(x), toots)), True)

def allPages(page, verbose=False, msg=None):
Expand All @@ -596,6 +596,8 @@ def allPages(page, verbose=False, msg=None):
if pageNum>1: return ret
return ret

def getMentions(notifications):
return [x["status"] for x in notifications if x["type"]=="mentions"]

def ensureCachedAcct(acct, verbose=False, ignoreErrors=True, msg=None, force=False):
myMsg="fetching account ID"
Expand Down

0 comments on commit 6cd155d

Please sign in to comment.