@adminide-stack/yantra-mobile 12.0.87 → 12.0.88-alpha.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/lib/features/agent-chat/NativeAgentChat.js +14 -16
- package/lib/features/agent-chat/NativeAgentChat.js.map +1 -1
- package/lib/features/agent-chat/edgeSwipe.js +8 -0
- package/lib/features/agent-chat/edgeSwipe.js.map +1 -0
- package/lib/features/agent-chat/edgeZone.js +6 -0
- package/lib/features/agent-chat/edgeZone.js.map +1 -0
- package/lib/features/canvas/useCanvasSession.js +11 -3
- package/lib/features/canvas/useCanvasSession.js.map +1 -1
- package/lib/features/chat/emptyChatResponse.js +1 -1
- package/lib/features/chat/emptyChatResponse.js.map +1 -1
- package/lib/features/chat/streamingMarkdown.js +3 -2
- package/lib/features/chat/streamingMarkdown.js.map +1 -1
- package/lib/features/job-search/JobSearchAgentChatPane.js +33 -5
- package/lib/features/job-search/JobSearchAgentChatPane.js.map +1 -1
- package/lib/features/job-search/JobSearchExperience.js +12 -16
- package/lib/features/job-search/JobSearchExperience.js.map +1 -1
- package/lib/features/messaging/chatModel.js +60 -33
- package/lib/features/messaging/chatModel.js.map +1 -1
- package/lib/features/shopping/ShoppingExperience.js +11 -16
- package/lib/features/shopping/ShoppingExperience.js.map +1 -1
- package/lib/features/travel/CarPriceGuide.js +132 -0
- package/lib/features/travel/CarPriceGuide.js.map +1 -0
- package/lib/features/travel/CarResultCard.js +267 -0
- package/lib/features/travel/CarResultCard.js.map +1 -0
- package/lib/features/travel/FlightDealsBoard.js +4 -8
- package/lib/features/travel/FlightDealsBoard.js.map +1 -1
- package/lib/features/travel/FlightResultCard.js +266 -0
- package/lib/features/travel/FlightResultCard.js.map +1 -0
- package/lib/features/travel/PopularDestinations.js +11 -11
- package/lib/features/travel/PopularDestinations.js.map +1 -1
- package/lib/features/travel/TravelAgentChatPane.js +2 -1
- package/lib/features/travel/TravelAgentChatPane.js.map +1 -1
- package/lib/features/travel/TravelBookHero.js +12 -2
- package/lib/features/travel/TravelBookHero.js.map +1 -1
- package/lib/features/travel/TravelExperience.js +407 -149
- package/lib/features/travel/TravelExperience.js.map +1 -1
- package/lib/features/travel/TravelPropertyCard.js +63 -55
- package/lib/features/travel/TravelPropertyCard.js.map +1 -1
- package/lib/features/travel/TravelResultsMap.js +4 -3
- package/lib/features/travel/TravelResultsMap.js.map +1 -1
- package/lib/features/travel/carView.js +190 -0
- package/lib/features/travel/carView.js.map +1 -0
- package/lib/features/travel/catalog.js +10 -1
- package/lib/features/travel/catalog.js.map +1 -1
- package/lib/features/travel/chat/TravelChatResultCard.js +19 -4
- package/lib/features/travel/chat/TravelChatResultCard.js.map +1 -1
- package/lib/features/travel/chat/widgetContent.js +30 -8
- package/lib/features/travel/chat/widgetContent.js.map +1 -1
- package/lib/features/travel/flightView.js +106 -0
- package/lib/features/travel/flightView.js.map +1 -0
- package/lib/features/travel/parseTravelIntent.js +81 -17
- package/lib/features/travel/parseTravelIntent.js.map +1 -1
- package/lib/features/travel/searchError.js +15 -0
- package/lib/features/travel/searchError.js.map +1 -0
- package/lib/features/travel/services/placePredictions.js +1 -1
- package/lib/features/travel/services/placePredictions.js.map +1 -1
- package/lib/features/travel/services/travelFlightSearch.js +35 -7
- package/lib/features/travel/services/travelFlightSearch.js.map +1 -1
- package/lib/features/travel/services/travelPropertySearch.js +15 -10
- package/lib/features/travel/services/travelPropertySearch.js.map +1 -1
- package/lib/features/travel/types.js.map +1 -1
- package/lib/features/travel/useTravelSearch.js +43 -20
- package/lib/features/travel/useTravelSearch.js.map +1 -1
- package/lib/hooks/useCdecliChannel.js.map +1 -1
- package/lib/screens/TravelNative/index.js +3 -2
- package/lib/screens/TravelNative/index.js.map +1 -1
- package/lib/screens/WebBuilder/webbuilderWarmCache.js +16 -3
- package/lib/screens/WebBuilder/webbuilderWarmCache.js.map +1 -1
- package/package.json +4 -4
|
@@ -17,6 +17,10 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
function compareIds(a, b) {
|
|
21
|
+
if (a === b) return 0;
|
|
22
|
+
return a < b ? -1 : 1;
|
|
23
|
+
}
|
|
20
24
|
function displayNameOf(user, fallback = "Unknown") {
|
|
21
25
|
var _a, _b, _c, _d;
|
|
22
26
|
if (!user) return fallback;
|
|
@@ -44,24 +48,6 @@ function toEpoch(value) {
|
|
|
44
48
|
const parsed = Date.parse(value);
|
|
45
49
|
return Number.isNaN(parsed) ? 0 : parsed;
|
|
46
50
|
}
|
|
47
|
-
function toChatMessage(post, viewerId) {
|
|
48
|
-
var _a, _b, _c;
|
|
49
|
-
const author = pickAuthor(post);
|
|
50
|
-
const attachments = toChatAttachments(post);
|
|
51
|
-
return {
|
|
52
|
-
id: String(post.id),
|
|
53
|
-
body: bodyOf(post, attachments.length > 0),
|
|
54
|
-
createdAt: toEpoch(post.createdAt),
|
|
55
|
-
authorId: (author == null ? void 0 : author.id) ? String(author.id) : null,
|
|
56
|
-
authorName: displayNameOf(author),
|
|
57
|
-
authorAvatar: (_c = (_b = author == null ? void 0 : author.picture) != null ? _b : (_a = author == null ? void 0 : author.profile) == null ? void 0 : _a.picture) != null ? _c : null,
|
|
58
|
-
isMine: !!(author == null ? void 0 : author.id) && String(author.id) === viewerId,
|
|
59
|
-
isDeleted: !!post.deletedAt,
|
|
60
|
-
isEdited: !!post.editedAt,
|
|
61
|
-
attachments,
|
|
62
|
-
reactions: toChatReactions(post.reactionSummary, viewerId)
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
51
|
function kindOfMime(mimeType) {
|
|
66
52
|
if (mimeType.startsWith("image/")) return "image";
|
|
67
53
|
if (mimeType.startsWith("audio/")) return "audio";
|
|
@@ -148,6 +134,24 @@ function toChatReactions(summary, viewerId) {
|
|
|
148
134
|
};
|
|
149
135
|
});
|
|
150
136
|
}
|
|
137
|
+
function toChatMessage(post, viewerId) {
|
|
138
|
+
var _a, _b, _c;
|
|
139
|
+
const author = pickAuthor(post);
|
|
140
|
+
const attachments = toChatAttachments(post);
|
|
141
|
+
return {
|
|
142
|
+
id: String(post.id),
|
|
143
|
+
body: bodyOf(post, attachments.length > 0),
|
|
144
|
+
createdAt: toEpoch(post.createdAt),
|
|
145
|
+
authorId: (author == null ? void 0 : author.id) ? String(author.id) : null,
|
|
146
|
+
authorName: displayNameOf(author),
|
|
147
|
+
authorAvatar: (_c = (_b = author == null ? void 0 : author.picture) != null ? _b : (_a = author == null ? void 0 : author.profile) == null ? void 0 : _a.picture) != null ? _c : null,
|
|
148
|
+
isMine: !!(author == null ? void 0 : author.id) && String(author.id) === viewerId,
|
|
149
|
+
isDeleted: !!post.deletedAt,
|
|
150
|
+
isEdited: !!post.editedAt,
|
|
151
|
+
attachments,
|
|
152
|
+
reactions: toChatReactions(post.reactionSummary, viewerId)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
151
155
|
function applyReactionSummary(messages, messageId, summary, viewerId) {
|
|
152
156
|
return messages.map((m) => m.id === messageId ? __spreadProps(__spreadValues({}, m), {
|
|
153
157
|
reactions: toChatReactions(summary, viewerId)
|
|
@@ -184,7 +188,7 @@ function mergeMessages(existing, incoming) {
|
|
|
184
188
|
const byId = /* @__PURE__ */ new Map();
|
|
185
189
|
for (const m of existing) byId.set(m.id, m);
|
|
186
190
|
for (const m of incoming) byId.set(m.id, m);
|
|
187
|
-
return Array.from(byId.values()).sort((a, b) => a.createdAt - b.createdAt || (a.id
|
|
191
|
+
return Array.from(byId.values()).sort((a, b) => a.createdAt - b.createdAt || compareIds(a.id, b.id));
|
|
188
192
|
}
|
|
189
193
|
function reconcileOptimistic(messages, confirmed, windowMs = 6e4) {
|
|
190
194
|
if (!confirmed.isMine) return mergeMessages(messages, [confirmed]);
|
|
@@ -241,6 +245,11 @@ function looksLikeMachineTitle(value) {
|
|
|
241
245
|
if (/^group(\s+chat)?$/i.test(label)) return true;
|
|
242
246
|
return false;
|
|
243
247
|
}
|
|
248
|
+
function storedLabelOf(channel) {
|
|
249
|
+
if (!looksLikeMachineTitle(channel.displayName)) return channel.displayName.trim();
|
|
250
|
+
if (!looksLikeMachineTitle(channel.title)) return channel.title.trim();
|
|
251
|
+
return "";
|
|
252
|
+
}
|
|
244
253
|
function toConversation(channel, viewerId) {
|
|
245
254
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
246
255
|
const peerCandidate = peerOf(channel, viewerId);
|
|
@@ -248,14 +257,15 @@ function toConversation(channel, viewerId) {
|
|
|
248
257
|
const populatedMembers = ((_b = channel.members) != null ? _b : []).filter(Boolean);
|
|
249
258
|
const twoParty = populatedMembers.length === 2 && Boolean(peerCandidate);
|
|
250
259
|
const hasMachineLabel = looksLikeMachineTitle(channel.displayName) && looksLikeMachineTitle(channel.title);
|
|
251
|
-
const
|
|
260
|
+
const storedLabel = storedLabelOf(channel);
|
|
261
|
+
const namedGroup = Boolean(channel.type) && Boolean(storedLabel) && storedLabel.toLowerCase() !== displayNameOf(peerCandidate, "").toLowerCase();
|
|
262
|
+
const isDirect = explicitDirect || twoParty && !namedGroup || !channel.type && hasMachineLabel && Boolean(peerCandidate);
|
|
252
263
|
const peer = isDirect ? peerCandidate : null;
|
|
253
264
|
const names = memberNames(channel, viewerId);
|
|
254
265
|
const lastAuthor = channel.lastMessage ? pickAuthor(channel.lastMessage) : null;
|
|
255
266
|
const lastAuthorName = lastAuthor && String(lastAuthor.id) !== viewerId ? displayNameOf(lastAuthor, "") : "";
|
|
256
267
|
const creatorName = displayNameOf(channel.creator, "");
|
|
257
268
|
const groupFallback = names.length ? names.join(", ") : lastAuthorName || (creatorName && creatorName !== "Unknown" ? creatorName : "Chat");
|
|
258
|
-
const storedLabel = !looksLikeMachineTitle(channel.displayName) ? channel.displayName.trim() : !looksLikeMachineTitle(channel.title) ? channel.title.trim() : "";
|
|
259
269
|
const title = isDirect ? displayNameOf(peer, storedLabel || lastAuthorName || "Direct message") : storedLabel || groupFallback;
|
|
260
270
|
const topic = looksLikeMachineTitle(channel.topic) ? "" : ((_c = channel.topic) != null ? _c : "").trim();
|
|
261
271
|
const preview = ((_e = (_d = channel.lastMessage) == null ? void 0 : _d.message) == null ? void 0 : _e.trim()) || attachmentPreview(channel.lastMessage) || topic;
|
|
@@ -274,7 +284,7 @@ function toConversation(channel, viewerId) {
|
|
|
274
284
|
};
|
|
275
285
|
}
|
|
276
286
|
function sortConversations(list) {
|
|
277
|
-
return list.slice().sort((a, b) => b.lastActivity - a.lastActivity || a.title.localeCompare(b.title) || (a.id
|
|
287
|
+
return list.slice().sort((a, b) => b.lastActivity - a.lastActivity || a.title.localeCompare(b.title) || compareIds(a.id, b.id));
|
|
278
288
|
}
|
|
279
289
|
function conversationListKey(c) {
|
|
280
290
|
var _a;
|
|
@@ -285,17 +295,30 @@ function conversationListKey(c) {
|
|
|
285
295
|
if (c.isDirect) return `title:${title}`;
|
|
286
296
|
return `title:${title}`;
|
|
287
297
|
}
|
|
298
|
+
function personTitle(c) {
|
|
299
|
+
const title = c.title.trim().toLowerCase();
|
|
300
|
+
if (!title || title === "chat" || title === "unknown" || title.includes(",")) return "";
|
|
301
|
+
return title;
|
|
302
|
+
}
|
|
288
303
|
function dedupeConversationList(list) {
|
|
289
|
-
const
|
|
290
|
-
const
|
|
291
|
-
const
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
304
|
+
const peers = /* @__PURE__ */ new Set();
|
|
305
|
+
const peerTitles = /* @__PURE__ */ new Set();
|
|
306
|
+
const titles = /* @__PURE__ */ new Set();
|
|
307
|
+
return sortConversations(list).filter((c) => {
|
|
308
|
+
var _a;
|
|
309
|
+
const title = personTitle(c);
|
|
310
|
+
const peerId = ((_a = c.peer) == null ? void 0 : _a.id) ? String(c.peer.id) : "";
|
|
311
|
+
if (peerId) {
|
|
312
|
+
if (peers.has(peerId) || title && titles.has(title)) return false;
|
|
313
|
+
peers.add(peerId);
|
|
314
|
+
if (title) peerTitles.add(title);
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
if (!title) return true;
|
|
318
|
+
if (titles.has(title) || peerTitles.has(title)) return false;
|
|
319
|
+
titles.add(title);
|
|
320
|
+
return true;
|
|
321
|
+
});
|
|
299
322
|
}
|
|
300
323
|
function mergeConversations(existing, incoming) {
|
|
301
324
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -303,10 +326,14 @@ function mergeConversations(existing, incoming) {
|
|
|
303
326
|
for (const c of incoming) byId.set(c.id, c);
|
|
304
327
|
return dedupeConversationList(Array.from(byId.values()));
|
|
305
328
|
}
|
|
329
|
+
function subtitleAfterPost(conv, preview) {
|
|
330
|
+
if (!preview) return conv.subtitle;
|
|
331
|
+
return preview === conv.title ? "" : preview;
|
|
332
|
+
}
|
|
306
333
|
function patchConversationAfterPost(conv, post, viewerId) {
|
|
307
334
|
var _a;
|
|
308
335
|
const preview = ((_a = post.message) == null ? void 0 : _a.trim()) || attachmentPreview(post);
|
|
309
|
-
const nextSubtitle =
|
|
336
|
+
const nextSubtitle = subtitleAfterPost(conv, preview);
|
|
310
337
|
const activity = toEpoch(post.createdAt) || Date.now();
|
|
311
338
|
const author = pickAuthor(post);
|
|
312
339
|
const fromPeer = author && String(author.id) !== viewerId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chatModel.js","sources":["../../../src/features/messaging/chatModel.ts"],"sourcesContent":["/**\n * Pure shaping between messenger-box's wire types and what the chat UI renders.\n *\n * Everything here is a plain function over plain data - no React, no seams, no\n * clock beyond what is passed in - because this is where the bugs that actually\n * ruin a chat client live: messages in the wrong order, a duplicate after a\n * reconnect, an optimistic row that never resolves, a DM titled with your own\n * name. Those are all cheap to unit-test and expensive to debug on a device.\n */\n\nexport interface ChatUser {\n id: string;\n givenName?: string | null;\n familyName?: string | null;\n username?: string | null;\n email?: string | null;\n picture?: string | null;\n profile?: { displayName?: string | null; picture?: string | null } | null;\n}\n\nexport interface WirePost {\n id: string;\n message?: string | null;\n type?: string | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n editedAt?: string | null;\n deletedAt?: string | null;\n rootId?: string | null;\n parentId?: string | null;\n filenames?: (string | null)[] | null;\n props?: Record<string, unknown> | null;\n /** Attached files (messenger-box `Post.files`, linked to the post by id). */\n files?: { data?: (WireFile | null)[] | null } | null;\n author?: ChatUser | null;\n creator?: ChatUser | null;\n reactionSummary?: WireReaction[] | null;\n}\n\nexport interface WireFile {\n id?: string | null;\n name?: string | null;\n mimeType?: string | null;\n url?: string | null;\n width?: number | null;\n height?: number | null;\n size?: number | null;\n}\n\n/** What a message's `props.attachmentKind` says the attachments are (set when sending). */\nexport type ChatAttachmentKind = 'image' | 'audio' | 'file';\n\n/**\n * One attached file. `url` is what the server returned (an image-resizer thumbnail for every\n * type) or, while sending, the local file; `key` is the storage key, from which the UI builds\n * the full-size / playable CDN URL (see `attachmentUrl`).\n */\nexport interface ChatAttachment {\n id: string;\n kind: ChatAttachmentKind;\n name: string;\n mimeType: string;\n url: string;\n key: string | null;\n width?: number | null;\n height?: number | null;\n /** Voice notes: recorded length (from the message's props). */\n durationMs?: number | null;\n}\n\nexport interface WireReaction {\n reaction: string;\n count: number;\n userIds?: (string | null)[] | null;\n}\n\n/** One Tapback on a message, grouped across users. */\nexport interface ChatReaction {\n reaction: string;\n count: number;\n /** The viewer is one of the reactors. */\n mine: boolean;\n userIds: string[];\n}\n\nexport interface WireChannelMember {\n id?: string | null;\n user?: ChatUser | null;\n msgCount?: number | null;\n lastViewedAt?: string | null;\n}\n\nexport interface WireChannel {\n id: string;\n type?: string | null;\n orgName?: string | null;\n title?: string | null;\n displayName?: string | null;\n topic?: string | null;\n lastPostAt?: string | null;\n totalMsgCount?: number | null;\n createdAt?: string | null;\n lastMessage?: WirePost | null;\n creator?: ChatUser | null;\n members?: (WireChannelMember | null)[] | null;\n}\n\n/** Where an optimistic message is in its lifecycle. */\nexport type ChatSendState = 'sending' | 'sent' | 'failed';\n\nexport interface ChatMessage {\n id: string;\n body: string;\n createdAt: number;\n authorId: string | null;\n authorName: string;\n authorAvatar?: string | null;\n isMine: boolean;\n isDeleted: boolean;\n isEdited: boolean;\n attachments: ChatAttachment[];\n /** Tapbacks, in first-use order. Empty when nobody reacted. */\n reactions: ChatReaction[];\n /** Present only on messages this device is still sending. */\n sendState?: ChatSendState;\n /** The optimistic id this row replaced, so the UI can animate rather than jump. */\n replacedClientId?: string;\n}\n\nexport interface ChatConversation {\n id: string;\n title: string;\n subtitle: string;\n avatarUrl?: string | null;\n /** Sort key; 0 when the channel has never had a message. */\n lastActivity: number;\n unreadCount: number;\n isDirect: boolean;\n /** The other participant, for a DM. Null for groups. */\n peer: ChatUser | null;\n}\n\n/**\n * A person's display name, in the order a human would expect.\n *\n * Email is the last resort and is truncated at the `@`: a transcript full of\n * `someone@example.com` is worse than one full of `someone`.\n */\nexport function displayNameOf(user?: ChatUser | null, fallback = 'Unknown'): string {\n if (!user) return fallback;\n const profileName = user.profile?.displayName?.trim();\n if (profileName) return profileName;\n const fullName = [user.givenName, user.familyName].filter(Boolean).join(' ').trim();\n if (fullName) return fullName;\n const username = user.username?.trim();\n if (username) return username;\n const email = user.email?.trim();\n if (email) return email.split('@')[0] || fallback;\n return fallback;\n}\n\nfunction memberNames(channel: WireChannel, viewerId: string): string[] {\n return (channel.members ?? [])\n .map((member) => member?.user)\n .filter((user): user is ChatUser => Boolean(user?.id) && String(user.id) !== viewerId)\n .map((user) => displayNameOf(user, ''))\n .filter(Boolean)\n .slice(0, 3);\n}\n\n/**\n * messenger-box populates `author` on some write paths and `creator` on others\n * (`sendMessage` sets creator). Reading only one shows \"Unknown\" for a large\n * fraction of real transcripts.\n */\nexport function pickAuthor(post: WirePost): ChatUser | null {\n return post.author ?? post.creator ?? null;\n}\n\n/** Epoch millis, tolerant of nulls and unparseable values. */\nexport function toEpoch(value?: string | number | null): number {\n if (value == null) return 0;\n if (typeof value === 'number') return Number.isFinite(value) ? value : 0;\n const parsed = Date.parse(value);\n return Number.isNaN(parsed) ? 0 : parsed;\n}\n\nexport function toChatMessage(post: WirePost, viewerId: string): ChatMessage {\n const author = pickAuthor(post);\n const attachments = toChatAttachments(post);\n return {\n id: String(post.id),\n body: bodyOf(post, attachments.length > 0),\n createdAt: toEpoch(post.createdAt),\n authorId: author?.id ? String(author.id) : null,\n authorName: displayNameOf(author),\n authorAvatar: author?.picture ?? author?.profile?.picture ?? null,\n isMine: !!author?.id && String(author.id) === viewerId,\n isDeleted: !!post.deletedAt,\n isEdited: !!post.editedAt,\n attachments,\n reactions: toChatReactions(post.reactionSummary, viewerId),\n };\n}\n\nfunction kindOfMime(mimeType: string): ChatAttachmentKind {\n if (mimeType.startsWith('image/')) return 'image';\n if (mimeType.startsWith('audio/')) return 'audio';\n return 'file';\n}\n\n/**\n * The storage key inside a file URL. messenger-box hands back image-resizer URLs\n * (`<handler>/fit-in/150x150/<key>`) for every attachment; a plain storage URL or a bare key\n * also works.\n */\nexport function fileKeyFromUrl(url: string | null | undefined): string | null {\n const value = (url ?? '').trim();\n if (!value) return null;\n const resized = value.match(/\\/fit-in\\/\\d+x\\d+\\/(.+)$/);\n if (resized) return decodeURIComponent(resized[1].split('?')[0]);\n if (!/^[a-z]+:\\/\\//i.test(value)) return value.split('?')[0];\n if (/^(file|content|ph|assets-library):/i.test(value)) return null;\n try {\n return decodeURIComponent(new URL(value).pathname.replace(/^\\/+/, '')) || null;\n } catch {\n return null;\n }\n}\n\n/** Full-size (image) or playable (audio) URL: the CDN copy when a base is known, else what we have. */\nexport function attachmentUrl(attachment: ChatAttachment, fileBaseUrl?: string | null): string {\n if (!attachment.key || !fileBaseUrl) return attachment.url;\n return `${fileBaseUrl.replace(/\\/+$/, '')}/${attachment.key}`;\n}\n\n/** `props` is an AnyObject scalar: an object from some paths, a JSON string from others. */\nfunction propsOf(post: WirePost | null | undefined): Record<string, unknown> {\n const raw = post?.props as unknown;\n if (raw && typeof raw === 'object') return raw as Record<string, unknown>;\n if (typeof raw === 'string') {\n try {\n const parsed = JSON.parse(raw);\n return parsed && typeof parsed === 'object' ? parsed : {};\n } catch {\n return {};\n }\n }\n return {};\n}\n\nexport function toChatAttachments(post: WirePost): ChatAttachment[] {\n const props = propsOf(post) as { attachmentKind?: unknown; voiceDurationMs?: unknown };\n const durationMs = typeof props.voiceDurationMs === 'number' ? props.voiceDurationMs : null;\n return (post.files?.data ?? [])\n .filter((f): f is WireFile => Boolean(f?.url))\n .map((f, i) => {\n const mimeType = f.mimeType ?? 'application/octet-stream';\n const kind = kindOfMime(mimeType);\n return {\n id: String(f.id ?? `${post.id}-${i}`),\n kind,\n name: f.name ?? 'file',\n mimeType,\n url: String(f.url),\n key: fileKeyFromUrl(f.url),\n width: f.width ?? null,\n height: f.height ?? null,\n durationMs: kind === 'audio' ? durationMs : null,\n };\n });\n}\n\n/**\n * The text of an attachment-only message. messenger-box requires non-blank message text, so this\n * label is sent as the text: push notifications and other clients read it, and this app hides it\n * inside the bubble (see `toChatMessage`).\n */\nexport const ATTACHMENT_LABELS: Record<ChatAttachmentKind, string> = {\n image: '📷 Photo',\n audio: '🎤 Voice message',\n file: '📎 Attachment',\n};\n\n/** Chat-list preview for a message that is only an attachment. */\nexport function attachmentPreview(post: WirePost | null | undefined): string {\n const kind = propsOf(post).attachmentKind;\n return typeof kind === 'string' && kind in ATTACHMENT_LABELS ? ATTACHMENT_LABELS[kind as ChatAttachmentKind] : '';\n}\n\nconst LABEL_TEXTS = new Set(Object.values(ATTACHMENT_LABELS));\n\n/** The bubble text: an attachment-only message's label is not shown next to the attachment itself. */\nfunction bodyOf(post: WirePost, hasAttachments: boolean): string {\n const body = post.message ?? '';\n const trimmed = body.trim();\n const label = attachmentPreview(post);\n if (label && trimmed === label) return '';\n // Same label with the files attached, even if props did not come back.\n return hasAttachments && LABEL_TEXTS.has(trimmed) ? '' : body;\n}\n\nexport function toChatReactions(summary: WireReaction[] | null | undefined, viewerId: string): ChatReaction[] {\n return (summary ?? [])\n .filter((r) => r && r.reaction && r.count > 0)\n .map((r) => {\n const userIds = (r.userIds ?? []).filter((u): u is string => typeof u === 'string' && u.length > 0);\n return { reaction: r.reaction, count: r.count, userIds, mine: userIds.includes(viewerId) };\n });\n}\n\n/** Replace one message's reactions with the server's latest summary. */\nexport function applyReactionSummary(\n messages: ChatMessage[],\n messageId: string,\n summary: WireReaction[] | null | undefined,\n viewerId: string,\n): ChatMessage[] {\n return messages.map((m) => (m.id === messageId ? { ...m, reactions: toChatReactions(summary, viewerId) } : m));\n}\n\n/**\n * The viewer's reactions after picking `emoji` (null = remove). One Tapback per person,\n * like iMessage: a new pick replaces the old one, the same pick removes it.\n */\nexport function withViewerReaction(reactions: ChatReaction[], emoji: string | null, viewerId: string): ChatReaction[] {\n const current = reactions.find((r) => r.mine)?.reaction ?? null;\n const next = emoji && emoji !== current ? emoji : null;\n const out = reactions\n .map((r) =>\n r.mine ? { ...r, mine: false, count: r.count - 1, userIds: r.userIds.filter((u) => u !== viewerId) } : r,\n )\n .filter((r) => r.count > 0);\n if (!next) return out;\n const idx = out.findIndex((r) => r.reaction === next);\n if (idx >= 0) {\n const r = out[idx];\n out[idx] = { ...r, mine: true, count: r.count + 1, userIds: [...r.userIds, viewerId] };\n return out;\n }\n return [...out, { reaction: next, count: 1, mine: true, userIds: [viewerId] }];\n}\n\n/**\n * Merge a batch of messages into the transcript: de-duplicated by id, oldest\n * first.\n *\n * De-duplication is the whole point. The same message arrives twice all the\n * time - the subscription delivers it while the head-page refetch that follows\n * a reconnect also returns it, and offset paging re-reads a row when something\n * lands mid-scroll. LAST WRITE WINS on a collision, so a server row replaces\n * the optimistic copy rather than the other way round.\n *\n * Ties break on id, not on insertion order: two messages can share a timestamp\n * to the millisecond, and an unstable comparator makes them swap places on\n * every render.\n */\nexport function mergeMessages(existing: ChatMessage[], incoming: ChatMessage[]): ChatMessage[] {\n const byId = new Map<string, ChatMessage>();\n for (const m of existing) byId.set(m.id, m);\n for (const m of incoming) byId.set(m.id, m);\n return Array.from(byId.values()).sort(\n (a, b) => a.createdAt - b.createdAt || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),\n );\n}\n\n/**\n * Reconcile a server message with the optimistic row it confirms.\n *\n * Matched on (author, body, nearby timestamp) rather than an echoed client id,\n * because `sendMessage` does not round-trip one. The window is deliberately\n * generous - a slow network is normal - and the cost of a miss is a brief\n * duplicate that the next refetch cleans up, not a lost message.\n */\nexport function reconcileOptimistic(messages: ChatMessage[], confirmed: ChatMessage, windowMs = 60_000): ChatMessage[] {\n // Only the viewer's OWN message can confirm the viewer's pending row.\n // Without this, someone else sending the identical text inside the window\n // consumes the optimistic slot: their message is relabelled as yours and\n // yours disappears. \"ok\", \"thanks\" and \"👍\" collide constantly.\n if (!confirmed.isMine) return mergeMessages(messages, [confirmed]);\n\n // Attachment sends pick the post id up front, so the pending row already has the real id.\n const sameIdIdx = messages.findIndex((m) => m.id === confirmed.id && m.sendState === 'sending');\n if (sameIdIdx !== -1) {\n const next = messages.slice();\n const pending = messages[sameIdIdx];\n next[sameIdIdx] = {\n ...confirmed,\n // Keep the local previews until the server copy lists its files.\n attachments: confirmed.attachments.length ? confirmed.attachments : pending.attachments,\n sendState: 'sent',\n };\n return next;\n }\n\n const pendingIdx = messages.findIndex(\n (m) =>\n m.sendState === 'sending' &&\n m.isMine &&\n m.body === confirmed.body &&\n // Same author, not merely both \"mine\" - guards the same collision\n // when authorId is populated on both sides.\n (!m.authorId || !confirmed.authorId || m.authorId === confirmed.authorId) &&\n Math.abs(m.createdAt - confirmed.createdAt) <= windowMs,\n );\n if (pendingIdx === -1) return mergeMessages(messages, [confirmed]);\n\n const next = messages.slice();\n next[pendingIdx] = { ...confirmed, sendState: 'sent', replacedClientId: messages[pendingIdx].id };\n // Still merge: the same id may already be present from a concurrent refetch.\n return mergeMessages(\n next.filter((m) => m.id !== confirmed.id || m.replacedClientId),\n [next[pendingIdx]],\n );\n}\n\n/**\n * The other participant in a DM.\n *\n * Falls back to null rather than to the viewer: a conversation labelled with\n * your own name is a bug users notice immediately, and every DM the viewer\n * created before members were populated would hit it.\n */\nexport function peerOf(channel: WireChannel, viewerId: string): ChatUser | null {\n const members = (channel.members ?? []).filter(Boolean) as WireChannelMember[];\n const other = members.find((m) => m.user?.id && String(m.user.id) !== viewerId);\n return other?.user ?? null;\n}\n\n/**\n * How many messages the viewer has not read.\n *\n * `member.msgCount` is the count the member has SEEN, so unread is the channel\n * total minus that - clamped at zero because the two counters are updated on\n * different write paths and briefly disagree.\n */\nexport function unreadOf(channel: WireChannel, viewerId: string): number {\n const mine = (channel.members ?? []).find((m) => m?.user?.id && String(m.user.id) === viewerId);\n if (!mine) return 0;\n const total = channel.totalMsgCount ?? 0;\n const seen = mine.msgCount ?? 0;\n return Math.max(0, total - seen);\n}\n\nconst DIRECT_TYPES = new Set(['DIRECT', 'Direct', 'direct']);\n\nfunction looksLikeMachineTitle(value?: string | null): boolean {\n const label = value?.trim() ?? '';\n if (!label) return true;\n if (/^chat[\\s_-]*channel\\b/i.test(label) || /^chat-channel-/i.test(label)) return true;\n if (/^[a-f0-9]{8,}$/i.test(label)) return true;\n if (label.includes('__')) return true;\n if (/^group(\\s+chat)?$/i.test(label)) return true;\n return false;\n}\n\nexport function toConversation(channel: WireChannel, viewerId: string): ChatConversation {\n const peerCandidate = peerOf(channel, viewerId);\n const explicitDirect = DIRECT_TYPES.has(String(channel.type ?? ''));\n const populatedMembers = (channel.members ?? []).filter(Boolean);\n const twoParty = populatedMembers.length === 2 && Boolean(peerCandidate);\n const hasMachineLabel = looksLikeMachineTitle(channel.displayName) && looksLikeMachineTitle(channel.title);\n const isDirect = explicitDirect || twoParty || (!channel.type && hasMachineLabel && Boolean(peerCandidate));\n const peer = isDirect ? peerCandidate : null;\n\n const names = memberNames(channel, viewerId);\n const lastAuthor = channel.lastMessage ? pickAuthor(channel.lastMessage) : null;\n const lastAuthorName = lastAuthor && String(lastAuthor.id) !== viewerId ? displayNameOf(lastAuthor, '') : '';\n const creatorName = displayNameOf(channel.creator, '');\n const groupFallback = names.length\n ? names.join(', ')\n : lastAuthorName || (creatorName && creatorName !== 'Unknown' ? creatorName : 'Chat');\n const storedLabel = !looksLikeMachineTitle(channel.displayName)\n ? channel.displayName!.trim()\n : !looksLikeMachineTitle(channel.title)\n ? channel.title!.trim()\n : '';\n const title = isDirect\n ? displayNameOf(peer, storedLabel || lastAuthorName || 'Direct message')\n : storedLabel || groupFallback;\n const topic = looksLikeMachineTitle(channel.topic) ? '' : (channel.topic ?? '').trim();\n const preview = channel.lastMessage?.message?.trim() || attachmentPreview(channel.lastMessage) || topic;\n\n return {\n id: String(channel.id),\n title,\n subtitle: preview === title ? '' : preview,\n avatarUrl:\n peer?.picture ??\n peer?.profile?.picture ??\n channel.members?.find((member) => member?.user?.picture)?.user?.picture ??\n lastAuthor?.picture ??\n lastAuthor?.profile?.picture ??\n null,\n lastActivity: toEpoch(channel.lastPostAt) || toEpoch(channel.createdAt),\n unreadCount: unreadOf(channel, viewerId),\n isDirect,\n peer,\n };\n}\n\n/**\n * Conversation list order: most recent first, then title, then id.\n *\n * The trailing keys matter more than they look. A channel with no messages has\n * `lastActivity === 0`, so a fresh account is entirely ties; without a stable\n * tiebreak the list reshuffles on every poll.\n */\nexport function sortConversations(list: ChatConversation[]): ChatConversation[] {\n return list\n .slice()\n .sort(\n (a, b) =>\n b.lastActivity - a.lastActivity ||\n a.title.localeCompare(b.title) ||\n (a.id < b.id ? -1 : a.id > b.id ? 1 : 0),\n );\n}\n\n/** Stable key for collapsing duplicate list rows (same person, multiple channel ids). */\nexport function conversationListKey(c: ChatConversation): string {\n if (c.peer?.id) return `peer:${String(c.peer.id)}`;\n const title = c.title.trim().toLowerCase();\n if (!title || title === 'chat' || title === 'unknown') return `id:${c.id}`;\n // Multi-person groups use comma-separated titles; keep those distinct.\n if (title.includes(',')) return `id:${c.id}`;\n if (c.isDirect) return `title:${title}`;\n // Server often returns duplicate 1:1 channels as untyped GROUP rows with the peer's name.\n return `title:${title}`;\n}\n\n/** Newest row wins per list key. */\nexport function dedupeConversationList(list: ChatConversation[]): ChatConversation[] {\n const sorted = sortConversations(list);\n const seen = new Set<string>();\n const out: ChatConversation[] = [];\n for (const c of sorted) {\n const key = conversationListKey(c);\n if (seen.has(key)) continue;\n seen.add(key);\n out.push(c);\n }\n return out;\n}\n\n/** @deprecated Use dedupeConversationList */\nexport function dedupeDirectConversations(list: ChatConversation[]): ChatConversation[] {\n return dedupeConversationList(list);\n}\n\nexport function mergeConversations(existing: ChatConversation[], incoming: ChatConversation[]): ChatConversation[] {\n const byId = new Map<string, ChatConversation>();\n for (const c of existing) byId.set(c.id, c);\n for (const c of incoming) byId.set(c.id, c);\n return dedupeConversationList(Array.from(byId.values()));\n}\n\n/** Refresh preview + sort key when a new post lands (send echo or subscription). */\nexport function patchConversationAfterPost(conv: ChatConversation, post: WirePost, viewerId: string): ChatConversation {\n const preview = post.message?.trim() || attachmentPreview(post);\n const nextSubtitle = preview == null || preview === '' ? conv.subtitle : preview === conv.title ? '' : preview;\n const activity = toEpoch(post.createdAt) || Date.now();\n const author = pickAuthor(post);\n const fromPeer = author && String(author.id) !== viewerId;\n return {\n ...conv,\n subtitle: nextSubtitle,\n lastActivity: activity,\n unreadCount: fromPeer ? conv.unreadCount + 1 : conv.unreadCount,\n };\n}\n\n/**\n * Day separators, computed against a caller-supplied \"now\".\n *\n * The clock is a parameter so this is testable and so a device with a skewed\n * clock does not silently label everything \"Today\".\n */\nexport function dayLabel(epoch: number, now: number): string {\n if (!epoch) return '';\n const d = new Date(epoch);\n const n = new Date(now);\n const sameDay = (a: Date, b: Date) =>\n a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n if (sameDay(d, n)) return 'Today';\n const yesterday = new Date(now);\n yesterday.setDate(yesterday.getDate() - 1);\n if (sameDay(d, yesterday)) return 'Yesterday';\n return d.toLocaleDateString(undefined, {\n month: 'short',\n day: 'numeric',\n year: d.getFullYear() === n.getFullYear() ? undefined : 'numeric',\n });\n}\n\n/** Short clock label for a bubble. */\nexport function timeLabel(epoch: number): string {\n if (!epoch) return '';\n return new Date(epoch).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });\n}\n\n/** Relative age for the conversation list. */\nexport function relativeLabel(epoch: number, now: number): string {\n if (!epoch) return '';\n const diff = now - epoch;\n if (diff < 60_000) return 'now';\n if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m`;\n const d = new Date(epoch);\n const n = new Date(now);\n if (d.getFullYear() === n.getFullYear() && d.getMonth() === n.getMonth() && d.getDate() === n.getDate()) {\n return timeLabel(epoch);\n }\n if (diff < 7 * 86_400_000) return d.toLocaleDateString(undefined, { weekday: 'short' });\n return d.toLocaleDateString(undefined, { month: 'numeric', day: 'numeric' });\n}\n\n/** Initials for the avatar fallback; never more than two glyphs. */\nexport function initialsOf(name: string): string {\n const parts = name.trim().split(/\\s+/).filter(Boolean);\n if (!parts.length) return '?';\n if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();\n return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();\n}\n"],"names":["_a","_b","next"],"mappings":";;;;;;;;;;;;;;;;;;;AAkJgB,SAAA,aAAA,CAAc,IAAwB,EAAA,QAAA,GAAW,SAAmB,EAAA;AAlJpF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAmJE,EAAI,IAAA,CAAC,MAAa,OAAA,QAAA;AAClB,EAAA,MAAM,WAAc,GAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,IAAA,CAAK,OAAL,KAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAc,gBAAd,IAA2B,GAAA,MAAA,GAAA,EAAA,CAAA,IAAA,EAAA;AAC/C,EAAA,IAAI,aAAoB,OAAA,WAAA;AACxB,EAAA,MAAM,QAAW,GAAA,CAAC,IAAK,CAAA,SAAA,EAAW,IAAK,CAA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CAAA,CAAE,CAAC,CAAA,EAAG,WAAY,EAAA;AAChE"}
|
|
1
|
+
{"version":3,"file":"chatModel.js","sources":["../../../src/features/messaging/chatModel.ts"],"sourcesContent":["/**\n * Pure shaping between messenger-box's wire types and what the chat UI renders.\n *\n * Everything here is a plain function over plain data - no React, no seams, no\n * clock beyond what is passed in - because this is where the bugs that actually\n * ruin a chat client live: messages in the wrong order, a duplicate after a\n * reconnect, an optimistic row that never resolves, a DM titled with your own\n * name. Those are all cheap to unit-test and expensive to debug on a device.\n */\n\nexport interface ChatUser {\n id: string;\n givenName?: string | null;\n familyName?: string | null;\n username?: string | null;\n email?: string | null;\n picture?: string | null;\n profile?: { displayName?: string | null; picture?: string | null } | null;\n}\n\nexport interface WirePost {\n id: string;\n message?: string | null;\n type?: string | null;\n createdAt?: string | null;\n updatedAt?: string | null;\n editedAt?: string | null;\n deletedAt?: string | null;\n rootId?: string | null;\n parentId?: string | null;\n filenames?: (string | null)[] | null;\n props?: Record<string, unknown> | null;\n /** Attached files (messenger-box `Post.files`, linked to the post by id). */\n files?: { data?: (WireFile | null)[] | null } | null;\n author?: ChatUser | null;\n creator?: ChatUser | null;\n reactionSummary?: WireReaction[] | null;\n}\n\nexport interface WireFile {\n id?: string | null;\n name?: string | null;\n mimeType?: string | null;\n url?: string | null;\n width?: number | null;\n height?: number | null;\n size?: number | null;\n}\n\n/** What a message's `props.attachmentKind` says the attachments are (set when sending). */\nexport type ChatAttachmentKind = 'image' | 'audio' | 'file';\n\n/**\n * One attached file. `url` is what the server returned (an image-resizer thumbnail for every\n * type) or, while sending, the local file; `key` is the storage key, from which the UI builds\n * the full-size / playable CDN URL (see `attachmentUrl`).\n */\nexport interface ChatAttachment {\n id: string;\n kind: ChatAttachmentKind;\n name: string;\n mimeType: string;\n url: string;\n key: string | null;\n width?: number | null;\n height?: number | null;\n /** Voice notes: recorded length (from the message's props). */\n durationMs?: number | null;\n}\n\nexport interface WireReaction {\n reaction: string;\n count: number;\n userIds?: (string | null)[] | null;\n}\n\n/** One Tapback on a message, grouped across users. */\nexport interface ChatReaction {\n reaction: string;\n count: number;\n /** The viewer is one of the reactors. */\n mine: boolean;\n userIds: string[];\n}\n\nexport interface WireChannelMember {\n id?: string | null;\n user?: ChatUser | null;\n msgCount?: number | null;\n lastViewedAt?: string | null;\n}\n\nexport interface WireChannel {\n id: string;\n type?: string | null;\n orgName?: string | null;\n title?: string | null;\n displayName?: string | null;\n topic?: string | null;\n lastPostAt?: string | null;\n totalMsgCount?: number | null;\n createdAt?: string | null;\n lastMessage?: WirePost | null;\n creator?: ChatUser | null;\n members?: (WireChannelMember | null)[] | null;\n}\n\n/** Where an optimistic message is in its lifecycle. */\nexport type ChatSendState = 'sending' | 'sent' | 'failed';\n\nexport interface ChatMessage {\n id: string;\n body: string;\n createdAt: number;\n authorId: string | null;\n authorName: string;\n authorAvatar?: string | null;\n isMine: boolean;\n isDeleted: boolean;\n isEdited: boolean;\n attachments: ChatAttachment[];\n /** Tapbacks, in first-use order. Empty when nobody reacted. */\n reactions: ChatReaction[];\n /** Present only on messages this device is still sending. */\n sendState?: ChatSendState;\n /** The optimistic id this row replaced, so the UI can animate rather than jump. */\n replacedClientId?: string;\n}\n\nexport interface ChatConversation {\n id: string;\n title: string;\n subtitle: string;\n avatarUrl?: string | null;\n /** Sort key; 0 when the channel has never had a message. */\n lastActivity: number;\n unreadCount: number;\n isDirect: boolean;\n /** The other participant, for a DM. Null for groups. */\n peer: ChatUser | null;\n}\n\n/**\n * A person's display name, in the order a human would expect.\n *\n * Email is the last resort and is truncated at the `@`: a transcript full of\n * `someone@example.com` is worse than one full of `someone`.\n */\n/** Ids in a stable order, the last tiebreak for a sort. */\nfunction compareIds(a: string, b: string): number {\n if (a === b) return 0;\n return a < b ? -1 : 1;\n}\n\nexport function displayNameOf(user?: ChatUser | null, fallback = 'Unknown'): string {\n if (!user) return fallback;\n const profileName = user.profile?.displayName?.trim();\n if (profileName) return profileName;\n const fullName = [user.givenName, user.familyName].filter(Boolean).join(' ').trim();\n if (fullName) return fullName;\n const username = user.username?.trim();\n if (username) return username;\n const email = user.email?.trim();\n if (email) return email.split('@')[0] || fallback;\n return fallback;\n}\n\nfunction memberNames(channel: WireChannel, viewerId: string): string[] {\n return (channel.members ?? [])\n .map((member) => member?.user)\n .filter((user): user is ChatUser => Boolean(user?.id) && String(user.id) !== viewerId)\n .map((user) => displayNameOf(user, ''))\n .filter(Boolean)\n .slice(0, 3);\n}\n\n/**\n * messenger-box populates `author` on some write paths and `creator` on others\n * (`sendMessage` sets creator). Reading only one shows \"Unknown\" for a large\n * fraction of real transcripts.\n */\nexport function pickAuthor(post: WirePost): ChatUser | null {\n return post.author ?? post.creator ?? null;\n}\n\n/** Epoch millis, tolerant of nulls and unparseable values. */\nexport function toEpoch(value?: string | number | null): number {\n if (value == null) return 0;\n if (typeof value === 'number') return Number.isFinite(value) ? value : 0;\n const parsed = Date.parse(value);\n return Number.isNaN(parsed) ? 0 : parsed;\n}\n\nfunction kindOfMime(mimeType: string): ChatAttachmentKind {\n if (mimeType.startsWith('image/')) return 'image';\n if (mimeType.startsWith('audio/')) return 'audio';\n return 'file';\n}\n\n/**\n * The storage key inside a file URL. messenger-box hands back image-resizer URLs\n * (`<handler>/fit-in/150x150/<key>`) for every attachment; a plain storage URL or a bare key\n * also works.\n */\nexport function fileKeyFromUrl(url: string | null | undefined): string | null {\n const value = (url ?? '').trim();\n if (!value) return null;\n const resized = value.match(/\\/fit-in\\/\\d+x\\d+\\/(.+)$/);\n if (resized) return decodeURIComponent(resized[1].split('?')[0]);\n if (!/^[a-z]+:\\/\\//i.test(value)) return value.split('?')[0];\n if (/^(file|content|ph|assets-library):/i.test(value)) return null;\n try {\n return decodeURIComponent(new URL(value).pathname.replace(/^\\/+/, '')) || null;\n } catch {\n return null;\n }\n}\n\n/** Full-size (image) or playable (audio) URL: the CDN copy when a base is known, else what we have. */\nexport function attachmentUrl(attachment: ChatAttachment, fileBaseUrl?: string | null): string {\n if (!attachment.key || !fileBaseUrl) return attachment.url;\n return `${fileBaseUrl.replace(/\\/+$/, '')}/${attachment.key}`;\n}\n\n/** `props` is an AnyObject scalar: an object from some paths, a JSON string from others. */\nfunction propsOf(post: WirePost | null | undefined): Record<string, unknown> {\n const raw = post?.props as unknown;\n if (raw && typeof raw === 'object') return raw as Record<string, unknown>;\n if (typeof raw === 'string') {\n try {\n const parsed = JSON.parse(raw);\n return parsed && typeof parsed === 'object' ? parsed : {};\n } catch {\n return {};\n }\n }\n return {};\n}\n\nexport function toChatAttachments(post: WirePost): ChatAttachment[] {\n const props = propsOf(post) as { attachmentKind?: unknown; voiceDurationMs?: unknown };\n const durationMs = typeof props.voiceDurationMs === 'number' ? props.voiceDurationMs : null;\n return (post.files?.data ?? [])\n .filter((f): f is WireFile => Boolean(f?.url))\n .map((f, i) => {\n const mimeType = f.mimeType ?? 'application/octet-stream';\n const kind = kindOfMime(mimeType);\n return {\n id: String(f.id ?? `${post.id}-${i}`),\n kind,\n name: f.name ?? 'file',\n mimeType,\n url: String(f.url),\n key: fileKeyFromUrl(f.url),\n width: f.width ?? null,\n height: f.height ?? null,\n durationMs: kind === 'audio' ? durationMs : null,\n };\n });\n}\n\n/**\n * The text of an attachment-only message. messenger-box requires non-blank message text, so this\n * label is sent as the text: push notifications and other clients read it, and this app hides it\n * inside the bubble (see `toChatMessage`).\n */\nexport const ATTACHMENT_LABELS: Record<ChatAttachmentKind, string> = {\n image: '📷 Photo',\n audio: '🎤 Voice message',\n file: '📎 Attachment',\n};\n\n/** Chat-list preview for a message that is only an attachment. */\nexport function attachmentPreview(post: WirePost | null | undefined): string {\n const kind = propsOf(post).attachmentKind;\n return typeof kind === 'string' && kind in ATTACHMENT_LABELS ? ATTACHMENT_LABELS[kind as ChatAttachmentKind] : '';\n}\n\nconst LABEL_TEXTS = new Set(Object.values(ATTACHMENT_LABELS));\n\n/** The bubble text: an attachment-only message's label is not shown next to the attachment itself. */\nfunction bodyOf(post: WirePost, hasAttachments: boolean): string {\n const body = post.message ?? '';\n const trimmed = body.trim();\n const label = attachmentPreview(post);\n if (label && trimmed === label) return '';\n // Same label with the files attached, even if props did not come back.\n return hasAttachments && LABEL_TEXTS.has(trimmed) ? '' : body;\n}\n\nexport function toChatReactions(summary: WireReaction[] | null | undefined, viewerId: string): ChatReaction[] {\n return (summary ?? [])\n .filter((r) => r && r.reaction && r.count > 0)\n .map((r) => {\n const userIds = (r.userIds ?? []).filter((u): u is string => typeof u === 'string' && u.length > 0);\n return { reaction: r.reaction, count: r.count, userIds, mine: userIds.includes(viewerId) };\n });\n}\n\nexport function toChatMessage(post: WirePost, viewerId: string): ChatMessage {\n const author = pickAuthor(post);\n const attachments = toChatAttachments(post);\n return {\n id: String(post.id),\n body: bodyOf(post, attachments.length > 0),\n createdAt: toEpoch(post.createdAt),\n authorId: author?.id ? String(author.id) : null,\n authorName: displayNameOf(author),\n authorAvatar: author?.picture ?? author?.profile?.picture ?? null,\n isMine: !!author?.id && String(author.id) === viewerId,\n isDeleted: !!post.deletedAt,\n isEdited: !!post.editedAt,\n attachments,\n reactions: toChatReactions(post.reactionSummary, viewerId),\n };\n}\n\n/** Replace one message's reactions with the server's latest summary. */\nexport function applyReactionSummary(\n messages: ChatMessage[],\n messageId: string,\n summary: WireReaction[] | null | undefined,\n viewerId: string,\n): ChatMessage[] {\n return messages.map((m) => (m.id === messageId ? { ...m, reactions: toChatReactions(summary, viewerId) } : m));\n}\n\n/**\n * The viewer's reactions after picking `emoji` (null = remove). One Tapback per person,\n * like iMessage: a new pick replaces the old one, the same pick removes it.\n */\nexport function withViewerReaction(reactions: ChatReaction[], emoji: string | null, viewerId: string): ChatReaction[] {\n const current = reactions.find((r) => r.mine)?.reaction ?? null;\n const next = emoji && emoji !== current ? emoji : null;\n const out = reactions\n .map((r) =>\n r.mine ? { ...r, mine: false, count: r.count - 1, userIds: r.userIds.filter((u) => u !== viewerId) } : r,\n )\n .filter((r) => r.count > 0);\n if (!next) return out;\n const idx = out.findIndex((r) => r.reaction === next);\n if (idx >= 0) {\n const r = out[idx];\n out[idx] = { ...r, mine: true, count: r.count + 1, userIds: [...r.userIds, viewerId] };\n return out;\n }\n return [...out, { reaction: next, count: 1, mine: true, userIds: [viewerId] }];\n}\n\n/**\n * Merge a batch of messages into the transcript: de-duplicated by id, oldest\n * first.\n *\n * De-duplication is the whole point. The same message arrives twice all the\n * time - the subscription delivers it while the head-page refetch that follows\n * a reconnect also returns it, and offset paging re-reads a row when something\n * lands mid-scroll. LAST WRITE WINS on a collision, so a server row replaces\n * the optimistic copy rather than the other way round.\n *\n * Ties break on id, not on insertion order: two messages can share a timestamp\n * to the millisecond, and an unstable comparator makes them swap places on\n * every render.\n */\nexport function mergeMessages(existing: ChatMessage[], incoming: ChatMessage[]): ChatMessage[] {\n const byId = new Map<string, ChatMessage>();\n for (const m of existing) byId.set(m.id, m);\n for (const m of incoming) byId.set(m.id, m);\n return Array.from(byId.values()).sort((a, b) => a.createdAt - b.createdAt || compareIds(a.id, b.id));\n}\n\n/**\n * Reconcile a server message with the optimistic row it confirms.\n *\n * Matched on (author, body, nearby timestamp) rather than an echoed client id,\n * because `sendMessage` does not round-trip one. The window is deliberately\n * generous - a slow network is normal - and the cost of a miss is a brief\n * duplicate that the next refetch cleans up, not a lost message.\n */\nexport function reconcileOptimistic(messages: ChatMessage[], confirmed: ChatMessage, windowMs = 60_000): ChatMessage[] {\n // Only the viewer's OWN message can confirm the viewer's pending row.\n // Without this, someone else sending the identical text inside the window\n // consumes the optimistic slot: their message is relabelled as yours and\n // yours disappears. \"ok\", \"thanks\" and \"👍\" collide constantly.\n if (!confirmed.isMine) return mergeMessages(messages, [confirmed]);\n\n // Attachment sends pick the post id up front, so the pending row already has the real id.\n const sameIdIdx = messages.findIndex((m) => m.id === confirmed.id && m.sendState === 'sending');\n if (sameIdIdx !== -1) {\n const next = messages.slice();\n const pending = messages[sameIdIdx];\n next[sameIdIdx] = {\n ...confirmed,\n // Keep the local previews until the server copy lists its files.\n attachments: confirmed.attachments.length ? confirmed.attachments : pending.attachments,\n sendState: 'sent',\n };\n return next;\n }\n\n const pendingIdx = messages.findIndex(\n (m) =>\n m.sendState === 'sending' &&\n m.isMine &&\n m.body === confirmed.body &&\n // Same author, not merely both \"mine\" - guards the same collision\n // when authorId is populated on both sides.\n (!m.authorId || !confirmed.authorId || m.authorId === confirmed.authorId) &&\n Math.abs(m.createdAt - confirmed.createdAt) <= windowMs,\n );\n if (pendingIdx === -1) return mergeMessages(messages, [confirmed]);\n\n const next = messages.slice();\n next[pendingIdx] = { ...confirmed, sendState: 'sent', replacedClientId: messages[pendingIdx].id };\n // Still merge: the same id may already be present from a concurrent refetch.\n return mergeMessages(\n next.filter((m) => m.id !== confirmed.id || m.replacedClientId),\n [next[pendingIdx]],\n );\n}\n\n/**\n * The other participant in a DM.\n *\n * Falls back to null rather than to the viewer: a conversation labelled with\n * your own name is a bug users notice immediately, and every DM the viewer\n * created before members were populated would hit it.\n */\nexport function peerOf(channel: WireChannel, viewerId: string): ChatUser | null {\n const members = (channel.members ?? []).filter(Boolean) as WireChannelMember[];\n const other = members.find((m) => m.user?.id && String(m.user.id) !== viewerId);\n return other?.user ?? null;\n}\n\n/**\n * How many messages the viewer has not read.\n *\n * `member.msgCount` is the count the member has SEEN, so unread is the channel\n * total minus that - clamped at zero because the two counters are updated on\n * different write paths and briefly disagree.\n */\nexport function unreadOf(channel: WireChannel, viewerId: string): number {\n const mine = (channel.members ?? []).find((m) => m?.user?.id && String(m.user.id) === viewerId);\n if (!mine) return 0;\n const total = channel.totalMsgCount ?? 0;\n const seen = mine.msgCount ?? 0;\n return Math.max(0, total - seen);\n}\n\nconst DIRECT_TYPES = new Set(['DIRECT', 'Direct', 'direct']);\n\nfunction looksLikeMachineTitle(value?: string | null): boolean {\n const label = value?.trim() ?? '';\n if (!label) return true;\n if (/^chat[\\s_-]*channel\\b/i.test(label) || /^chat-channel-/i.test(label)) return true;\n if (/^[a-f0-9]{8,}$/i.test(label)) return true;\n if (label.includes('__')) return true;\n if (/^group(\\s+chat)?$/i.test(label)) return true;\n return false;\n}\n\n/** The name a person gave the channel; '' when it only carries a machine id like \"a__b\". */\nfunction storedLabelOf(channel: WireChannel): string {\n if (!looksLikeMachineTitle(channel.displayName)) return channel.displayName!.trim();\n if (!looksLikeMachineTitle(channel.title)) return channel.title!.trim();\n return '';\n}\n\nexport function toConversation(channel: WireChannel, viewerId: string): ChatConversation {\n const peerCandidate = peerOf(channel, viewerId);\n const explicitDirect = DIRECT_TYPES.has(String(channel.type ?? ''));\n const populatedMembers = (channel.members ?? []).filter(Boolean);\n const twoParty = populatedMembers.length === 2 && Boolean(peerCandidate);\n const hasMachineLabel = looksLikeMachineTitle(channel.displayName) && looksLikeMachineTitle(channel.title);\n const storedLabel = storedLabelOf(channel);\n // Two members is a DM - unless the channel is typed (not DIRECT) and someone\n // named it something other than the other person (\"standup\" with two people\n // in it is still a group).\n const namedGroup =\n Boolean(channel.type) &&\n Boolean(storedLabel) &&\n storedLabel.toLowerCase() !== displayNameOf(peerCandidate, '').toLowerCase();\n const isDirect =\n explicitDirect || (twoParty && !namedGroup) || (!channel.type && hasMachineLabel && Boolean(peerCandidate));\n const peer = isDirect ? peerCandidate : null;\n\n const names = memberNames(channel, viewerId);\n const lastAuthor = channel.lastMessage ? pickAuthor(channel.lastMessage) : null;\n const lastAuthorName = lastAuthor && String(lastAuthor.id) !== viewerId ? displayNameOf(lastAuthor, '') : '';\n const creatorName = displayNameOf(channel.creator, '');\n const groupFallback = names.length\n ? names.join(', ')\n : lastAuthorName || (creatorName && creatorName !== 'Unknown' ? creatorName : 'Chat');\n const title = isDirect\n ? displayNameOf(peer, storedLabel || lastAuthorName || 'Direct message')\n : storedLabel || groupFallback;\n const topic = looksLikeMachineTitle(channel.topic) ? '' : (channel.topic ?? '').trim();\n const preview = channel.lastMessage?.message?.trim() || attachmentPreview(channel.lastMessage) || topic;\n\n return {\n id: String(channel.id),\n title,\n subtitle: preview === title ? '' : preview,\n avatarUrl:\n peer?.picture ??\n peer?.profile?.picture ??\n channel.members?.find((member) => member?.user?.picture)?.user?.picture ??\n lastAuthor?.picture ??\n lastAuthor?.profile?.picture ??\n null,\n lastActivity: toEpoch(channel.lastPostAt) || toEpoch(channel.createdAt),\n unreadCount: unreadOf(channel, viewerId),\n isDirect,\n peer,\n };\n}\n\n/**\n * Conversation list order: most recent first, then title, then id.\n *\n * The trailing keys matter more than they look. A channel with no messages has\n * `lastActivity === 0`, so a fresh account is entirely ties; without a stable\n * tiebreak the list reshuffles on every poll.\n */\nexport function sortConversations(list: ChatConversation[]): ChatConversation[] {\n return list\n .slice()\n .sort((a, b) => b.lastActivity - a.lastActivity || a.title.localeCompare(b.title) || compareIds(a.id, b.id));\n}\n\n/** Stable key for collapsing duplicate list rows (same person, multiple channel ids). */\nexport function conversationListKey(c: ChatConversation): string {\n if (c.peer?.id) return `peer:${String(c.peer.id)}`;\n const title = c.title.trim().toLowerCase();\n if (!title || title === 'chat' || title === 'unknown') return `id:${c.id}`;\n // Multi-person groups use comma-separated titles; keep those distinct.\n if (title.includes(',')) return `id:${c.id}`;\n if (c.isDirect) return `title:${title}`;\n // Server often returns duplicate 1:1 channels as untyped GROUP rows with the peer's name.\n return `title:${title}`;\n}\n\n/** A row's title when it names one person, lowercased; '' for groups and placeholders. */\nfunction personTitle(c: ChatConversation): string {\n const title = c.title.trim().toLowerCase();\n if (!title || title === 'chat' || title === 'unknown' || title.includes(',')) return '';\n return title;\n}\n\n/**\n * One row per conversation, newest first. The server also returns a person's\n * 1:1 chat as untyped rows under their name, so a row that names its peer and a\n * peerless row with the same name are one person - but two peers who share a\n * name stay two rows.\n */\nexport function dedupeConversationList(list: ChatConversation[]): ChatConversation[] {\n const peers = new Set<string>();\n const peerTitles = new Set<string>();\n const titles = new Set<string>();\n return sortConversations(list).filter((c) => {\n const title = personTitle(c);\n const peerId = c.peer?.id ? String(c.peer.id) : '';\n if (peerId) {\n if (peers.has(peerId) || (title && titles.has(title))) return false;\n peers.add(peerId);\n if (title) peerTitles.add(title);\n return true;\n }\n if (!title) return true;\n if (titles.has(title) || peerTitles.has(title)) return false;\n titles.add(title);\n return true;\n });\n}\n\n/** @deprecated Use dedupeConversationList */\nexport function dedupeDirectConversations(list: ChatConversation[]): ChatConversation[] {\n return dedupeConversationList(list);\n}\n\nexport function mergeConversations(existing: ChatConversation[], incoming: ChatConversation[]): ChatConversation[] {\n const byId = new Map<string, ChatConversation>();\n for (const c of existing) byId.set(c.id, c);\n for (const c of incoming) byId.set(c.id, c);\n return dedupeConversationList(Array.from(byId.values()));\n}\n\n/** The list preview after a post: unchanged for an empty one, hidden when it only repeats the title. */\nfunction subtitleAfterPost(conv: ChatConversation, preview: string | null | undefined): string {\n if (!preview) return conv.subtitle;\n return preview === conv.title ? '' : preview;\n}\n\n/** Refresh preview + sort key when a new post lands (send echo or subscription). */\nexport function patchConversationAfterPost(conv: ChatConversation, post: WirePost, viewerId: string): ChatConversation {\n const preview = post.message?.trim() || attachmentPreview(post);\n const nextSubtitle = subtitleAfterPost(conv, preview);\n const activity = toEpoch(post.createdAt) || Date.now();\n const author = pickAuthor(post);\n const fromPeer = author && String(author.id) !== viewerId;\n return {\n ...conv,\n subtitle: nextSubtitle,\n lastActivity: activity,\n unreadCount: fromPeer ? conv.unreadCount + 1 : conv.unreadCount,\n };\n}\n\n/**\n * Day separators, computed against a caller-supplied \"now\".\n *\n * The clock is a parameter so this is testable and so a device with a skewed\n * clock does not silently label everything \"Today\".\n */\nexport function dayLabel(epoch: number, now: number): string {\n if (!epoch) return '';\n const d = new Date(epoch);\n const n = new Date(now);\n const sameDay = (a: Date, b: Date) =>\n a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();\n if (sameDay(d, n)) return 'Today';\n const yesterday = new Date(now);\n yesterday.setDate(yesterday.getDate() - 1);\n if (sameDay(d, yesterday)) return 'Yesterday';\n return d.toLocaleDateString(undefined, {\n month: 'short',\n day: 'numeric',\n year: d.getFullYear() === n.getFullYear() ? undefined : 'numeric',\n });\n}\n\n/** Short clock label for a bubble. */\nexport function timeLabel(epoch: number): string {\n if (!epoch) return '';\n return new Date(epoch).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' });\n}\n\n/** Relative age for the conversation list. */\nexport function relativeLabel(epoch: number, now: number): string {\n if (!epoch) return '';\n const diff = now - epoch;\n if (diff < 60_000) return 'now';\n if (diff < 3_600_000) return `${Math.floor(diff / 60_000)}m`;\n const d = new Date(epoch);\n const n = new Date(now);\n if (d.getFullYear() === n.getFullYear() && d.getMonth() === n.getMonth() && d.getDate() === n.getDate()) {\n return timeLabel(epoch);\n }\n if (diff < 7 * 86_400_000) return d.toLocaleDateString(undefined, { weekday: 'short' });\n return d.toLocaleDateString(undefined, { month: 'numeric', day: 'numeric' });\n}\n\n/** Initials for the avatar fallback; never more than two glyphs. */\nexport function initialsOf(name: string): string {\n const parts = name.trim().split(/\\s+/).filter(Boolean);\n if (!parts.length) return '?';\n if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();\n return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();\n}\n"],"names":["_a","_b","next"],"mappings":";;;;;;;;;;;;;;;;;;;AAmJA,SAAS,UAAA,CAAW,GAAW,CAAmB,EAAA;AAChD,EAAI,IAAA,CAAA,KAAM,GAAU,OAAA,CAAA;AACpB,EAAO,OAAA,CAAA,GAAI,IAAI,EAAK,GAAA,CAAA;AACtB;AACgB,SAAA,aAAA,CAAc,IAAwB,EAAA,QAAA,GAAW,SAAmB,EAAA;AAvJpF,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAwJE,EAAI,IAAA,CAAC,MAAa,OAAA,QAAA;AAClB,EAAA,MAAM,WAAc,GAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,IAAA,CAAK,OAAL,KAAA,IAAA,GAAA,MAAA,GAAA,EAAA,CAAc,gBAAd,IAA2B,GAAA,MAAA,GAAA,EAAA,CAAA,IAAA,EAAA;A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
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useEffect,useRef,useState,useMemo,useCallback}from'react';import {StyleSheet,useColorScheme,
|
|
1
|
+
import {jsx,jsxs,Fragment}from'react/jsx-runtime';import {useEffect,useRef,useState,useMemo,useCallback}from'react';import {StyleSheet,useColorScheme,View,Text,ActivityIndicator,Pressable,ScrollView,TextInput,Modal,Linking}from'react-native';import {useFocusEffect}from'@react-navigation/native';import {MaterialCommunityIcons}from'@expo/vector-icons';import {useSafeInsets}from'../canvas/withRemoteSafeArea.js';import {SOURCE_ORDER,productSource,DEPARTMENTS,SOURCE_LABELS,PRODUCT_SOURCES,SOURCE_SECTION,formatPrice}from'./catalog.js';import {hydrateCart,useCart,setQty,removeFromCart,clearCart}from'./shoppingCart.js';import {createShoppingExec}from'./shoppingExec.js';import {setShoppingRuntime}from'./shoppingRuntime.js';import {useShoppingSearch}from'./useShoppingSearch.js';import {ProductPhoto}from'./ProductPhoto.js';import {ProductDetailSheet}from'./ProductDetailSheet.js';import {ProductCard}from'./ProductCard.js';import {ProductFilterBar}from'./ProductFilterBar.js';import {DealsPanel}from'./DealsPanel.js';import {TrendingSections}from'./TrendingSections.js';import {DEFAULT_PRODUCT_FILTERS,applyProductFilters}from'./services/productFilters.js';import {WatchlistPanel}from'./WatchlistPanel.js';import {SavedPanel}from'./SavedPanel.js';import {HistoryPanel}from'./HistoryPanel.js';import {OrdersPanel}from'./OrdersPanel.js';import {hydrateSaved}from'./savedProducts.js';import {hydrateShoppingHistory,recordProductView,recordOrder}from'./shoppingHistoryStore.js';import {ShoppingAgentChatPane}from'./ShoppingAgentChatPane.js';import {shouldClaimOpenAgentMove,isOpenAgentSwipe}from'./shopAgentSwipe.js';import {createEdgeSwipe}from'../agent-chat/edgeSwipe.js';var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -89,9 +89,13 @@ function ShoppingExperience({
|
|
|
89
89
|
chatOpenRef.current = chatOpen;
|
|
90
90
|
const shopSwipeBlockedRef = useRef(false);
|
|
91
91
|
shopSwipeBlockedRef.current = Boolean(cartOpen || detail);
|
|
92
|
-
const shopSwipe = useMemo(() =>
|
|
93
|
-
|
|
94
|
-
|
|
92
|
+
const shopSwipe = useMemo(() => createEdgeSwipe({
|
|
93
|
+
zone: {
|
|
94
|
+
edge: "right",
|
|
95
|
+
width: 44
|
|
96
|
+
},
|
|
97
|
+
claim: (g) => !chatOpenRef.current && !shopSwipeBlockedRef.current && shouldClaimOpenAgentMove(g),
|
|
98
|
+
release: (g) => {
|
|
95
99
|
if (!chatOpenRef.current && !shopSwipeBlockedRef.current && isOpenAgentSwipe(g)) {
|
|
96
100
|
setChatOpen(true);
|
|
97
101
|
}
|
|
@@ -187,9 +191,9 @@ function ShoppingExperience({
|
|
|
187
191
|
ink,
|
|
188
192
|
muted
|
|
189
193
|
};
|
|
190
|
-
return /* @__PURE__ */ jsxs(View, { style: [styles.fill, {
|
|
194
|
+
return /* @__PURE__ */ jsxs(View, __spreadProps(__spreadValues({ style: [styles.fill, {
|
|
191
195
|
backgroundColor: screen
|
|
192
|
-
}], testID: "shopping-panel", children: [
|
|
196
|
+
}], testID: "shopping-panel" }, shopSwipe.panHandlers), { children: [
|
|
193
197
|
/* @__PURE__ */ jsxs(View, { style: styles.header, children: [
|
|
194
198
|
/* @__PURE__ */ jsxs(View, { style: styles.brandRow, children: [
|
|
195
199
|
/* @__PURE__ */ jsx(Text, { style: styles.brandShop, children: "Shop" }),
|
|
@@ -425,7 +429,6 @@ function ShoppingExperience({
|
|
|
425
429
|
] })
|
|
426
430
|
] }) }),
|
|
427
431
|
detail ? /* @__PURE__ */ jsx(ProductDetailSheet, { product: detail, onClose: () => setDetail(null), isDark, ink, muted, screen, border }) : null,
|
|
428
|
-
chatOpen || cartOpen || detail ? null : /* @__PURE__ */ jsx(View, __spreadProps(__spreadValues({ style: styles.agentSwipeEdge }, shopSwipe.panHandlers), { accessibilityLabel: "Swipe left from here to open the shopping agent" })),
|
|
429
432
|
chatOpen ? null : /* @__PURE__ */ jsx(Pressable, { onPress: () => setChatOpen(true), style: [styles.agentFab, {
|
|
430
433
|
bottom: Math.max(insets.bottom, 16) + 8
|
|
431
434
|
}], accessibilityRole: "button", accessibilityLabel: "Open shopping agent", children: /* @__PURE__ */ jsx(MaterialCommunityIcons, { name: "creation", size: 22, color: "#1a1408" }) }),
|
|
@@ -437,7 +440,7 @@ function ShoppingExperience({
|
|
|
437
440
|
setChatOpen(false);
|
|
438
441
|
openDetails(product);
|
|
439
442
|
}, seedTurn: initialAgentSeed, uiSearchTurn: searchState.uiSearchTurn, isDark, ink, muted, screen, border, card })
|
|
440
|
-
] });
|
|
443
|
+
] }));
|
|
441
444
|
}
|
|
442
445
|
const styles = StyleSheet.create({
|
|
443
446
|
fill: {
|
|
@@ -858,14 +861,6 @@ const styles = StyleSheet.create({
|
|
|
858
861
|
backgroundColor: "#e2e8f0",
|
|
859
862
|
alignItems: "center"
|
|
860
863
|
},
|
|
861
|
-
agentSwipeEdge: {
|
|
862
|
-
position: "absolute",
|
|
863
|
-
top: 0,
|
|
864
|
-
right: 0,
|
|
865
|
-
bottom: 0,
|
|
866
|
-
width: 44,
|
|
867
|
-
zIndex: 9
|
|
868
|
-
},
|
|
869
864
|
agentFab: {
|
|
870
865
|
position: "absolute",
|
|
871
866
|
right: 16,
|