feat: ignore background and local notifications for muted chats
This commit is contained in:
@@ -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<ConversationsController>()) {
|
||||
final controller = Get.find<ConversationsController>();
|
||||
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',
|
||||
|
||||
@@ -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 || '';
|
||||
|
||||
Reference in New Issue
Block a user