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
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
last_msg_all = Message.objects.filter(room=room).latest("time")
|
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:
|
except Message.DoesNotExist:
|
||||||
last_msg_all = None
|
pass
|
||||||
|
|
||||||
if last_msg_all and last_msg_all.body == request.POST["body"].strip():
|
|
||||||
return False
|
|
||||||
|
|
||||||
if not room:
|
if not room:
|
||||||
four_last_msg = Message.objects.filter(
|
four_last_msg = Message.objects.filter(room=room).order_by("-id")[:4]
|
||||||
author=request.profile, room=room
|
|
||||||
).order_by("-time")[:4]
|
|
||||||
if len(four_last_msg) >= 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
|
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 False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -207,7 +208,7 @@ def post_message(request):
|
||||||
|
|
||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
if len(request.POST["body"]) > 5000:
|
if len(request.POST["body"]) > 5000 or len(request.POST["body"].strip()) == 0:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
room = None
|
room = None
|
||||||
|
|
|
@ -36,8 +36,7 @@
|
||||||
$('#chat-log').prepend(data);
|
$('#chat-log').prepend(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
register_time($('.time-with-rel'));
|
postProcessMessages();
|
||||||
merge_authors();
|
|
||||||
|
|
||||||
if (!refresh_html) {
|
if (!refresh_html) {
|
||||||
$chat_box.scrollTop(scrollTopOfBottom($chat_box) - lastMsgPos);
|
$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) {
|
function scrollTopOfBottom(container) {
|
||||||
return container[0].scrollHeight - container.innerHeight()
|
return container[0].scrollHeight - container.innerHeight()
|
||||||
}
|
}
|
||||||
|
@ -111,10 +117,7 @@
|
||||||
|
|
||||||
$('#chat-log').append($data);
|
$('#chat-log').append($data);
|
||||||
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
||||||
register_time($('.time-with-rel'));
|
postProcessMessages();
|
||||||
MathJax.typeset();
|
|
||||||
populateCopyButton();
|
|
||||||
merge_authors();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_new_message(message, room, is_self_author) {
|
function add_new_message(message, room, is_self_author) {
|
||||||
|
@ -167,11 +170,8 @@
|
||||||
else {
|
else {
|
||||||
add_new_message(message, room, true);
|
add_new_message(message, room, true);
|
||||||
}
|
}
|
||||||
MathJax.typeset();
|
|
||||||
populateCopyButton();
|
|
||||||
register_time($('.time-with-rel'));
|
|
||||||
remove_unread_current_user();
|
remove_unread_current_user();
|
||||||
merge_authors();
|
postProcessMessages();
|
||||||
},
|
},
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
console.log('Fail to check message');
|
console.log('Fail to check message');
|
||||||
|
@ -310,8 +310,9 @@
|
||||||
load_next_page(null, true);
|
load_next_page(null, true);
|
||||||
update_last_seen();
|
update_last_seen();
|
||||||
refresh_status(true);
|
refresh_status(true);
|
||||||
$('#chat-input').focus();
|
|
||||||
show_right_panel();
|
show_right_panel();
|
||||||
|
$('#chat-input').focus();
|
||||||
$('#chat-input').val('').trigger('input');
|
$('#chat-input').val('').trigger('input');
|
||||||
}
|
}
|
||||||
window.lock_click_space = true;
|
window.lock_click_space = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue