Add author only viewing option

This commit is contained in:
John Xina 2023-07-13 20:06:44 +08:00
parent dd16ffe357
commit ac0da85e5c
2 changed files with 15 additions and 7 deletions

6
app.py
View File

@ -104,11 +104,13 @@ async def _jinja2_filter_translate(frags, reply_id=0):
async def thread_view(tid): async def thread_view(tid):
tid = int(tid) tid = int(tid)
pn = int(request.args.get('pn') or 1) pn = int(request.args.get('pn') or 1)
ao = int(request.args.get('ao') or 0)
async with aiotieba.Client() as tieba: async with aiotieba.Client() as tieba:
# Default to 15 posts per page, confirm to tieba.baidu.com # Default to 15 posts per page, confirm to tieba.baidu.com
thread_info = await tieba.get_posts(tid, rn=15, pn=pn, thread_info = await tieba.get_posts(tid, rn=15, pn=pn,
with_comments=should_fetch_comments) with_comments=should_fetch_comments,
only_thread_author=ao)
available_users = [] available_users = []
for floor in thread_info: for floor in thread_info:
@ -125,7 +127,7 @@ async def thread_view(tid):
await asyncio.gather(*(cache_name_from_id(tieba, i) for i in all_users)) await asyncio.gather(*(cache_name_from_id(tieba, i) for i in all_users))
return await render_template('thread.html', info=thread_info) return await render_template('thread.html', info=thread_info, ao=ao)
@app.route('/f') @app.route('/f')
async def forum_view(): async def forum_view():

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<title>{{ info.thread.text }} - 自由软件吧 - RAT</title> <title>{{ info.thread.text }}{{ ao }} - 自由软件吧 - RAT</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="referrer" content="never"> <meta name="referrer" content="never">
@ -14,6 +14,12 @@
<div class="title">{{ info.thread.title }}</div> <div class="title">{{ info.thread.title }}</div>
<div class="from"><a href="/f?kw={{ info.forum.fname }}">{{ info.forum.fname }}吧</a></div> <div class="from"><a href="/f?kw={{ info.forum.fname }}">{{ info.forum.fname }}吧</a></div>
</header> </header>
<div class="list">
<div class="vlist">
<div><a {% if not ao %} class="current-sel" {% endif %} href="/p/{{ info.thread.tid }}?ao=0">全部回复</a></div>
<div><a {% if ao %} class="current-sel" {% endif %} href="/p/{{ info.thread.tid }}?ao=1">仅看楼主</a></div>
</div>
</div>
<div class="list"> <div class="list">
{% for p in info %} {% for p in info %}
<div class="post" id="{{ p.floor }}"> <div class="post" id="{{ p.floor }}">
@ -61,13 +67,13 @@
<div class="paginator"> <div class="paginator">
{% if info.page.current_page > 1 %} {% if info.page.current_page > 1 %}
<a href="/p/{{ info.thread.tid }}">首页</a> <a href="/p/{{ info.thread.tid }}&ao={{ao}}">首页</a>
{% endif %} {% endif %}
{% for i in range(5) %} {% for i in range(5) %}
{% set np = info.page.current_page - 5 + i %} {% set np = info.page.current_page - 5 + i %}
{% if np > 0 %} {% if np > 0 %}
<a href="/p/{{ info.thread.tid }}?pn={{ np }}">{{ np }}</a> <a href="/p/{{ info.thread.tid }}?pn={{ np }}&ao={{ao}}">{{ np }}</a>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -76,12 +82,12 @@
{% for i in range(5) %} {% for i in range(5) %}
{% set np = info.page.current_page + 1 + i %} {% set np = info.page.current_page + 1 + i %}
{% if np <= info.page.total_page %} {% if np <= info.page.total_page %}
<a href="/p/{{ info.thread.tid }}?pn={{ np }}">{{ np }}</a> <a href="/p/{{ info.thread.tid }}?pn={{ np }}&ao={{ao}}">{{ np }}</a>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if info.page.current_page < info.page.total_page %} {% if info.page.current_page < info.page.total_page %}
<a href="/p/{{ info.thread.tid }}?pn={{ info.page.total_page }}">尾页</a> <a href="/p/{{ info.thread.tid }}?pn={{ info.page.total_page }}&ao={{ao}}">尾页</a>
{% endif %} {% endif %}
</div> </div>