Aevann 2024-07-13 14:10:46 +03:00
parent 11da0c714d
commit 5482495f0f
7 changed files with 56 additions and 10 deletions

View File

@ -851,12 +851,6 @@ class User(Base):
@property @property
@lazy @lazy
def chats_notifications_count(self): def chats_notifications_count(self):
if self.id == AEVANN_ID and SITE == 'rdrama.net':
return g.db.query(ChatMembership).filter(
ChatMembership.user_id == self.id,
ChatMembership.notification == True,
ChatMembership.chat_id.notin_((12,219,320,360,379,395,427,448,454,471)),
).count()
return g.db.query(ChatMembership).filter_by(user_id=self.id, notification=True).count() return g.db.query(ChatMembership).filter_by(user_id=self.id, notification=True).count()
@property @property

View File

@ -67,6 +67,8 @@ def chat(v, chat_id):
if not chat: if not chat:
abort(404, "Chat not found!") abort(404, "Chat not found!")
muting_chat = False
if chat.id == 1: if chat.id == 1:
if not v.allowed_in_chat: if not v.allowed_in_chat:
abort(403, f"To prevent spam, you'll need {TRUESCORE_MINIMUM} truescore (this is {TRUESCORE_MINIMUM} votes, either up or down, on any threads or comments you've made) in order to access chat. Sorry! I love you 💖") abort(403, f"To prevent spam, you'll need {TRUESCORE_MINIMUM} truescore (this is {TRUESCORE_MINIMUM} votes, either up or down, on any threads or comments you've made) in order to access chat. Sorry! I love you 💖")
@ -74,6 +76,7 @@ def chat(v, chat_id):
membership = g.db.query(ChatMembership).filter_by(user_id=v.id, chat_id=chat_id).one_or_none() membership = g.db.query(ChatMembership).filter_by(user_id=v.id, chat_id=chat_id).one_or_none()
if v.admin_level < PERMS['VIEW_CHATS'] and not membership: if v.admin_level < PERMS['VIEW_CHATS'] and not membership:
abort(403, "You're not a member of this chat!") abort(403, "You're not a member of this chat!")
muting_chat = (membership.notification == None)
displayed_messages = g.db.query(ChatMessage).options(joinedload(ChatMessage.quoted_message)).filter(ChatMessage.chat_id == chat.id) displayed_messages = g.db.query(ChatMessage).options(joinedload(ChatMessage.quoted_message)).filter(ChatMessage.chat_id == chat.id)
@ -87,6 +90,7 @@ def chat(v, chat_id):
sorted_memberships = None sorted_memberships = None
else: else:
if not session.get("GLOBAL") and membership: if not session.get("GLOBAL") and membership:
if membership.notification:
membership.notification = False membership.notification = False
membership.mentions = 0 membership.mentions = 0
g.db.add(membership) g.db.add(membership)
@ -103,9 +107,9 @@ def chat(v, chat_id):
orgy = get_running_orgy(v, chat_id) orgy = get_running_orgy(v, chat_id)
if orgy: if orgy:
orgies = g.db.query(Orgy).filter_by(chat_id=chat_id).order_by(Orgy.start_utc).all() orgies = g.db.query(Orgy).filter_by(chat_id=chat_id).order_by(Orgy.start_utc).all()
return render_template("orgy.html", v=v, messages=displayed_messages, chat=chat, sorted_memberships=sorted_memberships, orgy=orgy, orgies=orgies) return render_template("orgy.html", v=v, messages=displayed_messages, chat=chat, sorted_memberships=sorted_memberships, muting_chat=muting_chat, orgy=orgy, orgies=orgies)
return render_template("chat.html", v=v, messages=displayed_messages, chat=chat, sorted_memberships=sorted_memberships) return render_template("chat.html", v=v, messages=displayed_messages, chat=chat, sorted_memberships=sorted_memberships, muting_chat=muting_chat)
@app.post("/chat/<int:chat_id>/name") @app.post("/chat/<int:chat_id>/name")
@ -151,6 +155,31 @@ def leave_chat(v, chat_id):
return {"message": "Chat left successfully!"} return {"message": "Chat left successfully!"}
@app.post("/chat/<int:chat_id>/toggle_mute")
@limiter.limit('1/second', scope=rpath)
@limiter.limit('1/second', scope=rpath, key_func=get_ID)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def mute_chat(v, chat_id):
chat = g.db.get(Chat, chat_id)
if not chat:
abort(404, "Chat not found!")
membership = g.db.query(ChatMembership).filter_by(user_id=v.id, chat_id=chat_id).one_or_none()
if not membership:
abort(400, "You're not a member of this chat!")
if membership.notification == None:
membership.notification = False
msg = "Chat unmuted successfully (yayyy)"
else:
membership.notification = None
msg = "Chat muted successfully (die)"
g.db.add(membership)
return {"message": msg}
@app.get("/chat/<int:chat_id>/orgies") @app.get("/chat/<int:chat_id>/orgies")
@auth_required @auth_required

View File

@ -28,6 +28,10 @@
</form> </form>
<a href="/chat/{{chat.id}}/orgies" class="orgy-control fas fa-tv text-muted ml-2"></a> <a href="/chat/{{chat.id}}/orgies" class="orgy-control fas fa-tv text-muted ml-2"></a>
{% else %}
<button class="px-2" type="button" data-nonce="{{g.nonce}}" data-bs-toggle="tooltip" title="{% if muting_chat %}Unmute{% else %}Mute (don't do it){% endif %}" data-nonce="{{g.nonce}}" data-onclick="postToastReload(this, '/chat/{{chat.id}}/toggle_mute')">
<i class="fas fa-bell-slash {% if muting_chat %}text-danger{% else %}text-muted{% endif %}"></i>
</button>
{% endif %} {% endif %}
<button id="leave-private-chat" type="submit" class="btn btn-danger fl-r mt-1 mt-md-2 pt-0 px-2 text-small-sm" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="postToastReload(this, '/chat/{{chat.id}}/leave')">Leave</button> <button id="leave-private-chat" type="submit" class="btn btn-danger fl-r mt-1 mt-md-2 pt-0 px-2 text-small-sm" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="postToastReload(this, '/chat/{{chat.id}}/leave')">Leave</button>
@ -82,6 +86,10 @@
<img class="ml-1 chat-owner" data-bs-toggle="tooltip" alt="Owner" title="Owner" src="{{SITE_FULL_IMAGES}}/e/marseykingretard.webp"> <img class="ml-1 chat-owner" data-bs-toggle="tooltip" alt="Owner" title="Owner" src="{{SITE_FULL_IMAGES}}/e/marseykingretard.webp">
{% endif %} {% endif %}
{% if membership.notification == None %}
<i class="fas fa-bell-slash text-danger" data-bs-toggle="tooltip" title="Muting chat{% if v.id == membership.user_id %} (kys){% elif v.id == chat.owner_id %} (kick him){% endif %}"></i>
{% endif %}
<i class="d-none ml-1 text-smaller text-success online-marker online-marker-{{user.id}} fas fa-circle"></i> <i class="d-none ml-1 text-smaller text-success online-marker online-marker-{{user.id}} fas fa-circle"></i>
</li> </li>
{% endfor %} {% endfor %}

View File

@ -541,6 +541,10 @@
<img class="ml-1 chat-owner" data-bs-toggle="tooltip" alt="Owner" title="Owner" src="{{SITE_FULL_IMAGES}}/e/marseykingretard.webp"> <img class="ml-1 chat-owner" data-bs-toggle="tooltip" alt="Owner" title="Owner" src="{{SITE_FULL_IMAGES}}/e/marseykingretard.webp">
{% endif %} {% endif %}
{% if membership.notification == None %}
<i class="fas fa-bell-slash text-danger" data-bs-toggle="tooltip" title="Muting chat{% if v.id == membership.user_id %} (kys){% elif v.id == chat.owner_id %} (kick him){% endif %}"></i>
{% endif %}
<i class="d-none ml-1 text-smaller text-success online-marker online-marker-{{user.id}} fas fa-circle"></i> <i class="d-none ml-1 text-smaller text-success online-marker online-marker-{{user.id}} fas fa-circle"></i>
</li> </li>
{% endfor %} {% endfor %}

View File

@ -74,9 +74,11 @@
{% endif %} {% endif %}
{% if notification %} {% if notification %}
<i class="fas fa-circle ml-2 text-small" style="color:#008080"></i> <i class="fas fa-circle ml-2 text-small" style="color:#008080"></i>
{% elif notification == None %}
<i class="fas fa-bell-slash ml-2 text-danger" data-bs-toggle="tooltip" title="Muted (just leave bro)"></i>
{% endif %} {% endif %}
{% if get_running_orgy(v, chat.id) %} {% if get_running_orgy(v, chat.id) %}
<i class="fas fa-tv ml-2 text-small" style="color:#008080"></i> <i class="fas fa-tv ml-2 text-small" style="color:#008080" data-bs-toggle="tooltip" title="Orgy running"></i>
{% endif %} {% endif %}
</a> </a>
</td> </td>

View File

@ -16,6 +16,10 @@
{% if v.id == chat.owner_id %} {% if v.id == chat.owner_id %}
<a href="/chat/{{chat.id}}/orgies" class="orgy-control fas fa-tv text-muted ml-2"></a> <a href="/chat/{{chat.id}}/orgies" class="orgy-control fas fa-tv text-muted ml-2"></a>
{% else %}
<button class="px-2" type="button" data-nonce="{{g.nonce}}" data-bs-toggle="tooltip" title="{% if muting_chat %}Unmute{% else %}Mute (don't do it){% endif %}" data-nonce="{{g.nonce}}" data-onclick="postToastReload(this, '/chat/{{chat.id}}/toggle_mute')">
<i class="fas fa-bell-slash {% if muting_chat %}text-danger{% else %}text-muted{% endif %}"></i>
</button>
{% endif %} {% endif %}
<button id="leave-private-chat" type="submit" class="btn btn-danger fl-r mt-1 mt-md-2 pt-0 px-2 mr-1 text-small-sm" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="postToastReload(this, '/chat/{{chat.id}}/leave')">Leave</button> <button id="leave-private-chat" type="submit" class="btn btn-danger fl-r mt-1 mt-md-2 pt-0 px-2 mr-1 text-small-sm" data-nonce="{{g.nonce}}" data-onclick="areyousure(this)" data-areyousure="postToastReload(this, '/chat/{{chat.id}}/leave')">Leave</button>
@ -92,6 +96,10 @@
<img class="ml-1 chat-owner" data-bs-toggle="tooltip" alt="Owner" title="Owner" src="{{SITE_FULL_IMAGES}}/e/marseykingretard.webp"> <img class="ml-1 chat-owner" data-bs-toggle="tooltip" alt="Owner" title="Owner" src="{{SITE_FULL_IMAGES}}/e/marseykingretard.webp">
{% endif %} {% endif %}
{% if membership.notification == None %}
<i class="fas fa-bell-slash text-danger" data-bs-toggle="tooltip" title="Muting chat{% if v.id == membership.user_id %} (kys){% elif v.id == chat.owner_id %} (kick him){% endif %}"></i>
{% endif %}
<i class="d-none ml-1 text-smaller text-success online-marker online-marker-{{user.id}} fas fa-circle"></i> <i class="d-none ml-1 text-smaller text-success online-marker online-marker-{{user.id}} fas fa-circle"></i>
</li> </li>
{% endfor %} {% endfor %}

View File

@ -0,0 +1 @@
alter table chat_memberships alter column notification drop not null;