{"version":3,"file":"useChat.mjs","names":[],"sources":["../../../../../src/components/Chat/hooks/useChat.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type {\n  EventPayload,\n  OwnUserResponse,\n  StreamChat,\n  UserMuteResponse,\n} from 'stream-chat';\n\nexport type UseChatParams = {\n  client: StreamChat;\n};\n\nexport const useChat = ({ client }: UseChatParams) => {\n  const [mutes, setMutes] = useState<Array<UserMuteResponse>>([]);\n\n  const clientMutes = (client.user as OwnUserResponse)?.mutes ?? [];\n\n  const appSettings = useRef<ReturnType<StreamChat['getAppSettings']> | null>(null);\n\n  const getAppSettings = () => {\n    if (appSettings.current) {\n      return appSettings.current;\n    }\n    appSettings.current = client.getAppSettings();\n    return appSettings.current;\n  };\n\n  useEffect(() => {\n    if (!client) return;\n\n    const version = process.env.STREAM_CHAT_REACT_VERSION;\n\n    const userAgent = client.getUserAgent();\n    if (!userAgent.includes('stream-chat-react')) {\n      // e.g. 'stream-chat-react-2.3.2-stream-chat-javascript-client-browser-2.2.2'. The build\n      // replaces `process.env.STREAM_CHAT_REACT_VERSION` with the package version.\n      client.setUserAgent(`stream-chat-react-${version}-${userAgent}`);\n    }\n\n    const releaseChannelManager = client.channelManager.registerSubscriptions();\n    client.threads.registerSubscriptions();\n    client.polls.registerSubscriptions();\n    client.reminders.registerSubscriptions();\n    client.reminders.initTimers();\n\n    return () => {\n      releaseChannelManager();\n      client.threads.unregisterSubscriptions();\n      client.polls.unregisterSubscriptions();\n      client.reminders.unregisterSubscriptions();\n      client.reminders.clearTimers();\n    };\n  }, [client]);\n\n  useEffect(() => {\n    setMutes(clientMutes);\n\n    const handleEvent = (event: EventPayload<'notification.mutes_updated'>) => {\n      setMutes(event.me.mutes);\n    };\n\n    const subscription = client.on('notification.mutes_updated', handleEvent);\n    return () => subscription.unsubscribe();\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [clientMutes?.length]);\n\n  return {\n    getAppSettings,\n    mutes,\n  };\n};\n"],"mappings":";;AAaA,IAAa,WAAW,EAAE,aAA4B;CACpD,MAAM,CAAC,OAAO,YAAY,SAAkC,CAAC,CAAC;CAE9D,MAAM,cAAe,OAAO,MAA0B,SAAS,CAAC;CAEhE,MAAM,cAAc,OAAwD,IAAI;CAEhF,MAAM,uBAAuB;EAC3B,IAAI,YAAY,SACd,OAAO,YAAY;EAErB,YAAY,UAAU,OAAO,eAAe;EAC5C,OAAO,YAAY;CACrB;CAEA,gBAAgB;EACd,IAAI,CAAC,QAAQ;EAEb,MAAM,UAAA;EAEN,MAAM,YAAY,OAAO,aAAa;EACtC,IAAI,CAAC,UAAU,SAAS,mBAAmB,GAGzC,OAAO,aAAa,qBAAqB,QAAQ,GAAG,WAAW;EAGjE,MAAM,wBAAwB,OAAO,eAAe,sBAAsB;EAC1E,OAAO,QAAQ,sBAAsB;EACrC,OAAO,MAAM,sBAAsB;EACnC,OAAO,UAAU,sBAAsB;EACvC,OAAO,UAAU,WAAW;EAE5B,aAAa;GACX,sBAAsB;GACtB,OAAO,QAAQ,wBAAwB;GACvC,OAAO,MAAM,wBAAwB;GACrC,OAAO,UAAU,wBAAwB;GACzC,OAAO,UAAU,YAAY;EAC/B;CACF,GAAG,CAAC,MAAM,CAAC;CAEX,gBAAgB;EACd,SAAS,WAAW;EAEpB,MAAM,eAAe,UAAsD;GACzE,SAAS,MAAM,GAAG,KAAK;EACzB;EAEA,MAAM,eAAe,OAAO,GAAG,8BAA8B,WAAW;EACxE,aAAa,aAAa,YAAY;CAExC,GAAG,CAAC,aAAa,MAAM,CAAC;CAExB,OAAO;EACL;EACA;CACF;AACF"}