@messenger-box/platform-mobile 10.0.3-alpha.19 → 10.0.3-alpha.22
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/CHANGELOG.md +8 -0
- package/lib/screens/inbox/components/CachedImage/index.js +0 -19
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogsListItem.js +423 -50
- package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +375 -51
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js +175 -0
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js.map +1 -0
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js +191 -0
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js.map +1 -0
- package/lib/screens/inbox/containers/Dialogs.js +536 -66
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +95 -23
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +211 -0
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +1 -0
- package/package.json +2 -2
- package/src/screens/inbox/components/CachedImage/index.tsx +9 -9
- package/src/screens/inbox/components/DialogsListItem.tsx +624 -107
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +506 -114
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +35 -17
- package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +145 -0
- package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +159 -0
- package/src/screens/inbox/containers/Dialogs.tsx +711 -169
- package/src/screens/inbox/containers/ThreadConversationView.tsx +151 -35
|
@@ -64,10 +64,23 @@ const {
|
|
|
64
64
|
|
|
65
65
|
const createdAtText = (value: string) => {
|
|
66
66
|
if (!value) return '';
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
// Validate the date before processing
|
|
70
|
+
const timestamp = new Date(value).getTime();
|
|
71
|
+
if (isNaN(timestamp)) {
|
|
72
|
+
console.warn(`Invalid date value in createdAtText: ${value}`);
|
|
73
|
+
return 'Unknown date';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let date = new Date(value);
|
|
77
|
+
if (isToday(date)) return 'Today';
|
|
78
|
+
if (isYesterday(date)) return 'Yesterday';
|
|
79
|
+
return format(date, 'MMM dd, yyyy');
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error(`Error processing date in createdAtText: ${value}`, error);
|
|
82
|
+
return 'Unknown date';
|
|
83
|
+
}
|
|
71
84
|
};
|
|
72
85
|
|
|
73
86
|
// Create a safer version of useMachine to handle potential errors
|
|
@@ -296,24 +309,47 @@ function useSafeMachine(machine) {
|
|
|
296
309
|
|
|
297
310
|
// Debug: Log the dates of the messages for troubleshooting
|
|
298
311
|
if (newMessages.length > 0) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
312
|
+
try {
|
|
313
|
+
console.log(
|
|
314
|
+
'First new message date:',
|
|
315
|
+
!isNaN(new Date(newMessages[0].createdAt).getTime())
|
|
316
|
+
? new Date(newMessages[0].createdAt).toISOString()
|
|
317
|
+
: 'Invalid date',
|
|
318
|
+
);
|
|
319
|
+
console.log(
|
|
320
|
+
'Last new message date:',
|
|
321
|
+
!isNaN(new Date(newMessages[newMessages.length - 1].createdAt).getTime())
|
|
322
|
+
? new Date(newMessages[newMessages.length - 1].createdAt).toISOString()
|
|
323
|
+
: 'Invalid date',
|
|
324
|
+
);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
console.error('Error logging new message dates:', error);
|
|
327
|
+
}
|
|
304
328
|
}
|
|
305
329
|
|
|
306
330
|
if (prev.context.threadMessages.length > 0) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
331
|
+
try {
|
|
332
|
+
console.log(
|
|
333
|
+
'First existing message date:',
|
|
334
|
+
!isNaN(new Date(prev.context.threadMessages[0].createdAt).getTime())
|
|
335
|
+
? new Date(prev.context.threadMessages[0].createdAt).toISOString()
|
|
336
|
+
: 'Invalid date',
|
|
337
|
+
);
|
|
338
|
+
console.log(
|
|
339
|
+
'Last existing message date:',
|
|
340
|
+
!isNaN(
|
|
341
|
+
new Date(
|
|
342
|
+
prev.context.threadMessages[prev.context.threadMessages.length - 1].createdAt,
|
|
343
|
+
).getTime(),
|
|
344
|
+
)
|
|
345
|
+
? new Date(
|
|
346
|
+
prev.context.threadMessages[prev.context.threadMessages.length - 1].createdAt,
|
|
347
|
+
).toISOString()
|
|
348
|
+
: 'Invalid date',
|
|
349
|
+
);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
console.error('Error logging existing message dates:', error);
|
|
352
|
+
}
|
|
317
353
|
}
|
|
318
354
|
|
|
319
355
|
// If no new messages returned but total count says there should be more
|
|
@@ -338,7 +374,19 @@ function useSafeMachine(machine) {
|
|
|
338
374
|
// GiftedChat expects messages sorted by date (newest first)
|
|
339
375
|
const sortedMessages = orderBy(
|
|
340
376
|
combinedMessages,
|
|
341
|
-
[
|
|
377
|
+
[
|
|
378
|
+
(msg) => {
|
|
379
|
+
try {
|
|
380
|
+
// Safely access and convert date
|
|
381
|
+
return !isNaN(new Date(msg.createdAt).getTime())
|
|
382
|
+
? new Date(msg.createdAt).getTime()
|
|
383
|
+
: 0; // Default to oldest if invalid
|
|
384
|
+
} catch (error) {
|
|
385
|
+
console.error(`Error sorting message by date: ${msg.id}`, error);
|
|
386
|
+
return 0; // Default to oldest if error
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
],
|
|
342
390
|
['desc'],
|
|
343
391
|
);
|
|
344
392
|
|
|
@@ -1275,10 +1323,39 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
|
|
|
1275
1323
|
// Generate a unique _id if needed by combining id and createdAt
|
|
1276
1324
|
const uniqueId = msg.id || `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
1277
1325
|
|
|
1326
|
+
// Safely create a Date object with validation
|
|
1327
|
+
let messageDate;
|
|
1328
|
+
try {
|
|
1329
|
+
// Check if createdAt is a valid date string
|
|
1330
|
+
if (msg.createdAt && !isNaN(new Date(msg.createdAt).getTime())) {
|
|
1331
|
+
messageDate = new Date(msg.createdAt);
|
|
1332
|
+
} else {
|
|
1333
|
+
// Use current time as fallback if date is invalid
|
|
1334
|
+
console.warn(`Invalid date value for message ${msg.id}: ${msg.createdAt}`);
|
|
1335
|
+
messageDate = new Date();
|
|
1336
|
+
}
|
|
1337
|
+
} catch (error) {
|
|
1338
|
+
console.error(`Error creating date for message ${msg.id}:`, error);
|
|
1339
|
+
messageDate = new Date(); // Fallback to current time
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
// Extract image URL from files data
|
|
1343
|
+
let imageUrl = null;
|
|
1344
|
+
if (msg.files?.data && msg.files.data.length > 0) {
|
|
1345
|
+
const fileData = msg.files.data[0];
|
|
1346
|
+
if (fileData && fileData.url) {
|
|
1347
|
+
imageUrl = fileData.url;
|
|
1348
|
+
console.log('📷 Found image URL for message', msg.id, ':', imageUrl);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// Get the message text without adding "File attachment" for image-only messages
|
|
1353
|
+
let messageText = msg.message || '';
|
|
1354
|
+
|
|
1278
1355
|
let message: IMessageProps = {
|
|
1279
1356
|
_id: uniqueId,
|
|
1280
|
-
text:
|
|
1281
|
-
createdAt:
|
|
1357
|
+
text: messageText,
|
|
1358
|
+
createdAt: messageDate,
|
|
1282
1359
|
user: {
|
|
1283
1360
|
_id: msg?.author?.id ?? auth?.profile?.id,
|
|
1284
1361
|
name:
|
|
@@ -1288,7 +1365,7 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
|
|
|
1288
1365
|
avatar: msg?.author?.picture ?? auth?.profile?.picture,
|
|
1289
1366
|
},
|
|
1290
1367
|
type: msg?.type || '',
|
|
1291
|
-
image:
|
|
1368
|
+
image: imageUrl,
|
|
1292
1369
|
sent: msg?.isDelivered || true,
|
|
1293
1370
|
received: msg?.isRead || false,
|
|
1294
1371
|
propsConfiguration: msg?.propsConfiguration,
|
|
@@ -1298,16 +1375,37 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
|
|
|
1298
1375
|
}
|
|
1299
1376
|
|
|
1300
1377
|
// Sort messages by date (newest first as required by GiftedChat)
|
|
1301
|
-
|
|
1378
|
+
// Use a safer getTime() approach with error handling
|
|
1379
|
+
const sortedMessages = orderBy(
|
|
1380
|
+
res,
|
|
1381
|
+
[
|
|
1382
|
+
(msg) => {
|
|
1383
|
+
try {
|
|
1384
|
+
return msg.createdAt instanceof Date ? msg.createdAt.getTime() : new Date().getTime();
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
console.error('Error sorting message by date:', error);
|
|
1387
|
+
return 0; // Fallback to a default value
|
|
1388
|
+
}
|
|
1389
|
+
},
|
|
1390
|
+
],
|
|
1391
|
+
['desc'],
|
|
1392
|
+
);
|
|
1302
1393
|
|
|
1303
1394
|
// Log message dates to help with debugging
|
|
1304
1395
|
if (sortedMessages.length > 0) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1396
|
+
try {
|
|
1397
|
+
const firstMsg = sortedMessages[0];
|
|
1398
|
+
const lastMsg = sortedMessages[sortedMessages.length - 1];
|
|
1399
|
+
|
|
1400
|
+
console.log(
|
|
1401
|
+
'Message date range:',
|
|
1402
|
+
lastMsg.createdAt instanceof Date ? lastMsg.createdAt.toISOString() : 'invalid date',
|
|
1403
|
+
'to',
|
|
1404
|
+
firstMsg.createdAt instanceof Date ? firstMsg.createdAt.toISOString() : 'invalid date',
|
|
1405
|
+
);
|
|
1406
|
+
} catch (error) {
|
|
1407
|
+
console.error('Error logging message date range:', error);
|
|
1408
|
+
}
|
|
1311
1409
|
}
|
|
1312
1410
|
|
|
1313
1411
|
return sortedMessages;
|
|
@@ -1351,6 +1449,8 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
|
|
|
1351
1449
|
|
|
1352
1450
|
const renderMessageText = (props: any) => {
|
|
1353
1451
|
const { currentMessage } = props;
|
|
1452
|
+
|
|
1453
|
+
// For ALERT type messages with call to action
|
|
1354
1454
|
if (currentMessage.type === 'ALERT') {
|
|
1355
1455
|
const attachment = currentMessage?.propsConfiguration?.contents?.attachment;
|
|
1356
1456
|
let action: string = '';
|
|
@@ -1406,7 +1506,14 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
|
|
|
1406
1506
|
)}
|
|
1407
1507
|
</>
|
|
1408
1508
|
);
|
|
1409
|
-
}
|
|
1509
|
+
}
|
|
1510
|
+
// For file attachment messages, don't show the "File attachment" text
|
|
1511
|
+
else if (currentMessage.text === '📎 File attachment') {
|
|
1512
|
+
// Return null to not render any text for these messages
|
|
1513
|
+
return null;
|
|
1514
|
+
}
|
|
1515
|
+
// Default text rendering
|
|
1516
|
+
else {
|
|
1410
1517
|
return <MessageText {...props} textStyle={{ left: { marginLeft: 5 } }} />;
|
|
1411
1518
|
}
|
|
1412
1519
|
};
|
|
@@ -1943,10 +2050,19 @@ const ThreadConversationViewComponent = ({ channelId, postParentId, isPostParent
|
|
|
1943
2050
|
</Text>
|
|
1944
2051
|
<Text className="pl-0 color-gray-500">
|
|
1945
2052
|
{createdAtText(safeContextProperty('threadPost')[0]?.createdAt)} at{' '}
|
|
1946
|
-
{
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
2053
|
+
{(() => {
|
|
2054
|
+
try {
|
|
2055
|
+
const createdAt = safeContextProperty('threadPost')[0]?.createdAt;
|
|
2056
|
+
if (createdAt && !isNaN(new Date(createdAt).getTime())) {
|
|
2057
|
+
return format(new Date(createdAt), 'hh:mm:a');
|
|
2058
|
+
} else {
|
|
2059
|
+
return 'unknown time';
|
|
2060
|
+
}
|
|
2061
|
+
} catch (error) {
|
|
2062
|
+
console.error('Error formatting thread post time:', error);
|
|
2063
|
+
return 'unknown time';
|
|
2064
|
+
}
|
|
2065
|
+
})()}
|
|
1950
2066
|
</Text>
|
|
1951
2067
|
</Box>
|
|
1952
2068
|
</HStack>
|