Ver Fonte

feat: remove typing indicators to reduce system load

unknown há 2 meses atrás
pai
commit
cef411acac
2 ficheiros alterados com 2 adições e 39 exclusões
  1. 1 5
      backend/main.py
  2. 1 34
      src/components/OrderChat.vue

+ 1 - 5
backend/main.py

@@ -151,11 +151,7 @@ async def ws_chat(websocket: WebSocket, token: str = Query(...), order_id: int =
     try:
         while True:
             data = await websocket.receive_text()
-            if data == "typing":
-                await manager.broadcast_to_order(order_id, {"type": "typing", "is_admin": role == 'admin'})
-            elif data == "stop_typing":
-                await manager.broadcast_to_order(order_id, {"type": "stop_typing", "is_admin": role == 'admin'})
-            elif data == "read":
+            if data == "read":
                 if role == 'admin':
                     db.execute_commit("UPDATE order_messages SET is_read = TRUE WHERE order_id = %s AND is_from_admin = FALSE AND is_read = FALSE", (order_id,))
                     await global_manager.notify_admins()

+ 1 - 34
src/components/OrderChat.vue

@@ -48,15 +48,6 @@
           </div>
         </div>
       </template>
-
-      <!-- Typing Indicator -->
-      <div v-if="isOtherPartyTyping" class="flex justify-start mb-2 animate-in fade-in zoom-in duration-300">
-        <div class="bg-secondary/60 text-muted-foreground px-4 py-3 rounded-2xl rounded-bl-md flex items-center gap-1.5 shadow-sm">
-          <span class="w-1.5 h-1.5 bg-foreground/40 rounded-full animate-bounce" style="animation-delay: 0ms"></span>
-          <span class="w-1.5 h-1.5 bg-foreground/40 rounded-full animate-bounce" style="animation-delay: 150ms"></span>
-          <span class="w-1.5 h-1.5 bg-foreground/40 rounded-full animate-bounce" style="animation-delay: 300ms"></span>
-        </div>
-      </div>
     </div>
 
     <!-- Input area -->
@@ -68,7 +59,7 @@
           rows="1"
           class="flex-1 resize-none bg-background/80 border border-border/50 rounded-xl px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-primary/40 transition-all placeholder:text-muted-foreground/50 max-h-[80px] overflow-y-auto"
           @keydown.enter.exact.prevent="handleSend"
-          @input="onTextareaInput($event); autoResize($event)"
+          @input="autoResize($event)"
           ref="textareaRef"
         />
         <button
@@ -112,8 +103,6 @@ const wsConnected = ref(false);
 const messagesContainer = ref<HTMLElement | null>(null);
 const textareaRef = ref<HTMLTextAreaElement | null>(null);
 const otherPartyOnline = ref(false);
-const isOtherPartyTyping = ref(false);
-let typingTimeout: ReturnType<typeof setTimeout> | null = null;
 let cooldownInterval: ReturnType<typeof setInterval> | null = null;
 
 function startCooldown() {
@@ -155,16 +144,6 @@ function connectWebSocket() {
         return;
       }
       
-      if (msg.type === "typing" || msg.type === "stop_typing") {
-        const myRole = authStore.user?.role === 'admin' ? 'admin' : 'user';
-        const isFromOther = (msg.is_admin && myRole === 'user') || (!msg.is_admin && myRole === 'admin');
-        if (isFromOther) {
-          isOtherPartyTyping.value = (msg.type === "typing");
-          scrollToBottom();
-        }
-        return;
-      }
-      
       // If it's a message (type 'message' or has essential fields)
       if (msg.type === "message" || (msg.message && msg.id)) {
         // Use lenient comparison (==) for ID to avoid string/int mismatches
@@ -270,18 +249,6 @@ function autoResize(e: Event) {
   el.style.height = Math.min(el.scrollHeight, 80) + "px";
 }
 
-function onTextareaInput(e: Event) {
-  if (wsConnected.value && ws) {
-    ws.send("typing");
-    if (typingTimeout) clearTimeout(typingTimeout);
-    typingTimeout = setTimeout(() => {
-      if (ws && ws.readyState === WebSocket.OPEN) {
-        ws.send("stop_typing");
-      }
-    }, 2000);
-  }
-}
-
 function formatTime(dt: string) {
   if (!dt) return "";
   const d = new Date(dt);