diff --git a/files/routes/chat.py b/files/routes/chat.py index d5c32ee7c..57892b816 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -1,6 +1,8 @@ from files.helpers.const import SITE -if SITE=='pcmemes.net': +if SITE in ('pcmemes.net', 'localhost'): + count = 0 + import time from files.helpers.wrappers import auth_required from files.helpers.sanitize import sanitize @@ -10,15 +12,14 @@ if SITE=='pcmemes.net': from flask import render_template import sys + socketio = SocketIO(app, async_mode='gevent') + @app.get("/chat") @auth_required def chat( v): return render_template("chat.html", v=v) - - sex = SocketIO(app, async_mode='gevent') - - @sex.on('speak') + @socketio.on('speak') @auth_required def speak(data, v): @@ -27,9 +28,20 @@ if SITE=='pcmemes.net': "username":v.username, "namecolor":v.namecolor, "text":sanitize(data[:1000].strip()), - "time": time.strftime("%d %b %Y at %H:%M:%S", time.gmtime(int(time.time()))), - "userlink":v.url + "time": time.strftime("%d %b %Y at %H:%M:%S", time.gmtime(int(time.time()))) } emit('speak', data, broadcast=True) - return '', 204 \ No newline at end of file + return '', 204 + + @socketio.on('connect') + def connect(): + global count + count += 1 + emit("count", count) + + @socketio.on('disconnect') + def disconnect(): + global count + count -= 1 + emit("count", count) \ No newline at end of file diff --git a/files/routes/users.py b/files/routes/users.py index c0405b7b0..b5a9fc523 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -89,7 +89,7 @@ def upvoters_posts(v, username, uid): page = max(1, int(request.values.get("page", 1))) - listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==False, Vote.vote_type==1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() listing = [p.id for p in listing] next_exists = len(listing) > 25 @@ -108,7 +108,7 @@ def upvoters_comments(v, username, uid): page = max(1, int(request.values.get("page", 1))) - listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==False, CommentVote.vote_type==1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() listing = [c.id for c in listing] next_exists = len(listing) > 25 @@ -126,7 +126,7 @@ def downvoters_posts(v, username, uid): uid = int(uid) page = max(1, int(request.values.get("page", 1))) - listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + listing = g.db.query(Submission).join(Vote, Vote.submission_id==Submission.id).filter(Submission.ghost==False, Vote.vote_type==-1, Submission.author_id==id, Vote.user_id==uid).order_by(Submission.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() listing = [p.id for p in listing] next_exists = len(listing) > 25 @@ -144,7 +144,7 @@ def downvoters_comments(v, username, uid): uid = int(uid) page = max(1, int(request.values.get("page", 1))) - listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() + listing = g.db.query(Comment).join(CommentVote, CommentVote.comment_id==Comment.id).filter(Comment.ghost==False, CommentVote.vote_type==-1, Comment.author_id==id, CommentVote.user_id==uid).order_by(Comment.created_utc.desc()).offset(25 * (page - 1)).limit(26).all() listing = [c.id for c in listing] next_exists = len(listing) > 25 diff --git a/files/templates/chat.html b/files/templates/chat.html index c9afe85d7..d8284de51 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -7,6 +7,13 @@ {% block content %} +
+ + + 0 + +
+
@@ -42,12 +49,12 @@
- +
- +