Retro Bulletin Board Systems on atproto. Web app and TUI. lazy mirror of alyraffauf/atbbs atbbs.xyz
forums python tui atproto bbs
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

tui: add sysop hide/ban actions

+59 -2
+59 -2
tui/screens/thread.py
··· 6 6 from textual.widgets import Footer, Static 7 7 8 8 from core import lexicon 9 - from core.models import AtUri, AuthError, BBS, Thread 10 - from core.records import delete_record, hydrate_replies as fetch_replies 9 + from core.models import BBS, AtUri, AuthError, Thread 10 + from core.records import create_ban_record, create_hidden_record, delete_record 11 + from core.records import hydrate_replies as fetch_replies 11 12 from tui.screens.compose import ComposeReplyScreen 12 13 from tui.util import require_session 13 14 from tui.widgets.breadcrumb import Breadcrumb ··· 22 23 Binding("[", "prev_page", "prev page"), 23 24 Binding("]", "next_page", "next page"), 24 25 Binding("ctrl+s", "save_attachment", "save attachments", show=False), 26 + Binding("ctrl+h", "hide", "hide post", show=False), 27 + Binding("ctrl+b", "ban", "ban user", show=False), 25 28 ] 26 29 27 30 def __init__(self, bbs: BBS, handle: str, thread: Thread) -> None: ··· 128 131 replies = [p for p in self.query(Post) if p.collection == lexicon.REPLY] 129 132 if replies: 130 133 replies[0].focus() 134 + 135 + def action_ban(self) -> None: 136 + session = self.app.user_session 137 + if not session or session["did"] != self.bbs.identity.did: 138 + self.notify("User not authorized.", severity="error") 139 + return 140 + focused = self.focused 141 + if not isinstance(focused, Post) or not focused.author_did: 142 + return 143 + if focused.author_did == session["did"]: 144 + self.notify("Cannot ban yourself.", severity="warning") 145 + return 146 + self._do_ban(focused.author_did) 147 + 148 + @work 149 + async def _do_ban(self, did: str) -> None: 150 + session = self.app.user_session 151 + store = self.app.session_store 152 + 153 + async def updater(d, field, value): 154 + store.update_session_field(d, field, value) 155 + 156 + try: 157 + await create_ban_record(self.app.http_client, session, did, updater) 158 + self.notify(f"Banned {did}.") 159 + except Exception: 160 + self.notify("Could not ban user.", severity="error") 161 + 162 + def action_hide(self) -> None: 163 + session = self.app.user_session 164 + if not session or session["did"] != self.bbs.identity.did: 165 + self.notify("User not authorized.", severity="error") 166 + return 167 + focused = self.focused 168 + if not isinstance(focused, Post) or not focused.record_uri: 169 + return 170 + self._do_hide(focused) 171 + 172 + @work 173 + async def _do_hide(self, post: Post) -> None: 174 + session = self.app.user_session 175 + store = self.app.session_store 176 + 177 + async def updater(d, field, value): 178 + store.update_session_field(d, field, value) 179 + 180 + try: 181 + await create_hidden_record( 182 + self.app.http_client, session, post.record_uri, updater 183 + ) 184 + await post.remove() 185 + self.notify("Post hidden.") 186 + except Exception: 187 + self.notify("Could not hide post.", severity="error") 131 188 132 189 def action_next_page(self) -> None: 133 190 if self._page < self._total_pages: