forked from rDrama/rDrama
stop online and typing from hanging
parent
6bb36de5d4
commit
57b60e9128
|
@ -186,22 +186,25 @@ ta.addEventListener("keydown", function(e) {
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('online', function(data){
|
socket.on('online', function(data){
|
||||||
document.getElementsByClassName('board-chat-count')[0].innerHTML = data[0].length
|
const online_li = Object.entries(data[0])
|
||||||
document.getElementById('chat-count-header-bar').innerHTML = data[0].length
|
const muted_li = Object.keys(data[1])
|
||||||
|
|
||||||
|
document.getElementsByClassName('board-chat-count')[0].innerHTML = online_li.length
|
||||||
|
document.getElementById('chat-count-header-bar').innerHTML = online_li.length
|
||||||
const admin_level = parseInt(document.getElementById('admin_level').value)
|
const admin_level = parseInt(document.getElementById('admin_level').value)
|
||||||
let online = ''
|
let online = ''
|
||||||
let online2 = '<b>Users Online</b>'
|
let online2 = '<b>Users Online</b>'
|
||||||
for (const u of data[0])
|
for (const [k, val] of online_li)
|
||||||
{
|
{
|
||||||
let patron = ''
|
let patron = ''
|
||||||
if (u[3])
|
if (val[3])
|
||||||
patron = ` class="patron" style="background-color:#${u[2]}"`
|
patron = ` class="patron" style="background-color:#${val[2]}"`
|
||||||
|
|
||||||
online += `<li>`
|
online += `<li>`
|
||||||
if (admin_level && Object.keys(data[1]).includes(u[1].toLowerCase()))
|
if (admin_level && muted_li.includes(val[1].toLowerCase()))
|
||||||
online += '<b class="text-danger muted" data-bs-toggle="tooltip" title="Muted">X</b> '
|
online += '<b class="text-danger muted" data-bs-toggle="tooltip" title="Muted">X</b> '
|
||||||
online += `<a class="font-weight-bold" target="_blank" href="/@${u[1]}" style="color:#${u[2]}"><img loading="lazy" class="mr-1" src="/pp/${u[0]}"><span${patron}>${u[1]}</span></a></li>`
|
online += `<a class="font-weight-bold" target="_blank" href="/@${val[1]}" style="color:#${val[2]}"><img loading="lazy" class="mr-1" src="/pp/${k}"><span${patron}>${val[1]}</span></a></li>`
|
||||||
online2 += `<br>@${u[1]}`
|
online2 += `<br>@${val[1]}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const online_el = document.getElementById('online')
|
const online_el = document.getElementById('online')
|
||||||
|
@ -311,6 +314,12 @@ document.onpaste = function(event) {
|
||||||
handle_files()
|
handle_files()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function send_hearbeat() {
|
||||||
|
socket.emit('heartbeat')
|
||||||
|
}
|
||||||
|
send_hearbeat()
|
||||||
|
setInterval(send_hearbeat, 3600000);
|
||||||
|
|
||||||
box.scrollTo(0, box.scrollHeight)
|
box.scrollTo(0, box.scrollHeight)
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
box.scrollTo(0, box.scrollHeight)
|
box.scrollTo(0, box.scrollHeight)
|
||||||
|
|
|
@ -39,7 +39,7 @@ typing = {
|
||||||
f'{SITE_FULL}/chat': [],
|
f'{SITE_FULL}/chat': [],
|
||||||
}
|
}
|
||||||
online = {
|
online = {
|
||||||
f'{SITE_FULL}/chat': [],
|
f'{SITE_FULL}/chat': {},
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.set('loggedin_chat', len(online[f'{SITE_FULL}/chat']), timeout=0)
|
cache.set('loggedin_chat', len(online[f'{SITE_FULL}/chat']), timeout=0)
|
||||||
|
@ -194,14 +194,16 @@ def speak(data, v):
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
def refresh_online():
|
def refresh_online():
|
||||||
|
for li in online.values():
|
||||||
|
for entry in li.values():
|
||||||
|
if time.time() > entry[0]:
|
||||||
|
del li[entry]
|
||||||
|
if entry[1] in typing[g.referrer]:
|
||||||
|
typing[g.referrer].remove(entry[1])
|
||||||
|
|
||||||
emit("online", [online[g.referrer], muted], room=g.referrer, broadcast=True)
|
emit("online", [online[g.referrer], muted], room=g.referrer, broadcast=True)
|
||||||
cache.set('loggedin_chat', len(online[f'{SITE_FULL}/chat']), timeout=0)
|
cache.set('loggedin_chat', len(online[f'{SITE_FULL}/chat']), timeout=0)
|
||||||
|
|
||||||
def remove_from_online(v):
|
|
||||||
for li in online.values():
|
|
||||||
for entry in li:
|
|
||||||
if entry[0] == v.id:
|
|
||||||
li.remove(entry)
|
|
||||||
|
|
||||||
@socketio.on('connect')
|
@socketio.on('connect')
|
||||||
@auth_required_socketio
|
@auth_required_socketio
|
||||||
|
@ -215,20 +217,19 @@ def connect(v):
|
||||||
|
|
||||||
join_room(g.referrer)
|
join_room(g.referrer)
|
||||||
|
|
||||||
remove_from_online(v)
|
|
||||||
|
|
||||||
online[g.referrer].append([v.id, v.username, v.name_color, v.patron])
|
|
||||||
|
|
||||||
refresh_online()
|
|
||||||
|
|
||||||
emit('typing', typing[g.referrer], room=g.referrer)
|
emit('typing', typing[g.referrer], room=g.referrer)
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@socketio.on('disconnect')
|
@socketio.on('disconnect')
|
||||||
@auth_required_socketio
|
@auth_required_socketio
|
||||||
def disconnect(v):
|
def disconnect(v):
|
||||||
if g.referrer != f'{SITE_FULL}/notifications/messages':
|
for dictionary in online.values():
|
||||||
remove_from_online(v)
|
dictionary.pop(v.id, None)
|
||||||
|
|
||||||
|
if v.username in typing[g.referrer]:
|
||||||
|
typing[g.referrer].remove(v.username)
|
||||||
|
|
||||||
if g.referrer not in ALLOWED_REFERRERS:
|
if g.referrer not in ALLOWED_REFERRERS:
|
||||||
return '', 400
|
return '', 400
|
||||||
|
@ -240,6 +241,16 @@ def disconnect(v):
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
@socketio.on('heartbeat')
|
||||||
|
@auth_required_socketio
|
||||||
|
def heartbeat(v):
|
||||||
|
if g.referrer not in ALLOWED_REFERRERS:
|
||||||
|
return '', 400
|
||||||
|
expire_utc = int(time.time()) + 3610
|
||||||
|
online[g.referrer][v.id] = (expire_utc, v.username, v.name_color, v.patron)
|
||||||
|
refresh_online()
|
||||||
|
return '', 204
|
||||||
|
|
||||||
@socketio.on('typing')
|
@socketio.on('typing')
|
||||||
@is_not_banned_socketio
|
@is_not_banned_socketio
|
||||||
def typing_indicator(data, v):
|
def typing_indicator(data, v):
|
||||||
|
|
Loading…
Reference in New Issue