mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
fix: send notification
This commit is contained in:
parent
c3ea4feca5
commit
1077b2ac8b
5 changed files with 33 additions and 32 deletions
|
|
@ -220,7 +220,7 @@ class UsersTable:
|
|||
filter: Optional[dict] = None,
|
||||
skip: Optional[int] = None,
|
||||
limit: Optional[int] = None,
|
||||
) -> UserListResponse:
|
||||
) -> dict:
|
||||
with get_db() as db:
|
||||
query = db.query(User)
|
||||
|
||||
|
|
|
|||
|
|
@ -200,14 +200,11 @@ async def send_notification(name, webui_url, channel, message, active_user_ids):
|
|||
users = get_users_with_access("read", channel.access_control)
|
||||
|
||||
for user in users:
|
||||
if user.id in active_user_ids:
|
||||
continue
|
||||
else:
|
||||
if user.id not in active_user_ids:
|
||||
if user.settings:
|
||||
webhook_url = user.settings.ui.get("notifications", {}).get(
|
||||
"webhook_url", None
|
||||
)
|
||||
|
||||
if webhook_url:
|
||||
await post_webhook(
|
||||
name,
|
||||
|
|
@ -221,6 +218,8 @@ async def send_notification(name, webui_url, channel, message, active_user_ids):
|
|||
},
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@router.post("/{id}/messages/post", response_model=Optional[MessageModel])
|
||||
async def post_new_message(
|
||||
|
|
@ -305,8 +304,8 @@ async def post_new_message(
|
|||
|
||||
active_user_ids = get_user_ids_from_room(f"channel:{channel.id}")
|
||||
|
||||
background_tasks.add_task(
|
||||
send_notification,
|
||||
async def background_handler():
|
||||
await send_notification(
|
||||
request.app.state.WEBUI_NAME,
|
||||
request.app.state.config.WEBUI_URL,
|
||||
channel,
|
||||
|
|
@ -314,6 +313,8 @@ async def post_new_message(
|
|||
active_user_ids,
|
||||
)
|
||||
|
||||
background_tasks.add_task(background_handler)
|
||||
|
||||
return MessageModel(**message.model_dump())
|
||||
except Exception as e:
|
||||
log.exception(e)
|
||||
|
|
|
|||
|
|
@ -130,9 +130,10 @@ def has_access(
|
|||
# Get all users with access to a resource
|
||||
def get_users_with_access(
|
||||
type: str = "write", access_control: Optional[dict] = None
|
||||
) -> List[UserModel]:
|
||||
) -> list[UserModel]:
|
||||
if access_control is None:
|
||||
return Users.get_users()
|
||||
result = Users.get_users()
|
||||
return result.get("users", [])
|
||||
|
||||
permission_access = access_control.get(type, {})
|
||||
permitted_group_ids = permission_access.get("group_ids", [])
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@
|
|||
const item = filteredItems[index];
|
||||
if (!item) return;
|
||||
|
||||
// Add the "U:", "A:" or "C:" prefix to the id
|
||||
// Add the "U:", "M:" or "C:" prefix to the id
|
||||
// and also append the label after a pipe |
|
||||
// so that the mention renderer can show the label
|
||||
if (item)
|
||||
command({
|
||||
id: `${item.type === 'user' ? 'U' : item.type === 'model' ? 'A' : 'C'}:${item.id}|${item.label}`,
|
||||
id: `${item.type === 'user' ? 'U' : item.type === 'model' ? 'M' : 'C'}:${item.id}|${item.label}`,
|
||||
label: item.label
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@
|
|||
} else if (triggerChar === '@') {
|
||||
if (idType === 'U') {
|
||||
// User
|
||||
} else if (idType === 'A') {
|
||||
// Agent/assistant/ai model
|
||||
} else if (idType === 'M') {
|
||||
// Model
|
||||
const model = $models.find((m) => m.id === id);
|
||||
if (model) {
|
||||
label = model.name;
|
||||
|
|
@ -77,9 +77,8 @@
|
|||
if (idType === 'U') {
|
||||
// Open user profile
|
||||
console.log('Clicked user mention', id);
|
||||
} else if (idType === 'A') {
|
||||
// Open agent/assistant/ai model profile
|
||||
console.log('Clicked agent mention', id);
|
||||
} else if (idType === 'M') {
|
||||
console.log('Clicked model mention', id);
|
||||
await goto(`/?model=${id}`);
|
||||
}
|
||||
} else if (triggerChar === '#') {
|
||||
|
|
@ -101,15 +100,15 @@
|
|||
</span>
|
||||
</LinkPreview.Trigger>
|
||||
|
||||
{#if triggerChar === '@' && idType === 'U'}
|
||||
<LinkPreview.Content
|
||||
class="w-full max-w-[260px] rounded-2xl border border-gray-100 dark:border-gray-800 z-50 bg-white dark:bg-gray-850 dark:text-white shadow-lg transition"
|
||||
side="top"
|
||||
align="start"
|
||||
sideOffset={6}
|
||||
>
|
||||
{#if triggerChar === '@' && idType === 'U'}
|
||||
<UserStatus {id} />
|
||||
{/if}
|
||||
<!-- <div class="flex space-x-4">HI</div> -->
|
||||
</LinkPreview.Content>
|
||||
{/if}
|
||||
</LinkPreview.Root>
|
||||
|
|
|
|||
Loading…
Reference in a new issue