This commit is contained in:
Timothy Jaeryang Baek 2024-12-25 00:57:39 -07:00
parent 34cc472c48
commit 2e5c2bc4c2
2 changed files with 14 additions and 16 deletions

View File

@ -7,7 +7,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request, status, Backgrou
from pydantic import BaseModel 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.users import Users, UserNameResponse
from open_webui.models.channels import Channels, ChannelModel, ChannelForm 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): 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) users = get_users_with_access("read", channel.access_control)
for user in users: for user in users:
@ -252,19 +250,7 @@ async def post_new_message(
to=f"channel:{channel.id}", to=f"channel:{channel.id}",
) )
active_session_ids = sio.manager.get_participants( active_user_ids = get_user_ids_from_room(f"channel:{channel.id}")
namespace="/",
room=f"channel:{channel.id}",
)
active_user_ids = list(
set(
[
SESSION_POOL.get(session_id[0])
for session_id in active_session_ids
]
)
)
background_tasks.add_task( background_tasks.add_task(
send_notification, channel, message, active_user_ids send_notification, channel, message, active_user_ids

View File

@ -289,3 +289,15 @@ def get_event_call(request_info):
def get_user_id_from_session_pool(sid): def get_user_id_from_session_pool(sid):
return SESSION_POOL.get(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