Skip to content

Commit

Permalink
toot menu is now general-purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
enkiv2 committed Jul 14, 2022
1 parent fb11c93 commit 4594bf4
Showing 1 changed file with 52 additions and 47 deletions.
99 changes: 52 additions & 47 deletions fern
Original file line number Diff line number Diff line change
Expand Up @@ -279,52 +279,14 @@ def drawSelectedMsg(user, displayname, cw, msg, cwopen=False):
scr.addstr(i, panelstart, line, curses.color_pair(textnum))
i+=1

def drawPanelContents(toots, selectedIdx, skipSeen=False):
def drawPanelContents(toots, selectedIdx):
global isCWOpen
scr.clear()
drawPanels(fillInDomain(mastodon.account_verify_credentials()["acct"]), ROWS, COLS, selectedIdx)
i=0
for toot in toots:
for toot in stripNulls(toots):
if(i>(ROWS-3)/4): continue
if toot==None:
drawMsgPanel(i, "", "", "MESSAGE UNAVAILABLE", "", True)
if i==selectedIdx:
drawSelectedMsg("", "", "", "MESSAGE UNAVAILABLE", True)
else:
if "reblog" in toot and toot["reblog"] and type(toot["reblog"])==type(toot): toot=toot["reblog"]
if "muted" in toot or not "id" in toot: next
tid=gTid(toot)
if not tid in tootbase: tootbase[tid]=copy.deepcopy(toot)
seen=(tid in seen_toots)
if skipSeen and seen: next
acct=toot["account"]
username=fillInDomain(acct["acct"])
content=processContents(toot["content"])
cw=applyCWRules(username, content, toot["spoiler_text"])
drawMsgPanel(i, username, cw, content, str(toot["created_at"]), seen)
if i==selectedIdx:
if not seen:
seen_toots.append(tid)
if "media_attachments" in toot:
for attachment in toot["media_attachments"]:
content+="\n"+attachment["url"]
flags=""
if "in_reply_to_id" in toot and toot["in_reply_to_id"]: flags+="["+str(toot["in_reply_to_id"])+"<-]"
if toot["reblogged"]: flags+="[b]"
if toot["favourited"]: flags+="[f]"
if toot["sensitive"]: flags+="[sensitive]"
if "visibility" in toot: flags+="["+toot["visibility"]+"]"
if "mentions" in toot and toot["mentions"]:
if len(flags)>0: flags+="\n"
flags+="TO: "
for mention in toot["mentions"]: flags+=fillInDomain(mention["acct"])+" "
flags+="\n"
content=flags+content
if "tags" in toot and toot["tags"]:
tags=[]
for tag in toot["tags"]: tags.append(tag["name"])
content+="\n\nTAGS: "+(" ".join(tags))
drawSelectedMsg(username, acct["display_name"], cw, content, isCWOpen)
drawSelectionMenuItem(i, (i==selectedIdx), toot[0], *toot[1])
i+=1
scr.refresh()

Expand All @@ -348,6 +310,47 @@ def conditionalStatusMsg(default_msg, verbose=False, wait=False, msg=None, prefi
myMsg+=" "+suffix
statusMsg(myMsg, wait)

def prettyToots(toots, skipSeen=False):
ret=[]
for toot in toots:
t=toot
if "reblog" in toot and toot["reblog"]:
t=ensureCached(toot["reblog"])
t=prettyToot(t)
if not (skipSeen and t[1][6]):
ret.append(t)
return ret

def prettyToot(toot):
tid=gTid(toot)
acct=toot["account"]
username=fillInDomain(acct["acct"])
shortContent=processContents(toot["content"])
content=shortContent
cw=applyCWRules(username, content, toot["spoiler_text"])
if "media_attachments" in toot:
for attachment in toot["media_attachments"]:
content+="\n"+attachment["url"]
flags=""
if "in_reply_to_id" in toot and toot["in_reply_to_id"]: flags+="["+str(toot["in_reply_to_id"])+"<-]"
if toot["reblogged"]: flags+="[b]"
if toot["favourited"]: flags+="[f]"
if toot["sensitive"]: flags+="[sensitive]"
if "visibility" in toot: flags+="["+toot["visibility"]+"]"
if "mentions" in toot and toot["mentions"]:
if len(flags)>0: flags+="\n"
flags+="TO: "
for mention in toot["mentions"]: flags+=fillInDomain(mention["acct"])+" "
flags+="\n"
content=flags+content
if "tags" in toot and toot["tags"]:
tags=[]
for tag in toot["tags"]: tags.append(tag["name"])
content+="\n\nTAGS: "+(" ".join(tags))
seen=(tid in seen_toots)
ret=[username, acct["display_name"], cw, shortContent, content, str(toot["created_at"]), seen, isCWOpen]
return [tid, ret]

def prettyProfile(acct):
locked="[unlocked]"
if acct["locked"]:
Expand All @@ -368,12 +371,14 @@ def prettyProfile(acct):
]
if acct["fields"]:
body.extend(["", "Fields:"]+[x["name"]+":\t"+x["value"] for x in acct["fields"]])
ret=[fillInDomain(acct["acct"]), acct["display_name"], locked+discoverable+bot, body, str(acct["created_at"]), False, True]
ret=[fillInDomain(acct["acct"]), acct["display_name"], locked+discoverable+bot, displayName, body, str(acct["created_at"]), False, True]
return [acct["id"], ret]

def drawSelectionMenuItem(i, selected, username, displayName, cw, content, date, seen, isCWOpen):
drawMsgPanel(i, username, cw, content, date, seen)
def drawSelectionMenuItem(i, selected, tid, username, displayName, cw, shortContent, content, date, seen, isCWOpen):
drawMsgPanel(i, username, cw, shortContent, date, seen)
if selected:
if not tid in seen_toots:
seen_toots.append(tid)
drawSelectedMsg(username, displayName, cw, content, isCWOpen)
def selectMatches(l):
return []
Expand Down Expand Up @@ -552,7 +557,7 @@ def execCommand(cmd):
except Exception as e: statusMsg(str(e))
elif cmd=="import_history":
(tlIdx, hlIdx) = [0]*2
drawPanelContents(tl, hlIdx)
drawPanelContents(prettyToots(tl), hlIdx)
tl=importHistory(verbose=True)
if hlIdx+tlIdx<0:(hlIdx, tlIdx)=[0]*2
position=hlIdx+tlIdx
Expand Down Expand Up @@ -636,7 +641,7 @@ def importHistory(src="all", verbose=False):
for s in src:
ret=importHistory([s], verbose)+ret
if verbose:
drawPanelContents(ret, 0)
drawPanelContents(prettyToots(ret), 0)
return ret
src=str(src[0])
if src=="all":
Expand Down Expand Up @@ -784,7 +789,7 @@ def loadBase():
######################## MAIN
def mainloop():
global hlIdx, tl, commandKeys, tlIdx, ROWS, COLS
drawPanelContents(tl[tlIdx:], hlIdx)
drawPanelContents(prettyToots(tl[tlIdx:]), hlIdx)
key=scr.getch()
if key==curses.KEY_RESIZE:
ROWS, COLS = scr.getmaxyx()
Expand Down

0 comments on commit 4594bf4

Please sign in to comment.