Browse Source

fix: send notification

Timothy Jaeryang Baek 3 weeks ago
parent
commit
1077b2ac8b

+ 1 - 1
backend/open_webui/models/users.py

@@ -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)
 

+ 13 - 12
backend/open_webui/routers/channels.py

@@ -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,14 +304,16 @@ async def post_new_message(
 
             active_user_ids = get_user_ids_from_room(f"channel:{channel.id}")
 
-            background_tasks.add_task(
-                send_notification,
-                request.app.state.WEBUI_NAME,
-                request.app.state.config.WEBUI_URL,
-                channel,
-                message,
-                active_user_ids,
-            )
+            async def background_handler():
+                await send_notification(
+                    request.app.state.WEBUI_NAME,
+                    request.app.state.config.WEBUI_URL,
+                    channel,
+                    message,
+                    active_user_ids,
+                )
+
+            background_tasks.add_task(background_handler)
 
         return MessageModel(**message.model_dump())
     except Exception as e:

+ 3 - 2
backend/open_webui/utils/access_control.py

@@ -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", [])

+ 2 - 2
src/lib/components/channel/MessageInput/MentionList.svelte

@@ -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
 			});
 	};

+ 14 - 15
src/lib/components/chat/Messages/Markdown/MarkdownInlineTokens/MentionToken.svelte

@@ -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>
 
-	<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'}
+	{#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}
+		>
 			<UserStatus {id} />
-		{/if}
-		<!-- <div class="flex space-x-4">HI</div> -->
-	</LinkPreview.Content>
+			<!-- <div class="flex space-x-4">HI</div> -->
+		</LinkPreview.Content>
+	{/if}
 </LinkPreview.Root>