feature/IO-3377-Add-Notification-Tone-For-Messaging - Finalize

This commit is contained in:
Dave
2025-09-24 14:32:45 -04:00
parent e11260e8fc
commit 5ae2e33596
6 changed files with 221 additions and 43 deletions

View File

@@ -36,7 +36,7 @@ export function ChatAffixContainer({ bodyshop, chatVisible, currentUser }) {
// Register WebSocket handlers
if (socket?.connected) {
registerMessagingHandlers({ socket, client, currentUser });
registerMessagingHandlers({ socket, client, currentUser, bodyshop, t });
return () => {
unregisterMessagingHandlers({ socket });

View File

@@ -1,7 +1,10 @@
import { CONVERSATION_LIST_QUERY, GET_CONVERSATION_DETAILS } from "../../graphql/conversations.queries";
import { gql } from "@apollo/client";
import { QUERY_ACTIVE_ASSOCIATION_SOUND } from "../../graphql/user.queries"; // the query you added earlier
import { playNewMessageSound } from "../../utils/soundManager.js";
import { isLeaderTab } from "../../utils/singleTabAudioLeader";
import { CONVERSATION_LIST_QUERY, GET_CONVERSATION_DETAILS } from "../../graphql/conversations.queries";
import { QUERY_ACTIVE_ASSOCIATION_SOUND } from "../../graphql/user.queries";
const logLocal = (message, ...args) => {
if (import.meta.env.VITE_APP_IS_TEST || !import.meta.env.PROD) {
@@ -36,7 +39,7 @@ const enrichConversation = (conversation, isOutbound) => ({
// });
// };
export const registerMessagingHandlers = ({ socket, client, currentUser }) => {
export const registerMessagingHandlers = ({ socket, client, currentUser, bodyshop }) => {
if (!(socket && client)) return;
const handleNewMessageSummary = async (message) => {
@@ -45,7 +48,7 @@ export const registerMessagingHandlers = ({ socket, client, currentUser }) => {
// True only when DB value is strictly true; falls back to true on cache miss
const isNewMessageSoundEnabled = (client) => {
try {
const email = currentUser?.email; // adjust if you keep email elsewhere
const email = currentUser?.email;
if (!email) return true; // default allow if we can't resolve user
const res = client.readQuery({
query: QUERY_ACTIVE_ASSOCIATION_SOUND,
@@ -64,9 +67,9 @@ export const registerMessagingHandlers = ({ socket, client, currentUser }) => {
const queryVariables = { offset: 0 };
if (!isoutbound) {
// Play notification sound for new inbound message
if (isNewMessageSoundEnabled(client)) {
playNewMessageSound();
// Play notification sound for new inbound message (scoped to bodyshop)
if (isLeaderTab(bodyshop.id) && isNewMessageSoundEnabled(client)) {
playNewMessageSound(bodyshop.id);
}
}
@@ -325,8 +328,6 @@ export const registerMessagingHandlers = ({ socket, client, currentUser }) => {
case "conversation-unarchived":
case "conversation-archived":
// Would like to someday figure out how to get this working without refetch queries,
// But I have but a solid 4 hours into it, and there are just too many weird occurrences
try {
const listQueryVariables = { offset: 0 };
const detailsQueryVariables = { conversationId };