order private chat members alphabetically
parent
f7efda103e
commit
b1a43340bd
|
@ -14,8 +14,6 @@ class Chat(Base):
|
|||
name = Column(String)
|
||||
created_utc = Column(Integer)
|
||||
|
||||
memberships = relationship("ChatMembership")
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
||||
super().__init__(*args, **kwargs)
|
||||
|
|
|
@ -25,8 +25,8 @@ def chat_user(v, username):
|
|||
abort(403, f"@{user.username} is muting notifications from you, so you can't chat with them!")
|
||||
|
||||
|
||||
sq = g.db.query(Chat.id).join(Chat.memberships).filter(ChatMembership.user_id.in_((v.id, user.id))).group_by(Chat.id).having(func.count(Chat.id) == 2).subquery()
|
||||
existing = g.db.query(Chat.id).join(Chat.memberships).filter(Chat.id == sq.c.id).group_by(Chat.id).having(func.count(Chat.id) == 2).one_or_none()
|
||||
sq = g.db.query(Chat.id).join(ChatMembership, ChatMembership.chat_id == Chat.id).filter(ChatMembership.user_id.in_((v.id, user.id))).group_by(Chat.id).having(func.count(Chat.id) == 2).subquery()
|
||||
existing = g.db.query(Chat.id).join(ChatMembership, ChatMembership.chat_id == Chat.id).filter(Chat.id == sq.c.id).group_by(Chat.id).having(func.count(Chat.id) == 2).one_or_none()
|
||||
if existing:
|
||||
return redirect(f"/chat/{existing.id}")
|
||||
|
||||
|
@ -71,7 +71,10 @@ def private_chat(v, chat_id):
|
|||
g.db.add(membership)
|
||||
g.db.commit() #to clear notif count
|
||||
|
||||
return render_template("private_chat.html", v=v, messages=displayed_messages, chat=chat)
|
||||
query = g.db.query(ChatMembership).filter_by(chat_id=chat.id)
|
||||
sorted_memberships = [query.filter_by(user_id=chat.owner_id).one()] + query.filter(ChatMembership.user_id != chat.owner_id).join(ChatMembership.user).order_by(func.lower(User.username)).all()
|
||||
|
||||
return render_template("private_chat.html", v=v, messages=displayed_messages, chat=chat, sorted_memberships=sorted_memberships)
|
||||
|
||||
|
||||
@app.post("/chat/<int:chat_id>/name")
|
||||
|
|
|
@ -532,9 +532,9 @@
|
|||
<br><br><br><br><br><br><br><br>
|
||||
{% elif request.path.startswith('/chat/') %}
|
||||
<div class="mx-2">
|
||||
<h5 class="mt-2 mb-3">Members ({{chat.memberships|length}})</h5>
|
||||
<h5 class="mt-2 mb-3">Members ({{sorted_memberships|length}})</h5>
|
||||
<ul class="col text-left d-lg-none bg-white mb-4 pb-2" style="max-width:300px;list-style-type:none">
|
||||
{% for membership in chat.memberships %}
|
||||
{% for membership in sorted_memberships %}
|
||||
{% set user = membership.user %}
|
||||
{% set patron = '' %}
|
||||
{% if user.patron %}
|
||||
|
|
|
@ -42,9 +42,9 @@
|
|||
</div>
|
||||
|
||||
<div class="col text-left d-none d-lg-block pt-3 pb-5" style="max-width:313px">
|
||||
<h5>Members ({{chat.memberships|length}})</h5>
|
||||
<h5>Members ({{sorted_memberships|length}})</h5>
|
||||
<div id="members" class="mt-2">
|
||||
{% for membership in chat.memberships %}
|
||||
{% for membership in sorted_memberships %}
|
||||
{% set user = membership.user %}
|
||||
{% set patron = '' %}
|
||||
{% if user.patron %}
|
||||
|
|
Loading…
Reference in New Issue