@nivaro/react 0.1.26 → 0.1.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1711,7 +1711,7 @@ export declare function useTypingIndicator(room: string | null): {
1711
1711
  typingText: string | null;
1712
1712
  };
1713
1713
 
1714
- export declare function useUnreadChirp(totalUnread: number): void;
1714
+ export declare function useUnreadChirp(totalUnread: number, rooms?: RoomInfo[]): void;
1715
1715
 
1716
1716
  export declare function useWatchFields(form: UseNivaroFormReturn, fields: string[]): Record<string, unknown>;
1717
1717
 
package/dist/index.js CHANGED
@@ -1877,11 +1877,30 @@ function useCreateChannel() {
1877
1877
  });
1878
1878
  }
1879
1879
  let prevUnread = 0;
1880
- function useUnreadChirp(e) {
1881
- const t = useChatConfig();
1880
+ const prevByRoom = /* @__PURE__ */ new Map();
1881
+ function useUnreadChirp(e, t) {
1882
+ const s = useChatConfig();
1882
1883
  useEffect(() => {
1883
- t.sound && e > prevUnread && playChirp(), prevUnread = e;
1884
- }, [e, t.sound]);
1884
+ const n = e > prevUnread;
1885
+ if (s.sound && n && playChirp(), t) {
1886
+ const r = prevByRoom.size > 0;
1887
+ for (const a of t) {
1888
+ const l = prevByRoom.get(a.room) ?? 0;
1889
+ if (r && !a.muted && a.unread > l) {
1890
+ const i = a.lastMessage, o = i != null && i.sender_name ? String(i.sender_name).trim() : null;
1891
+ toast(
1892
+ a.kind === "dm" ? `New message from ${o || a.label}` : `New message in ${a.label}${o ? ` — ${o}` : ""}`,
1893
+ {
1894
+ description: i != null && i.message ? String(i.message).replace(/<[^>]*>/g, "").slice(0, 90) : void 0,
1895
+ duration: 4e3
1896
+ }
1897
+ );
1898
+ }
1899
+ prevByRoom.set(a.room, a.unread);
1900
+ }
1901
+ }
1902
+ prevUnread = e;
1903
+ }, [e, s.sound, t]);
1885
1904
  }
1886
1905
  function useMarkRoomRead() {
1887
1906
  const e = useNivaroClient(), t = useQueryClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nivaro/react",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "React hooks and components for Nivaro CMS forms",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",