From 0498575e51997c0532680a7b3c003fd84427f8e9 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Mon, 18 May 2026 19:53:59 +0300 Subject: [PATCH] feat: ignore background and local notifications for muted chats --- whatsapp_app/lib/services/firebase_service.dart | 11 +++++++++++ whatsapp_bridge/server.js | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/whatsapp_app/lib/services/firebase_service.dart b/whatsapp_app/lib/services/firebase_service.dart index 1587330..33557e6 100644 --- a/whatsapp_app/lib/services/firebase_service.dart +++ b/whatsapp_app/lib/services/firebase_service.dart @@ -5,6 +5,7 @@ import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:get/get.dart'; +import '../controllers/conversations_controller.dart'; import '../models/conversation_model.dart'; import '../screens/chat_screen.dart'; import 'whatsapp_service.dart'; @@ -173,6 +174,16 @@ class FirebaseService extends GetxService { return; // Silent } + // Do not show local notification if the chat is muted in user's conversations list + if (chatId != null && Get.isRegistered()) { + final controller = Get.find(); + final index = controller.conversations.indexWhere((c) => c.id == chatId); + if (index != -1 && controller.conversations[index].isMuted) { + print('[LOCAL NOTIF] Skipping: Chat $chatId is muted by user.'); + return; // Silent + } + } + const androidDetails = AndroidNotificationDetails( 'whatsapp_channel', 'WhatsApp Messages', diff --git a/whatsapp_bridge/server.js b/whatsapp_bridge/server.js index 90887fd..95cc947 100644 --- a/whatsapp_bridge/server.js +++ b/whatsapp_bridge/server.js @@ -334,6 +334,12 @@ function initWhatsApp() { // Trigger background push notification if not sent by me if (!msg.fromMe) { try { + const chat = await msg.getChat(); + if (chat.isMuted) { + console.log(`[FCM] Push skipped for muted chat: ${msg.from}`); + return; + } + const contact = await msg.getContact(); const senderName = contact.name || contact.pushname || msg.from.split('@')[0]; let body = msg.body || '';