diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 6a328d3ef..5272bd59d 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request, status, Backgrou from pydantic import BaseModel -from open_webui.socket.main import sio, SESSION_POOL +from open_webui.socket.main import sio, get_user_ids_from_room from open_webui.models.users import Users, UserNameResponse from open_webui.models.channels import Channels, ChannelModel, ChannelForm @@ -182,8 +182,6 @@ async def get_channel_messages( async def send_notification(channel, message, active_user_ids): - - print(f"Sending notification to {channel=}, {message=}, {active_user_ids=}") users = get_users_with_access("read", channel.access_control) for user in users: @@ -252,19 +250,7 @@ async def post_new_message( to=f"channel:{channel.id}", ) - active_session_ids = sio.manager.get_participants( - namespace="/", - room=f"channel:{channel.id}", - ) - - active_user_ids = list( - set( - [ - SESSION_POOL.get(session_id[0]) - for session_id in active_session_ids - ] - ) - ) + active_user_ids = get_user_ids_from_room(f"channel:{channel.id}") background_tasks.add_task( send_notification, channel, message, active_user_ids diff --git a/backend/open_webui/socket/main.py b/backend/open_webui/socket/main.py index 9c6885ad6..f24e1d505 100644 --- a/backend/open_webui/socket/main.py +++ b/backend/open_webui/socket/main.py @@ -289,3 +289,15 @@ def get_event_call(request_info): def get_user_id_from_session_pool(sid): return SESSION_POOL.get(sid) + + +def get_user_ids_from_room(room): + active_session_ids = sio.manager.get_participants( + namespace="/", + room=room, + ) + + active_user_ids = list( + set([SESSION_POOL.get(session_id[0]) for session_id in active_session_ids]) + ) + return active_user_ids