Change "Users Online" to just "Users".

This commit is contained in:
Ben Rog-Wilhelm 2023-08-27 07:47:38 -05:00
parent 2908df104a
commit 525a62033a
5 changed files with 47 additions and 6 deletions

View file

@ -33,7 +33,7 @@ export function ChatHeading() {
className="far fa-user"
onClick={handleToggleUserListDrawer}
/>
<em>{online.length} users online</em>
<em>{online.length} users</em>
</>
)}
</div>

View file

@ -13,7 +13,7 @@ export function UserList({ fluid = false }: Props) {
return (
<div className="UserList">
<div className="UserList-heading">
<h5>Users Online</h5>
<h5>Users</h5>
<div className="Chat-online">
<i className="far fa-user fa-sm" /> {online.length}
</div>

View file

@ -139,6 +139,8 @@ class User(CreatedBase):
Index('users_subs_idx', stored_subscriber_count)
Index('users_unbanutc_idx', unban_utc.desc())
Index('chat_auth_index', chat_authorized)
badges = relationship("Badge", viewonly=True)
subscriptions = relationship("Subscription", viewonly=True)
following = relationship("Follow", primaryjoin="Follow.user_id==User.id", viewonly=True)

View file

@ -61,7 +61,7 @@ else:
CHAT_SCROLLBACK_ITEMS: Final[int] = 500
typing: list[str] = []
online: list[str] = []
online: list[str] = [] # right now we maintain this but don't actually use it anywhere
muted: dict[str, int] = cache.get(f'{SITE}_muted') or {}
messages: list[dict[str, Any]] = cache.get(f'{SITE}_chat') or []
total: int = cache.get(f'{SITE}_total') or 0
@ -82,6 +82,15 @@ def send_system_reply(text):
}
emit('speak', data)
def get_chat_userlist():
# Query for the User.username column for users with chat_authorized == True
result = g.db.query(User.username).filter(User.chat_authorized == True).all()
# Convert the list of tuples into a flat list of usernames
userlist = [item[0] for item in result]
return userlist
@app.get("/chat")
@is_not_permabanned
@chat_is_allowed()
@ -152,13 +161,12 @@ def speak(data, v):
def connect(v):
if v.username not in online:
online.append(v.username)
emit("online", online, broadcast=True)
if not socket_ids_to_user_ids.get(request.sid):
socket_ids_to_user_ids[request.sid] = v.id
user_ids_to_socket_ids[v.id] = request.sid
emit('online', online)
emit('online', get_chat_userlist())
emit('catchup', messages)
emit('typing', typing)
@ -168,7 +176,6 @@ def connect(v):
def disconnect(v):
if v.username in online:
online.remove(v.username)
emit("online", online, broadcast=True)
if v.username in typing: typing.remove(v.username)
@ -216,6 +223,8 @@ def add(user):
user_instance.chat_authorized = True
g.db.commit()
emit('online', get_chat_userlist(), broadcast=True)
send_system_reply(f"Added {user} to chat.")
else:
send_system_reply(f"Could not find user {user}.")
@ -232,6 +241,8 @@ def remove(user):
user_instance.chat_authorized = False
g.db.commit()
emit('online', get_chat_userlist(), broadcast=True)
send_system_reply(f"Removed {user} from chat.")
else:
send_system_reply(f"Could not find user {user}.")

View file

@ -0,0 +1,28 @@
"""add chat_authorized index
Revision ID: c41b790058ad
Revises: 503fd4d18a54
Create Date: 2023-08-27 12:43:34.202689+00:00
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c41b790058ad'
down_revision = '503fd4d18a54'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_index('chat_auth_index', 'users', ['chat_authorized'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('chat_auth_index', table_name='users')
# ### end Alembic commands ###