Browse Source

完成基本功能

master
欧醚 3 years ago
parent
commit
d8daeff8fc
2 changed files with 54 additions and 5 deletions
  1. +20
    -3
      ask.py
  2. +34
    -2
      templates/inbox.html

+ 20
- 3
ask.py View File

@ -116,8 +116,7 @@ def inbox(acct, secr):
@app.route('/askMe/<acct>/<secr>/new', methods=['POST'])
def new_question(acct, secr):
u = User.query.filter_by(acct=acct, secr=secr).first()
if not u:
if not User.query.filter_by(acct=acct, secr=secr).first():
abort(404)
content = request.form.get('question')
@ -126,7 +125,7 @@ def new_question(acct, secr):
abort(422)
toot = th.status_post(f"@{acct} 叮~ 有新提问了 回复“删除”以永久删除该提问(第一次被点开时实际执行删除),回复其他均视为回答该提问。可以回复多条,可以随时删除/重新编辑你的回复,可以@其他社友加入对话\n\n{content}", visibility='direct')
toot = th.status_post(f"@{acct} 叮~ 有新提问 (戳我头像了解如何回复) \n\n{content}", visibility='direct')
if not toot:
abort(500)
@ -138,5 +137,23 @@ def new_question(acct, secr):
return redirect(".")
@app.route('/askMe/<acct>/<secr>/<int:toot>')
def question_info(acct, secr, toot):
if not User.query.filter_by(acct=acct, secr=secr).first() or not Question.query.filter_by(acct=acct, toot=toot):
abort(404)
context = th.status_context(toot)
replies = [
{
'disp': t.account.display_name,
'url': t.account.url,
'content': h2t.handle(t.content).replace(BOT_NAME,'').strip(),
'time': str(t.created_at)
}
for t in context.descendants
]
print(replies)
return {'replies': replies}
if __name__ == '__main__':
app.run(debug=True)

+ 34
- 2
templates/inbox.html View File

@ -18,6 +18,19 @@
border-radius: .5rem;
margin: 25px 0;
}
pre {
margin: 15px 0 0 15px;
}
.timeago {
font-size: 0.5em;
text-align: right;
}
.display_name {
margin: 0;
}
.card-body {
padding: 0.75em;
}
</style>
</head>
<body style="background-color: #001a37;color:#e8e8e8">
@ -53,7 +66,7 @@
<div class="qbox">
<pre>{{q.content}}</pre>
<div style="text-align:right">
<time class="timeago" datetime="{{q.time}}">{{q.time}}</time>
<time class="timeago" datetime="{{q.time}}"></time>
<a class="btn btn-link request-answer" data-toggle="collapse" href="#collapse-{{q.toot}}" role="button" aria-expanded="false" aria-controls="collapse-{{q.toot}}">
查看回复
<span><svg fill="#007bff" viewBox="0 0 24 24" width="24" height="24" ><path d="M12 13L8.285 9.218a.758.758 0 0 0-1.064 0 .738.738 0 0 0 0 1.052l4.249 4.512a.758.758 0 0 0 1.064 0l4.246-4.512a.738.738 0 0 0 0-1.052.757.757 0 0 0-1.063 0L12.002 13z" style="animation: downn 1.5s infinite;" "=""></path></svg></span>
@ -70,7 +83,26 @@
<script>
$('.timeago').timeago();
$('.collapse').on('show.bs.collapse', (e) => {
console.log(e.target.id.split('-')[1]);
let self = e.target;
let toot = self.id.split('-')[1];
$.ajax({
type:'GET',
url:toot,
success:(result,status,xhr) => {
console.log(result+' : '+status);
if(result.replies.length) {
$(self).empty();
result.replies.forEach((rp) => {
$(self).append(`<div class="card card-body"><p class="display_name"><a href="${rp.url}">${rp.disp}</a>:</p><pre>${rp.content}</pre><time class="timeago" datetime="${rp.time}"></time></div>`)
});
console.log($(self).find('.timeago'));
$(self).find('.timeago').timeago();
}
},
error:(xhr,status,error) => {
console.log(error+' : '+status);
}
});
});
</script>

Loading…
Cancel
Save