@fayz-ai/plugin-conversations 0.28.0 → 0.30.0
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/{CampaignsSurface-75POQIRI.js → CampaignsSurface-DK7JSM3Y.js} +32 -14
- package/dist/CampaignsSurface-DK7JSM3Y.js.map +1 -0
- package/dist/{ConversationsPage-2D343Q5P.js → ConversationsPage-VXGZBHZG.js} +305 -99
- package/dist/ConversationsPage-VXGZBHZG.js.map +1 -0
- package/dist/{TemplatesSurface-QNTRYYTX.js → TemplatesSurface-6ICY3LS7.js} +54 -8
- package/dist/TemplatesSurface-6ICY3LS7.js.map +1 -0
- package/dist/{chunk-4OWC3V53.js → chunk-GDB5UCPB.js} +43 -7
- package/dist/chunk-GDB5UCPB.js.map +1 -0
- package/dist/components/Composer.d.ts +14 -0
- package/dist/components/Composer.d.ts.map +1 -0
- package/dist/components/InboxWatcher.d.ts.map +1 -1
- package/dist/data/journeys.d.ts +16 -1
- package/dist/data/journeys.d.ts.map +1 -1
- package/dist/data/media.d.ts +13 -0
- package/dist/data/media.d.ts.map +1 -0
- package/dist/index.js +76 -7
- package/dist/index.js.map +1 -1
- package/dist/lib/media-cache.d.ts +6 -0
- package/dist/lib/media-cache.d.ts.map +1 -0
- package/dist/locales/en.d.ts.map +1 -1
- package/dist/locales/pt-BR.d.ts.map +1 -1
- package/dist/migrations/index.d.ts +2 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/main.browser.js +3 -1
- package/dist/migrations/main.browser.js.map +1 -1
- package/dist/migrations/main.js +32 -2
- package/dist/migrations/main.js.map +1 -1
- package/dist/store.d.ts +7 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/views/MediaBubble.d.ts.map +1 -1
- package/dist/views/MessageThread.d.ts.map +1 -1
- package/dist/views/campaigns/CampaignWizard.d.ts.map +1 -1
- package/dist/views/campaigns/TemplatesSurface.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/CampaignsSurface-75POQIRI.js.map +0 -1
- package/dist/ConversationsPage-2D343Q5P.js.map +0 -1
- package/dist/TemplatesSurface-QNTRYYTX.js.map +0 -1
- package/dist/chunk-4OWC3V53.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ConversationsContextProvider, useConversationsStore, assinarChegada, useConversationsConfig, CHANNEL_LABELS, isWaitingOnUs, MessagePreview, mediaPreviewKind } from './chunk-NXYQFOT7.js';
|
|
2
2
|
import { providersApi } from './chunk-HMWUU5O7.js';
|
|
3
|
-
import * as
|
|
4
|
-
import
|
|
5
|
-
import { SquarePen, MessageSquare, Globe, Mail, Instagram, Phone, Search, User, Archive, Inbox, CheckCheck, ChevronLeft, MoreHorizontal, ArchiveRestore,
|
|
3
|
+
import * as React7 from 'react';
|
|
4
|
+
import React7__default from 'react';
|
|
5
|
+
import { SquarePen, MessageSquare, Globe, Mail, Instagram, Phone, Search, User, Archive, Inbox, CheckCheck, ChevronLeft, MoreHorizontal, ArchiveRestore, X, Building2, CheckCircle2, MoreVertical, Loader2, Forward, AlertTriangle, Check, Clock, ExternalLink, Reply, FileText, Trash2, Paperclip, Square, Mic, Send, Snowflake, Sun, Flame, Ban, BarChart3, MapPin, UserRound, Copy, Download } from 'lucide-react';
|
|
6
6
|
import { PageHeaderActions, cn, Button, Modal, ModalContent, ModalHeader, ModalTitle, ModalBody, Textarea, ModalFooter, Input, FilterChip, Skeleton, Dropdown, DropdownTrigger, DropdownContent, DropdownItem, toast } from '@fayz-ai/ui';
|
|
7
7
|
import { useRightRailStore, PageActions, useLimitGuard, ContactPicker, invalidateLimit, useConnectors, adminNavigateTo } from '@fayz-ai/admin';
|
|
8
8
|
import { currentAppPath, appHref, onAppPathChange, replaceApp, useTranslation, useActiveTenantId, errorMessage, tl, getSupabaseClientOptional, getActiveTenantId } from '@fayz-ai/core';
|
|
@@ -23,10 +23,10 @@ var CHANNEL_ACCENT = {
|
|
|
23
23
|
webchat: { color: "#f59e0b", badge: "bg-[#f59e0b]/12 text-[#b45309] dark:text-[#fcd34d]" }
|
|
24
24
|
};
|
|
25
25
|
function useMediaQuery(query) {
|
|
26
|
-
const [matches, setMatches] =
|
|
26
|
+
const [matches, setMatches] = React7__default.useState(
|
|
27
27
|
() => typeof window !== "undefined" && window.matchMedia(query).matches
|
|
28
28
|
);
|
|
29
|
-
|
|
29
|
+
React7__default.useEffect(() => {
|
|
30
30
|
if (typeof window === "undefined") return;
|
|
31
31
|
const mql = window.matchMedia(query);
|
|
32
32
|
const onChange = () => setMatches(mql.matches);
|
|
@@ -108,9 +108,9 @@ var whatsappConnected = () => {
|
|
|
108
108
|
return whatsappCache;
|
|
109
109
|
};
|
|
110
110
|
function useChannelConnections() {
|
|
111
|
-
const [whatsapp, setWhatsapp] =
|
|
111
|
+
const [whatsapp, setWhatsapp] = React7.useState(void 0);
|
|
112
112
|
const { connectors } = useConnectors({ hostPluginId: "conversations", includeGrants: false });
|
|
113
|
-
|
|
113
|
+
React7.useEffect(() => {
|
|
114
114
|
let cancelled = false;
|
|
115
115
|
void whatsappConnected().then((v) => {
|
|
116
116
|
if (!cancelled) setWhatsapp(v);
|
|
@@ -119,7 +119,7 @@ function useChannelConnections() {
|
|
|
119
119
|
cancelled = true;
|
|
120
120
|
};
|
|
121
121
|
}, []);
|
|
122
|
-
return
|
|
122
|
+
return React7.useMemo(() => {
|
|
123
123
|
if (whatsapp === void 0) return void 0;
|
|
124
124
|
const live = (needle) => (connectors ?? []).some((c) => c.state === "connected" && c.slug.toLowerCase().includes(needle));
|
|
125
125
|
return { whatsapp: whatsapp || live("whatsapp"), email: live("mail"), instagram: live("instagram") };
|
|
@@ -178,12 +178,12 @@ function ConversationList({ className }) {
|
|
|
178
178
|
setLeadOwnerFilter,
|
|
179
179
|
setSearch
|
|
180
180
|
} = useConversationsStore((s) => s);
|
|
181
|
-
const [archived, setArchived] =
|
|
182
|
-
const shown =
|
|
181
|
+
const [archived, setArchived] = React7__default.useState(false);
|
|
182
|
+
const shown = React7__default.useMemo(
|
|
183
183
|
() => conversations.filter((c) => archived ? c.status === "closed" : c.status !== "closed"),
|
|
184
184
|
[conversations, archived]
|
|
185
185
|
);
|
|
186
|
-
const donos =
|
|
186
|
+
const donos = React7__default.useMemo(() => {
|
|
187
187
|
const vistos = /* @__PURE__ */ new Map();
|
|
188
188
|
for (const c of conversations) {
|
|
189
189
|
if (c.leadOwnerId) vistos.set(c.leadOwnerId, c.leadOwnerName ?? c.leadOwnerId);
|
|
@@ -350,9 +350,9 @@ function ConversationList({ className }) {
|
|
|
350
350
|
] });
|
|
351
351
|
}
|
|
352
352
|
function useSendWindow(conversationId) {
|
|
353
|
-
const [row, setRow] =
|
|
354
|
-
const [providers, setProviders] =
|
|
355
|
-
|
|
353
|
+
const [row, setRow] = React7__default.useState(null);
|
|
354
|
+
const [providers, setProviders] = React7__default.useState(null);
|
|
355
|
+
React7__default.useEffect(() => {
|
|
356
356
|
let alive = true;
|
|
357
357
|
providersApi.list().then((p) => {
|
|
358
358
|
if (alive) setProviders(p);
|
|
@@ -363,7 +363,7 @@ function useSendWindow(conversationId) {
|
|
|
363
363
|
alive = false;
|
|
364
364
|
};
|
|
365
365
|
}, []);
|
|
366
|
-
|
|
366
|
+
React7__default.useEffect(() => {
|
|
367
367
|
let alive = true;
|
|
368
368
|
if (!conversationId) {
|
|
369
369
|
setRow(null);
|
|
@@ -384,7 +384,7 @@ function useSendWindow(conversationId) {
|
|
|
384
384
|
};
|
|
385
385
|
}, [conversationId]);
|
|
386
386
|
const provider = (providers ?? []).find((p) => p.isActive);
|
|
387
|
-
const mode =
|
|
387
|
+
const mode = React7__default.useMemo(() => {
|
|
388
388
|
if (!provider) return { kind: "blocked", reason: "no_provider" };
|
|
389
389
|
if (!provider.capabilities?.requires_template) {
|
|
390
390
|
return { kind: "free", until: null, minutesLeft: null };
|
|
@@ -459,10 +459,10 @@ function DeliveryMark({ m }) {
|
|
|
459
459
|
] });
|
|
460
460
|
}
|
|
461
461
|
function MessageMenu({ m }) {
|
|
462
|
-
const [open, setOpen] =
|
|
463
|
-
const [detail, setDetail] =
|
|
464
|
-
const [loading, setLoading] =
|
|
465
|
-
const [err, setErr] =
|
|
462
|
+
const [open, setOpen] = React7__default.useState(false);
|
|
463
|
+
const [detail, setDetail] = React7__default.useState(null);
|
|
464
|
+
const [loading, setLoading] = React7__default.useState(false);
|
|
465
|
+
const [err, setErr] = React7__default.useState(null);
|
|
466
466
|
async function load() {
|
|
467
467
|
setOpen(true);
|
|
468
468
|
if (!m.providerMessageId) return;
|
|
@@ -535,29 +535,84 @@ function MessageMenu({ m }) {
|
|
|
535
535
|
] }) })
|
|
536
536
|
] });
|
|
537
537
|
}
|
|
538
|
+
|
|
539
|
+
// src/lib/media-cache.ts
|
|
540
|
+
var CACHE = "fayz-wa-media-v1";
|
|
541
|
+
var memory = /* @__PURE__ */ new Map();
|
|
542
|
+
var pending = /* @__PURE__ */ new Map();
|
|
543
|
+
var keyOf = (messageId) => `/__wa-media/${messageId}`;
|
|
544
|
+
async function fromCache(messageId) {
|
|
545
|
+
try {
|
|
546
|
+
if (typeof caches === "undefined") return null;
|
|
547
|
+
const hit = await (await caches.open(CACHE)).match(keyOf(messageId));
|
|
548
|
+
return hit ? await hit.blob() : null;
|
|
549
|
+
} catch {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
async function toCache(messageId, blob) {
|
|
554
|
+
try {
|
|
555
|
+
if (typeof caches === "undefined") return;
|
|
556
|
+
await (await caches.open(CACHE)).put(keyOf(messageId), new Response(blob, { headers: { "content-type": blob.type || "application/octet-stream" } }));
|
|
557
|
+
} catch {
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
function cachedMediaUrl(messageId, sign) {
|
|
561
|
+
const known = memory.get(messageId);
|
|
562
|
+
if (known) return Promise.resolve(known);
|
|
563
|
+
const inFlight = pending.get(messageId);
|
|
564
|
+
if (inFlight) return inFlight;
|
|
565
|
+
const job = (async () => {
|
|
566
|
+
const cached = await fromCache(messageId);
|
|
567
|
+
if (cached) {
|
|
568
|
+
const url = URL.createObjectURL(cached);
|
|
569
|
+
memory.set(messageId, url);
|
|
570
|
+
return url;
|
|
571
|
+
}
|
|
572
|
+
const signed = await sign();
|
|
573
|
+
if (!signed) return null;
|
|
574
|
+
try {
|
|
575
|
+
const res = await fetch(signed);
|
|
576
|
+
if (!res.ok) return signed;
|
|
577
|
+
const blob = await res.blob();
|
|
578
|
+
void toCache(messageId, blob);
|
|
579
|
+
const url = URL.createObjectURL(blob);
|
|
580
|
+
memory.set(messageId, url);
|
|
581
|
+
return url;
|
|
582
|
+
} catch {
|
|
583
|
+
return signed;
|
|
584
|
+
}
|
|
585
|
+
})().finally(() => pending.delete(messageId));
|
|
586
|
+
pending.set(messageId, job);
|
|
587
|
+
return job;
|
|
588
|
+
}
|
|
589
|
+
function knownMediaUrl(messageId) {
|
|
590
|
+
return memory.get(messageId) ?? null;
|
|
591
|
+
}
|
|
538
592
|
var COM_ARQUIVO = /* @__PURE__ */ new Set(["image", "video", "audio", "document", "sticker"]);
|
|
539
593
|
function temArquivo(m) {
|
|
540
594
|
return !!m.mediaPath && COM_ARQUIVO.has(String(m.messageType));
|
|
541
595
|
}
|
|
542
596
|
function useUrlAssinada(m, visivel) {
|
|
543
|
-
const [url, setUrl] =
|
|
544
|
-
const [erro, setErro] =
|
|
545
|
-
|
|
597
|
+
const [url, setUrl] = React7.useState(() => knownMediaUrl(m.id));
|
|
598
|
+
const [erro, setErro] = React7.useState(false);
|
|
599
|
+
React7.useEffect(() => {
|
|
546
600
|
if (!visivel || url || erro || !temArquivo(m)) return;
|
|
547
601
|
let vivo = true;
|
|
548
|
-
(async () => {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
602
|
+
cachedMediaUrl(m.id, async () => {
|
|
603
|
+
const sb = getSupabaseClientOptional();
|
|
604
|
+
const { data, error } = await sb.functions.invoke("conversations-provider", {
|
|
605
|
+
body: { tenantId: getActiveTenantId(), action: "media_url", messageId: m.id }
|
|
606
|
+
});
|
|
607
|
+
if (error || data?.error) throw new Error("falhou");
|
|
608
|
+
return data?.url ?? null;
|
|
609
|
+
}).then((u) => {
|
|
610
|
+
if (!vivo) return;
|
|
611
|
+
if (u) setUrl(u);
|
|
612
|
+
else setErro(true);
|
|
613
|
+
}).catch(() => {
|
|
614
|
+
if (vivo) setErro(true);
|
|
615
|
+
});
|
|
561
616
|
return () => {
|
|
562
617
|
vivo = false;
|
|
563
618
|
};
|
|
@@ -577,10 +632,10 @@ function duracao(seg) {
|
|
|
577
632
|
return `${m}:${String(s).padStart(2, "0")}`;
|
|
578
633
|
}
|
|
579
634
|
function MediaBubble({ m, outbound }) {
|
|
580
|
-
const ref =
|
|
581
|
-
const [visivel, setVisivel] =
|
|
635
|
+
const ref = React7.useRef(null);
|
|
636
|
+
const [visivel, setVisivel] = React7.useState(false);
|
|
582
637
|
const { url, erro } = useUrlAssinada(m, visivel);
|
|
583
|
-
|
|
638
|
+
React7.useEffect(() => {
|
|
584
639
|
const el = ref.current;
|
|
585
640
|
if (!el || typeof IntersectionObserver === "undefined") {
|
|
586
641
|
setVisivel(true);
|
|
@@ -660,6 +715,172 @@ function MediaBubble({ m, outbound }) {
|
|
|
660
715
|
legenda ? /* @__PURE__ */ jsx("p", { className: "whitespace-pre-wrap break-words", children: legenda }) : null
|
|
661
716
|
] });
|
|
662
717
|
}
|
|
718
|
+
function recordingMime() {
|
|
719
|
+
if (typeof MediaRecorder === "undefined") return void 0;
|
|
720
|
+
for (const m of ["audio/ogg;codecs=opus", "audio/webm;codecs=opus", "audio/webm", "audio/mp4"]) {
|
|
721
|
+
if (MediaRecorder.isTypeSupported?.(m)) return m;
|
|
722
|
+
}
|
|
723
|
+
return void 0;
|
|
724
|
+
}
|
|
725
|
+
function clock(seconds) {
|
|
726
|
+
return `${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, "0")}`;
|
|
727
|
+
}
|
|
728
|
+
function Composer({ canType, placeholder, sending, onSendText, onSendMedia }) {
|
|
729
|
+
const t = useTranslation();
|
|
730
|
+
const [draft, setDraft] = React7.useState("");
|
|
731
|
+
const [file, setFile] = React7.useState(null);
|
|
732
|
+
const [preview, setPreview] = React7.useState(null);
|
|
733
|
+
const [recording, setRecording] = React7.useState(false);
|
|
734
|
+
const [seconds, setSeconds] = React7.useState(0);
|
|
735
|
+
const [busy, setBusy] = React7.useState(false);
|
|
736
|
+
const inputRef = React7.useRef(null);
|
|
737
|
+
const recorder = React7.useRef(null);
|
|
738
|
+
const chunks = React7.useRef([]);
|
|
739
|
+
const discard = React7.useRef(false);
|
|
740
|
+
const timer = React7.useRef(null);
|
|
741
|
+
React7.useEffect(() => {
|
|
742
|
+
if (!file || !/^(image|video)\//u.test(file.type)) {
|
|
743
|
+
setPreview(null);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
const url = URL.createObjectURL(file);
|
|
747
|
+
setPreview(url);
|
|
748
|
+
return () => URL.revokeObjectURL(url);
|
|
749
|
+
}, [file]);
|
|
750
|
+
React7.useEffect(() => () => {
|
|
751
|
+
if (timer.current) window.clearInterval(timer.current);
|
|
752
|
+
recorder.current?.stream.getTracks().forEach((tr) => tr.stop());
|
|
753
|
+
}, []);
|
|
754
|
+
async function send() {
|
|
755
|
+
if (busy || sending) return;
|
|
756
|
+
setBusy(true);
|
|
757
|
+
try {
|
|
758
|
+
if (file) {
|
|
759
|
+
await onSendMedia({ file, fileName: file.name, caption: draft.trim() || void 0 });
|
|
760
|
+
setFile(null);
|
|
761
|
+
setDraft("");
|
|
762
|
+
} else if (draft.trim()) {
|
|
763
|
+
const text = draft;
|
|
764
|
+
setDraft("");
|
|
765
|
+
await onSendText(text);
|
|
766
|
+
}
|
|
767
|
+
} catch (e) {
|
|
768
|
+
toast.error(e.message);
|
|
769
|
+
} finally {
|
|
770
|
+
setBusy(false);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
async function startRecording() {
|
|
774
|
+
const mime = recordingMime();
|
|
775
|
+
if (!navigator.mediaDevices?.getUserMedia || !mime) {
|
|
776
|
+
toast.error(t("conversations.composer.noMic"));
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
try {
|
|
780
|
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
781
|
+
const rec = new MediaRecorder(stream, { mimeType: mime });
|
|
782
|
+
chunks.current = [];
|
|
783
|
+
discard.current = false;
|
|
784
|
+
rec.ondataavailable = (e) => {
|
|
785
|
+
if (e.data.size) chunks.current.push(e.data);
|
|
786
|
+
};
|
|
787
|
+
rec.onstop = async () => {
|
|
788
|
+
stream.getTracks().forEach((tr) => tr.stop());
|
|
789
|
+
if (timer.current) {
|
|
790
|
+
window.clearInterval(timer.current);
|
|
791
|
+
timer.current = null;
|
|
792
|
+
}
|
|
793
|
+
setRecording(false);
|
|
794
|
+
if (discard.current || chunks.current.length === 0) return;
|
|
795
|
+
const blob = new Blob(chunks.current, { type: mime.split(";")[0] });
|
|
796
|
+
setBusy(true);
|
|
797
|
+
try {
|
|
798
|
+
await onSendMedia({ file: blob, fileName: `audio.${mime.includes("ogg") ? "ogg" : mime.includes("mp4") ? "m4a" : "webm"}`, ptt: true });
|
|
799
|
+
} catch (e) {
|
|
800
|
+
toast.error(e.message);
|
|
801
|
+
} finally {
|
|
802
|
+
setBusy(false);
|
|
803
|
+
}
|
|
804
|
+
};
|
|
805
|
+
recorder.current = rec;
|
|
806
|
+
rec.start();
|
|
807
|
+
setSeconds(0);
|
|
808
|
+
setRecording(true);
|
|
809
|
+
timer.current = window.setInterval(() => setSeconds((s) => s + 1), 1e3);
|
|
810
|
+
} catch {
|
|
811
|
+
toast.error(t("conversations.composer.micDenied"));
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
function stopRecording(sendIt) {
|
|
815
|
+
discard.current = !sendIt;
|
|
816
|
+
recorder.current?.stop();
|
|
817
|
+
recorder.current = null;
|
|
818
|
+
}
|
|
819
|
+
const empty = !draft.trim() && !file;
|
|
820
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
821
|
+
file && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 border-b border-border bg-muted/30 px-4 py-2", children: [
|
|
822
|
+
preview && file.type.startsWith("image/") ? /* @__PURE__ */ jsx("img", { src: preview, alt: "", className: "h-14 w-14 rounded-md object-cover" }) : preview && file.type.startsWith("video/") ? /* @__PURE__ */ jsx("video", { src: preview, className: "h-14 w-20 rounded-md object-cover" }) : /* @__PURE__ */ jsx("span", { className: "flex h-14 w-14 items-center justify-center rounded-md bg-card", children: /* @__PURE__ */ jsx(FileText, { className: "h-6 w-6 text-muted-foreground" }) }),
|
|
823
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
|
|
824
|
+
/* @__PURE__ */ jsx("p", { className: "truncate text-sm", children: file.name }),
|
|
825
|
+
/* @__PURE__ */ jsxs("p", { className: "text-[11px] text-muted-foreground", children: [
|
|
826
|
+
(file.size / 1024 / 1024).toFixed(1),
|
|
827
|
+
" MB \xB7 ",
|
|
828
|
+
t("conversations.composer.captionHint")
|
|
829
|
+
] })
|
|
830
|
+
] }),
|
|
831
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", onClick: () => setFile(null), "aria-label": t("conversations.composer.removeFile"), children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" }) })
|
|
832
|
+
] }),
|
|
833
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-end gap-2 px-4 py-3", children: [
|
|
834
|
+
/* @__PURE__ */ jsx(
|
|
835
|
+
"input",
|
|
836
|
+
{
|
|
837
|
+
ref: inputRef,
|
|
838
|
+
type: "file",
|
|
839
|
+
className: "hidden",
|
|
840
|
+
accept: "image/*,video/*,audio/*,application/pdf,.doc,.docx,.xls,.xlsx,.csv,.txt,.zip",
|
|
841
|
+
onChange: (e) => {
|
|
842
|
+
const f = e.target.files?.[0];
|
|
843
|
+
if (f) setFile(f);
|
|
844
|
+
e.target.value = "";
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
),
|
|
848
|
+
recording ? /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-3 rounded-md border border-destructive/40 bg-destructive-soft/40 px-3 py-2", children: [
|
|
849
|
+
/* @__PURE__ */ jsx("span", { className: "h-2.5 w-2.5 animate-pulse rounded-full bg-destructive" }),
|
|
850
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm tabular-nums", children: clock(seconds) }),
|
|
851
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("conversations.composer.recording") }),
|
|
852
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "ml-auto h-8 w-8", onClick: () => stopRecording(false), "aria-label": t("conversations.composer.discard"), children: /* @__PURE__ */ jsx(Trash2, { className: "h-4 w-4" }) })
|
|
853
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
854
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon", className: "shrink-0", disabled: !canType || busy, onClick: () => inputRef.current?.click(), "aria-label": t("conversations.composer.attach"), children: /* @__PURE__ */ jsx(Paperclip, { className: "h-4 w-4" }) }),
|
|
855
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
856
|
+
Textarea,
|
|
857
|
+
{
|
|
858
|
+
value: draft,
|
|
859
|
+
onChange: (e) => setDraft(e.target.value),
|
|
860
|
+
onKeyDown: (e) => {
|
|
861
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
862
|
+
e.preventDefault();
|
|
863
|
+
void send();
|
|
864
|
+
}
|
|
865
|
+
},
|
|
866
|
+
onPaste: (e) => {
|
|
867
|
+
const f = Array.from(e.clipboardData.files ?? [])[0];
|
|
868
|
+
if (f) {
|
|
869
|
+
e.preventDefault();
|
|
870
|
+
setFile(f);
|
|
871
|
+
}
|
|
872
|
+
},
|
|
873
|
+
rows: 1,
|
|
874
|
+
disabled: !canType,
|
|
875
|
+
placeholder: file ? t("conversations.composer.caption") : placeholder,
|
|
876
|
+
className: "max-h-32 min-h-[40px] resize-none rounded-md border-border bg-background shadow-none focus:border-primary focus-visible:ring-0 focus-visible:ring-offset-0 disabled:bg-muted/40 disabled:text-muted-foreground disabled:opacity-100"
|
|
877
|
+
}
|
|
878
|
+
) })
|
|
879
|
+
] }),
|
|
880
|
+
recording ? /* @__PURE__ */ jsx(Button, { onClick: () => stopRecording(true), "aria-label": t("conversations.thread.send"), children: /* @__PURE__ */ jsx(Square, { className: "h-3.5 w-3.5 fill-current" }) }) : empty ? /* @__PURE__ */ jsx(Button, { onClick: () => void startRecording(), disabled: !canType || busy || sending, "aria-label": t("conversations.composer.record"), className: cn(busy && "opacity-70"), children: busy ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Mic, { className: "h-4 w-4" }) }) : /* @__PURE__ */ jsx(Button, { onClick: () => void send(), disabled: !canType || busy || sending, "aria-label": t("conversations.thread.send"), children: busy ? /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx(Send, { className: "h-4 w-4" }) })
|
|
881
|
+
] })
|
|
882
|
+
] });
|
|
883
|
+
}
|
|
663
884
|
var URL_RE = /(https?:\/\/[^\s<]+[^\s<.,;:!?)\]'"])/gu;
|
|
664
885
|
function RichText({ text, outbound }) {
|
|
665
886
|
const linkCls = outbound ? "underline text-white" : "text-[hsl(var(--info))] underline";
|
|
@@ -826,7 +1047,7 @@ function isFoldedRow(m) {
|
|
|
826
1047
|
return m.messageType === "reaction" || m.messageType === "edit" || m.messageType === "revoke";
|
|
827
1048
|
}
|
|
828
1049
|
function ContactCard({ contacts, outbound }) {
|
|
829
|
-
const [copied, setCopied] =
|
|
1050
|
+
const [copied, setCopied] = React7__default.useState(null);
|
|
830
1051
|
const copy = (value) => {
|
|
831
1052
|
void navigator.clipboard?.writeText(value);
|
|
832
1053
|
setCopied(value);
|
|
@@ -896,15 +1117,14 @@ function buildRows(messages) {
|
|
|
896
1117
|
}
|
|
897
1118
|
function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways, className }) {
|
|
898
1119
|
const t = useTranslation();
|
|
899
|
-
const { messages, sending, send, setStatus, refreshMessages } = useConversationsStore((s) => s);
|
|
900
|
-
const [draft, setDraft] = React9__default.useState("");
|
|
1120
|
+
const { messages, sending, send, sendMedia, setStatus, refreshMessages } = useConversationsStore((s) => s);
|
|
901
1121
|
const win = useSendWindow(selected.id);
|
|
902
1122
|
const canType = win.mode.kind === "free";
|
|
903
|
-
const threadRef =
|
|
904
|
-
|
|
1123
|
+
const threadRef = React7__default.useRef(null);
|
|
1124
|
+
React7__default.useEffect(() => {
|
|
905
1125
|
threadRef.current?.scrollTo({ top: threadRef.current.scrollHeight, behavior: "smooth" });
|
|
906
1126
|
}, [messages.length, selected.id]);
|
|
907
|
-
|
|
1127
|
+
React7__default.useEffect(() => {
|
|
908
1128
|
if (!selected.id) return;
|
|
909
1129
|
let timer = null;
|
|
910
1130
|
const start = () => {
|
|
@@ -926,15 +1146,9 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
926
1146
|
document.removeEventListener("visibilitychange", onVis);
|
|
927
1147
|
};
|
|
928
1148
|
}, [selected.id, refreshMessages]);
|
|
929
|
-
async function handleSend() {
|
|
930
|
-
if (!draft.trim()) return;
|
|
931
|
-
const body = draft;
|
|
932
|
-
setDraft("");
|
|
933
|
-
await send(body);
|
|
934
|
-
}
|
|
935
1149
|
const accent = CHANNEL_ACCENT[selected.channel];
|
|
936
|
-
const rows =
|
|
937
|
-
const jumpTo =
|
|
1150
|
+
const rows = React7__default.useMemo(() => buildRows(messages.filter((m) => !isFoldedRow(m))), [messages]);
|
|
1151
|
+
const jumpTo = React7__default.useCallback((providerId) => {
|
|
938
1152
|
const el = threadRef.current?.querySelector(`[data-provider-id="${CSS.escape(providerId)}"]`);
|
|
939
1153
|
if (!el) return;
|
|
940
1154
|
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
@@ -967,17 +1181,19 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
967
1181
|
}, "aria-label": t("conversations.thread.back"), children: /* @__PURE__ */ jsx(ChevronLeft, { className: "h-5 w-5" }) }),
|
|
968
1182
|
/* @__PURE__ */ jsx(Avatar, { name: selected.contactName, accent: selected.accent, size: "sm", channel: selected.channel }),
|
|
969
1183
|
/* @__PURE__ */ jsxs("div", { className: "min-w-0", children: [
|
|
970
|
-
/* @__PURE__ */
|
|
971
|
-
|
|
972
|
-
/* @__PURE__ */ jsx(ChannelBadge, { channel: selected.channel }),
|
|
1184
|
+
/* @__PURE__ */ jsxs("p", { className: "flex min-w-0 items-center gap-1.5 text-sm font-semibold text-foreground", children: [
|
|
1185
|
+
/* @__PURE__ */ jsx("span", { className: "truncate", children: selected.contactName }),
|
|
973
1186
|
selected.channel === "whatsapp" && selected.provider && /* @__PURE__ */ jsx(
|
|
974
1187
|
"span",
|
|
975
1188
|
{
|
|
976
1189
|
title: "As respostas saem por este n\xFAmero, o mesmo em que a pessoa escreveu.",
|
|
977
|
-
className: "shrink-0 rounded-full bg-muted px-1.5 text-[10px] text-muted-foreground",
|
|
1190
|
+
className: "shrink-0 rounded-full bg-muted px-1.5 text-[10px] font-normal text-muted-foreground",
|
|
978
1191
|
children: selected.provider === "tyxter" ? "n\xFAmero oficial" : "n\xFAmero do dia a dia"
|
|
979
1192
|
}
|
|
980
|
-
)
|
|
1193
|
+
)
|
|
1194
|
+
] }),
|
|
1195
|
+
!panelOpen && /* @__PURE__ */ jsxs("p", { className: "flex items-center gap-1.5 text-xs text-muted-foreground", children: [
|
|
1196
|
+
/* @__PURE__ */ jsx(ChannelBadge, { channel: selected.channel }),
|
|
981
1197
|
/* @__PURE__ */ jsx("span", { className: "truncate", children: selected.contactHandle })
|
|
982
1198
|
] })
|
|
983
1199
|
] })
|
|
@@ -1056,26 +1272,16 @@ function MessageThread({ selected, onTogglePanel, panelOpen, onBack, backAlways,
|
|
|
1056
1272
|
] }),
|
|
1057
1273
|
/* @__PURE__ */ jsxs("div", { className: "border-t border-border bg-card", children: [
|
|
1058
1274
|
/* @__PURE__ */ jsx(SendWindowBanner, { state: win }),
|
|
1059
|
-
/* @__PURE__ */
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
}
|
|
1070
|
-
},
|
|
1071
|
-
rows: 1,
|
|
1072
|
-
disabled: !canType,
|
|
1073
|
-
placeholder: canType ? t("conversations.thread.reply", { channel: CHANNEL_LABELS[selected.channel] }) : win.mode.kind === "blocked" ? "Envio bloqueado" : "Fora da janela \u2014 envie um template",
|
|
1074
|
-
className: "max-h-32 min-h-[40px] resize-none rounded-md border-border bg-background shadow-none focus:border-primary focus-visible:ring-0 focus-visible:ring-offset-0 disabled:bg-muted/40 disabled:text-muted-foreground disabled:opacity-100"
|
|
1075
|
-
}
|
|
1076
|
-
) }),
|
|
1077
|
-
/* @__PURE__ */ jsx(Button, { onClick: () => void handleSend(), disabled: !canType || sending || !draft.trim(), "aria-label": t("conversations.thread.send"), children: /* @__PURE__ */ jsx(Send, { className: "h-4 w-4" }) })
|
|
1078
|
-
] })
|
|
1275
|
+
/* @__PURE__ */ jsx(
|
|
1276
|
+
Composer,
|
|
1277
|
+
{
|
|
1278
|
+
canType,
|
|
1279
|
+
sending,
|
|
1280
|
+
placeholder: canType ? t("conversations.thread.reply", { channel: CHANNEL_LABELS[selected.channel] }) : win.mode.kind === "blocked" ? "Envio bloqueado" : "Fora da janela \u2014 envie um template",
|
|
1281
|
+
onSendText: (text) => send(text),
|
|
1282
|
+
onSendMedia: (input) => sendMedia(input)
|
|
1283
|
+
}
|
|
1284
|
+
)
|
|
1079
1285
|
] })
|
|
1080
1286
|
] });
|
|
1081
1287
|
}
|
|
@@ -1102,8 +1308,8 @@ function declaredCompany(meta) {
|
|
|
1102
1308
|
};
|
|
1103
1309
|
}
|
|
1104
1310
|
function useContactProfile(personId, handle) {
|
|
1105
|
-
const [profile, setProfile] =
|
|
1106
|
-
|
|
1311
|
+
const [profile, setProfile] = React7__default.useState(void 0);
|
|
1312
|
+
React7__default.useEffect(() => {
|
|
1107
1313
|
let alive = true;
|
|
1108
1314
|
setProfile(void 0);
|
|
1109
1315
|
const sb = getSupabaseClientOptional();
|
|
@@ -1357,14 +1563,14 @@ function NewConversationPanel({
|
|
|
1357
1563
|
const create = useConversationsStore((s) => s.create);
|
|
1358
1564
|
const config = useConversationsConfig();
|
|
1359
1565
|
const guardConversations = useLimitGuard("conversations_month");
|
|
1360
|
-
const [channel, setChannel] =
|
|
1361
|
-
const [contact, setContact] =
|
|
1362
|
-
const [typedHandle, setTypedHandle] =
|
|
1363
|
-
const [creatingContact, setCreatingContact] =
|
|
1364
|
-
const [firstMessage, setFirstMessage] =
|
|
1365
|
-
const [submitting, setSubmitting] =
|
|
1366
|
-
const [pickerKey, setPickerKey] =
|
|
1367
|
-
|
|
1566
|
+
const [channel, setChannel] = React7__default.useState("whatsapp");
|
|
1567
|
+
const [contact, setContact] = React7__default.useState(null);
|
|
1568
|
+
const [typedHandle, setTypedHandle] = React7__default.useState("");
|
|
1569
|
+
const [creatingContact, setCreatingContact] = React7__default.useState(false);
|
|
1570
|
+
const [firstMessage, setFirstMessage] = React7__default.useState("");
|
|
1571
|
+
const [submitting, setSubmitting] = React7__default.useState(false);
|
|
1572
|
+
const [pickerKey, setPickerKey] = React7__default.useState(0);
|
|
1573
|
+
React7__default.useEffect(() => {
|
|
1368
1574
|
if (open) {
|
|
1369
1575
|
setChannel("whatsapp");
|
|
1370
1576
|
setContact(null);
|
|
@@ -1481,9 +1687,9 @@ function useCaixaAoVivo() {
|
|
|
1481
1687
|
const load = useConversationsStore((s) => s.load);
|
|
1482
1688
|
const refreshMessages = useConversationsStore((s) => s.refreshMessages);
|
|
1483
1689
|
const selectedId = useConversationsStore((s) => s.selectedId);
|
|
1484
|
-
const abertoRef =
|
|
1690
|
+
const abertoRef = React7.useRef(selectedId);
|
|
1485
1691
|
abertoRef.current = selectedId;
|
|
1486
|
-
|
|
1692
|
+
React7.useEffect(() => {
|
|
1487
1693
|
if (!tenantId) return;
|
|
1488
1694
|
return assinarChegada(tenantId, ({ conversationId }) => {
|
|
1489
1695
|
void load();
|
|
@@ -1501,16 +1707,16 @@ function InboxView({ layout = "page", newSignal = 0 } = {}) {
|
|
|
1501
1707
|
const isWideViewport = useMediaQuery("(min-width: 1280px)");
|
|
1502
1708
|
const isWidePanel = isWideViewport && !dock;
|
|
1503
1709
|
const railOpen = useRightRailStore((s) => s.open);
|
|
1504
|
-
const [panelOpen, setPanelOpen] =
|
|
1505
|
-
const [newOpen, setNewOpen] =
|
|
1710
|
+
const [panelOpen, setPanelOpen] = React7__default.useState(false);
|
|
1711
|
+
const [newOpen, setNewOpen] = React7__default.useState(false);
|
|
1506
1712
|
const selected = conversations.find((c) => c.id === selectedId) ?? null;
|
|
1507
|
-
|
|
1713
|
+
React7__default.useEffect(() => {
|
|
1508
1714
|
if (newSignal > 0) setNewOpen(true);
|
|
1509
1715
|
}, [newSignal]);
|
|
1510
|
-
|
|
1716
|
+
React7__default.useEffect(() => {
|
|
1511
1717
|
setPanelOpen(isWidePanel && !railOpen);
|
|
1512
1718
|
}, [isWidePanel, railOpen]);
|
|
1513
|
-
const newActions =
|
|
1719
|
+
const newActions = React7__default.useMemo(() => [{
|
|
1514
1720
|
id: "new-conversation",
|
|
1515
1721
|
label: t("conversations.list.new"),
|
|
1516
1722
|
icon: SquarePen,
|
|
@@ -1590,7 +1796,7 @@ function conversationIdFromPath(path) {
|
|
|
1590
1796
|
return m ? decodeURIComponent(m[1]) : null;
|
|
1591
1797
|
}
|
|
1592
1798
|
function ConversationsPage({ store, config }) {
|
|
1593
|
-
|
|
1799
|
+
React7__default.useEffect(() => {
|
|
1594
1800
|
const wanted = requestedContact();
|
|
1595
1801
|
if (!wanted) {
|
|
1596
1802
|
const fromPath = conversationIdFromPath(currentAppPath());
|
|
@@ -1608,7 +1814,7 @@ function ConversationsPage({ store, config }) {
|
|
|
1608
1814
|
} catch {
|
|
1609
1815
|
}
|
|
1610
1816
|
}, []);
|
|
1611
|
-
|
|
1817
|
+
React7__default.useEffect(() => {
|
|
1612
1818
|
const write = (id) => {
|
|
1613
1819
|
const path = currentAppPath();
|
|
1614
1820
|
if (!path.startsWith("/conversations")) return;
|
|
@@ -1633,5 +1839,5 @@ function ConversationsPage({ store, config }) {
|
|
|
1633
1839
|
}
|
|
1634
1840
|
|
|
1635
1841
|
export { ConversationsPage, conversationIdFromPath };
|
|
1636
|
-
//# sourceMappingURL=ConversationsPage-
|
|
1637
|
-
//# sourceMappingURL=ConversationsPage-
|
|
1842
|
+
//# sourceMappingURL=ConversationsPage-VXGZBHZG.js.map
|
|
1843
|
+
//# sourceMappingURL=ConversationsPage-VXGZBHZG.js.map
|