Update check_valid_message and fix bugs copy latex
This commit is contained in:
parent
bb5b563431
commit
dbea1d0968
2 changed files with 23 additions and 21 deletions
|
@ -182,20 +182,21 @@ def check_valid_message(request, room):
|
|||
return False
|
||||
|
||||
try:
|
||||
last_msg_all = Message.objects.filter(room=room).latest("time")
|
||||
except Message.DoesNotExist:
|
||||
last_msg_all = None
|
||||
|
||||
if last_msg_all and last_msg_all.body == request.POST["body"].strip():
|
||||
last_msg = Message.objects.filter(room=room).first()
|
||||
if (
|
||||
last_msg.author == request.profile
|
||||
and last_msg.body == request.POST["body"].strip()
|
||||
):
|
||||
return False
|
||||
except Message.DoesNotExist:
|
||||
pass
|
||||
|
||||
if not room:
|
||||
four_last_msg = Message.objects.filter(
|
||||
author=request.profile, room=room
|
||||
).order_by("-time")[:4]
|
||||
four_last_msg = Message.objects.filter(room=room).order_by("-id")[:4]
|
||||
if len(four_last_msg) >= 4:
|
||||
same_author = all(msg.author == request.profile for msg in four_last_msg)
|
||||
time_diff = timezone.now() - four_last_msg[3].time
|
||||
if time_diff.total_seconds() < 15:
|
||||
if same_author and time_diff.total_seconds() < 300:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
@ -207,7 +208,7 @@ def post_message(request):
|
|||
|
||||
if request.method != "POST":
|
||||
return HttpResponseBadRequest()
|
||||
if len(request.POST["body"]) > 5000:
|
||||
if len(request.POST["body"]) > 5000 or len(request.POST["body"].strip()) == 0:
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
room = None
|
||||
|
|
|
@ -36,8 +36,7 @@
|
|||
$('#chat-log').prepend(data);
|
||||
}
|
||||
|
||||
register_time($('.time-with-rel'));
|
||||
merge_authors();
|
||||
postProcessMessages();
|
||||
|
||||
if (!refresh_html) {
|
||||
$chat_box.scrollTop(scrollTopOfBottom($chat_box) - lastMsgPos);
|
||||
|
@ -51,6 +50,13 @@
|
|||
})
|
||||
}
|
||||
|
||||
function postProcessMessages() {
|
||||
register_time($('.time-with-rel'));
|
||||
MathJax.typeset();
|
||||
populateCopyButton();
|
||||
merge_authors();
|
||||
}
|
||||
|
||||
function scrollTopOfBottom(container) {
|
||||
return container[0].scrollHeight - container.innerHeight()
|
||||
}
|
||||
|
@ -111,10 +117,7 @@
|
|||
|
||||
$('#chat-log').append($data);
|
||||
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
||||
register_time($('.time-with-rel'));
|
||||
MathJax.typeset();
|
||||
populateCopyButton();
|
||||
merge_authors();
|
||||
postProcessMessages();
|
||||
}
|
||||
|
||||
function add_new_message(message, room, is_self_author) {
|
||||
|
@ -167,11 +170,8 @@
|
|||
else {
|
||||
add_new_message(message, room, true);
|
||||
}
|
||||
MathJax.typeset();
|
||||
populateCopyButton();
|
||||
register_time($('.time-with-rel'));
|
||||
remove_unread_current_user();
|
||||
merge_authors();
|
||||
postProcessMessages();
|
||||
},
|
||||
error: function (data) {
|
||||
console.log('Fail to check message');
|
||||
|
@ -310,8 +310,9 @@
|
|||
load_next_page(null, true);
|
||||
update_last_seen();
|
||||
refresh_status(true);
|
||||
$('#chat-input').focus();
|
||||
|
||||
show_right_panel();
|
||||
$('#chat-input').focus();
|
||||
$('#chat-input').val('').trigger('input');
|
||||
}
|
||||
window.lock_click_space = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue