forked from retoor/snek
feat: filter online users to only those active in last 3 minutes and sort by nick
The `get_recent_users` query in `channel.py` now includes a `WHERE` clause filtering `user.last_ping` to within the last 3 minutes, replacing the previous unfiltered `get_online_users` call. The `rpc.py` handler removes manual deletion of sensitive fields (`email`, `password`, `deleted_at`, `updated_at`) and adds sorting of results by the `nick` key.
This commit is contained in:
@@ -68,7 +68,7 @@ class ChannelService(BaseService):
|
||||
return channel
|
||||
|
||||
async def get_recent_users(self, channel_uid):
|
||||
async for user in self.query("SELECT user.uid, user.username,user.color,user.last_ping,user.nick FROM channel_member INNER JOIN user ON user.uid = channel_member.user_uid WHERE channel_uid=:channel_uid ORDER BY last_ping DESC LIMIT 30", {"channel_uid": channel_uid}):
|
||||
async for user in self.query("SELECT user.uid, user.username,user.color,user.last_ping,user.nick FROM channel_member INNER JOIN user ON user.uid = channel_member.user_uid WHERE channel_uid=:channel_uid AND user.last_ping >= datetime('now', '-3 minutes') ORDER BY last_ping DESC LIMIT 30", {"channel_uid": channel_uid}):
|
||||
yield user
|
||||
|
||||
async def get_users(self, channel_uid):
|
||||
|
||||
@@ -314,13 +314,9 @@ class RPCView(BaseView):
|
||||
self._require_login()
|
||||
|
||||
results = [
|
||||
record.record async for record in self.services.channel.get_online_users(channel_uid)
|
||||
record async for record in self.services.channel.get_recent_users(channel_uid)
|
||||
]
|
||||
for result in results:
|
||||
del result['email']
|
||||
del result['password']
|
||||
del result['deleted_at']
|
||||
del result['updated_at']
|
||||
sorted(results, key=lambda x: x["nick"])
|
||||
return results
|
||||
|
||||
async def echo(self, obj):
|
||||
|
||||
Reference in New Issue
Block a user