@messenger-box/platform-mobile 10.0.3-alpha.36 → 10.0.3-alpha.37
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 +4 -0
- package/lib/screens/inbox/components/CachedImage/index.js +125 -93
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogsListItem.js +75 -271
- package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +184 -415
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +0 -2
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/containers/ConversationView.js +478 -944
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +212 -628
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +409 -1364
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/package.json +3 -3
- package/src/screens/inbox/components/CachedImage/index.tsx +191 -140
- package/src/screens/inbox/components/DialogsListItem.tsx +104 -368
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +69 -377
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +2 -4
- package/src/screens/inbox/containers/ConversationView.tsx +660 -1060
- package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
- package/src/screens/inbox/containers/Dialogs.tsx +301 -763
- package/src/screens/inbox/containers/ThreadConversationView.tsx +661 -1887
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js +0 -175
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js.map +0 -1
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js +0 -191
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js +0 -380
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +0 -211
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js +0 -438
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React__default,{useRef,
|
|
1
|
+
import React__default,{useRef,useState,useMemo,useCallback}from'react';import {HStack,Box,Text,Pressable,Avatar,AvatarFallbackText,AvatarImage}from'@admin-layout/gluestack-ui-mobile';import {isToday,isYesterday,format}from'date-fns';import {useFocusEffect}from'@react-navigation/native';import {useThreadMessagesQuery,OnThreadChatMessageAddedDocument,OnThreadCreatedUpdatedDocument}from'common/graphql';import {startCase}from'lodash-es';import colors from'tailwindcss/colors';var __defProp = Object.defineProperty;
|
|
2
2
|
var __defProps = Object.defineProperties;
|
|
3
3
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
@@ -44,163 +44,41 @@ const createdAtText = (value) => {
|
|
|
44
44
|
return "Yesterday";
|
|
45
45
|
return format(date, "MMM dd, yyyy");
|
|
46
46
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
value: BaseState.Idle,
|
|
61
|
-
matches: (stateValue) => stateValue === BaseState.Idle
|
|
62
|
-
});
|
|
63
|
-
const send = useCallback((event) => {
|
|
64
|
-
try {
|
|
65
|
-
if (event.type === Actions.INITIAL_CONTEXT) {
|
|
66
|
-
setState((prev) => {
|
|
67
|
-
var _a, _b, _c;
|
|
68
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
69
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
70
|
-
channelId: ((_a = event.data) == null ? void 0 : _a.channelId) || null,
|
|
71
|
-
currentUser: ((_b = event.data) == null ? void 0 : _b.currentUser) || null,
|
|
72
|
-
role: ((_c = event.data) == null ? void 0 : _c.role) || null,
|
|
73
|
-
loading: true
|
|
74
|
-
}),
|
|
75
|
-
value: BaseState.FetchingThreadMessages
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
} else if (event.type === Actions.UPDATE_THREAD_MESSAGES) {
|
|
79
|
-
setState((prev) => {
|
|
80
|
-
var _a, _b, _c, _d, _e;
|
|
81
|
-
if ((_a = event.data) == null ? void 0 : _a.threadMessages) {
|
|
82
|
-
if ((_b = event.data) == null ? void 0 : _b.directLastMessage) {
|
|
83
|
-
console.log("Using direct last message from event:", {
|
|
84
|
-
id: event.data.directLastMessage.id,
|
|
85
|
-
message: ((_c = event.data.directLastMessage.message) == null ? void 0 : _c.substring(0, 20)) + "..."
|
|
86
|
-
});
|
|
87
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
88
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
89
|
-
threadMessages: event.data.threadMessages,
|
|
90
|
-
lastMessage: event.data.directLastMessage,
|
|
91
|
-
loading: false
|
|
92
|
-
})
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
96
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
97
|
-
threadMessages: event.data.threadMessages,
|
|
98
|
-
lastMessage: computeLastMessage(event.data.threadMessages),
|
|
99
|
-
loading: false
|
|
100
|
-
})
|
|
101
|
-
});
|
|
102
|
-
} else if ((_d = event.data) == null ? void 0 : _d.message) {
|
|
103
|
-
const newMessage = event.data.message;
|
|
104
|
-
const updatedMessages = [...prev.context.threadMessages, newMessage];
|
|
105
|
-
console.log("Setting new message as lastMessage from subscription:", {
|
|
106
|
-
id: newMessage.id,
|
|
107
|
-
message: ((_e = newMessage.message) == null ? void 0 : _e.substring(0, 20)) + "...",
|
|
108
|
-
date: newMessage.createdAt || newMessage.updatedAt
|
|
109
|
-
});
|
|
110
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
111
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
112
|
-
threadMessages: updatedMessages,
|
|
113
|
-
lastMessage: newMessage,
|
|
114
|
-
loading: false
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return prev;
|
|
119
|
-
});
|
|
120
|
-
} else if (event.type === Actions.SET_TITLE) {
|
|
121
|
-
setState((prev) => {
|
|
122
|
-
var _a;
|
|
123
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
124
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
125
|
-
title: ((_a = event.data) == null ? void 0 : _a.title) || ""
|
|
126
|
-
})
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
} else if (event.type === Actions.SET_SERVICE_POST_PARENT_ID) {
|
|
130
|
-
setState((prev) => {
|
|
131
|
-
var _a;
|
|
132
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
133
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
134
|
-
servicePostParentId: ((_a = event.data) == null ? void 0 : _a.servicePostParentId) || null
|
|
135
|
-
})
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
} else if (event.type === Actions.START_LOADING) {
|
|
139
|
-
setState((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
140
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
141
|
-
loading: true
|
|
142
|
-
})
|
|
143
|
-
}));
|
|
144
|
-
} else if (event.type === Actions.STOP_LOADING) {
|
|
145
|
-
setState((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
146
|
-
context: __spreadProps(__spreadValues({}, prev.context), {
|
|
147
|
-
loading: false
|
|
148
|
-
})
|
|
149
|
-
}));
|
|
150
|
-
}
|
|
151
|
-
} catch (error) {
|
|
152
|
-
console.error("Error sending event to state machine:", error);
|
|
153
|
-
}
|
|
154
|
-
}, []);
|
|
155
|
-
const computeLastMessage = (threadMessages) => {
|
|
156
|
-
if (!threadMessages || !threadMessages.length)
|
|
157
|
-
return null;
|
|
158
|
-
let posts = [];
|
|
159
|
-
let replies = [];
|
|
160
|
-
const isTextMessage = (msg) => {
|
|
161
|
-
if (!msg)
|
|
162
|
-
return false;
|
|
163
|
-
if (!msg.message || msg.message === "")
|
|
164
|
-
return false;
|
|
165
|
-
const isImageMessage = msg.message.includes("<img") || msg.message.includes("[Image]") || msg.message.includes("![") || /\.(jpeg|jpg|gif|png|bmp|webp)/i.test(msg.message) && (msg.message.includes("http") || msg.message.includes("/images/"));
|
|
166
|
-
return !isImageMessage;
|
|
167
|
-
};
|
|
168
|
-
threadMessages.forEach((thread) => {
|
|
169
|
-
var _a;
|
|
170
|
-
if ((thread == null ? void 0 : thread.post) && isTextMessage(thread.post)) {
|
|
171
|
-
posts.push(thread.post);
|
|
172
|
-
}
|
|
173
|
-
if ((_a = thread == null ? void 0 : thread.replies) == null ? void 0 : _a.length) {
|
|
174
|
-
replies = [...replies, ...thread.replies.filter((r) => isTextMessage(r))];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
const allMessages = [...posts, ...replies];
|
|
178
|
-
if (!allMessages.length)
|
|
179
|
-
return null;
|
|
180
|
-
return allMessages.reduce((a, b) => {
|
|
181
|
-
const dateA = safeDate(a == null ? void 0 : a.createdAt);
|
|
182
|
-
const dateB = safeDate(b == null ? void 0 : b.createdAt);
|
|
183
|
-
if (!dateA)
|
|
184
|
-
return b;
|
|
185
|
-
if (!dateB)
|
|
186
|
-
return a;
|
|
187
|
-
return dateA > dateB ? a : b;
|
|
188
|
-
}, allMessages[0]);
|
|
47
|
+
const computeLastMessage = (threadMessages) => {
|
|
48
|
+
if (!threadMessages || !threadMessages.length)
|
|
49
|
+
return null;
|
|
50
|
+
let posts = [];
|
|
51
|
+
let replies = [];
|
|
52
|
+
const isTextMessage = (msg) => {
|
|
53
|
+
if (!msg)
|
|
54
|
+
return false;
|
|
55
|
+
if (!msg.message || msg.message === "")
|
|
56
|
+
return false;
|
|
57
|
+
const isImageMessage = msg.message.includes("<img") || msg.message.includes("[Image]") || msg.message.includes("![") || /\.(jpeg|jpg|gif|png|bmp|webp)/i.test(msg.message) && (msg.message.includes("http") || msg.message.includes("/images/"));
|
|
58
|
+
return !isImageMessage;
|
|
189
59
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return
|
|
203
|
-
|
|
60
|
+
threadMessages.forEach((thread) => {
|
|
61
|
+
var _a;
|
|
62
|
+
if ((thread == null ? void 0 : thread.post) && isTextMessage(thread.post)) {
|
|
63
|
+
posts.push(thread.post);
|
|
64
|
+
}
|
|
65
|
+
if ((_a = thread == null ? void 0 : thread.replies) == null ? void 0 : _a.length) {
|
|
66
|
+
replies = [...replies, ...thread.replies.filter((r) => isTextMessage(r))];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const allMessages = [...posts, ...replies];
|
|
70
|
+
if (!allMessages.length)
|
|
71
|
+
return null;
|
|
72
|
+
return allMessages.reduce((a, b) => {
|
|
73
|
+
const dateA = safeDate(a == null ? void 0 : a.createdAt);
|
|
74
|
+
const dateB = safeDate(b == null ? void 0 : b.createdAt);
|
|
75
|
+
if (!dateA)
|
|
76
|
+
return b;
|
|
77
|
+
if (!dateB)
|
|
78
|
+
return a;
|
|
79
|
+
return dateA > dateB ? a : b;
|
|
80
|
+
}, allMessages[0]);
|
|
81
|
+
};
|
|
204
82
|
const ServiceChannelWithLastMessage = React__default.memo(({
|
|
205
83
|
channel,
|
|
206
84
|
lastMessage,
|
|
@@ -272,27 +150,11 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
272
150
|
refreshing,
|
|
273
151
|
role
|
|
274
152
|
}) {
|
|
275
|
-
var _a, _b, _c, _d;
|
|
153
|
+
var _a, _b, _c, _d, _e;
|
|
276
154
|
const isMountedRef = useRef(true);
|
|
277
|
-
const [
|
|
278
|
-
const safeContextProperty = useCallback((property, defaultValue = null) => {
|
|
279
|
-
var _a2, _b2;
|
|
280
|
-
try {
|
|
281
|
-
return (_b2 = (_a2 = state == null ? void 0 : state.context) == null ? void 0 : _a2[property]) != null ? _b2 : defaultValue;
|
|
282
|
-
} catch (error2) {
|
|
283
|
-
console.error(`Error accessing state.context.${property}:`, error2);
|
|
284
|
-
return defaultValue;
|
|
285
|
-
}
|
|
286
|
-
}, [state]);
|
|
287
|
-
const safeSend = useCallback((event) => {
|
|
288
|
-
try {
|
|
289
|
-
send(event);
|
|
290
|
-
} catch (error2) {
|
|
291
|
-
console.error("Error sending event to state machine:", error2, event);
|
|
292
|
-
}
|
|
293
|
-
}, [send]);
|
|
155
|
+
const [subscriptionsTimestamp, setSubscriptionsTimestamp] = useState(Date.now());
|
|
294
156
|
const {
|
|
295
|
-
data:
|
|
157
|
+
data: threadMessagesData,
|
|
296
158
|
loading: threadMessageLoading,
|
|
297
159
|
error,
|
|
298
160
|
refetch: refetchThreadMessages,
|
|
@@ -312,58 +174,22 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
312
174
|
console.error(`Error fetching thread messages for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
313
175
|
}
|
|
314
176
|
});
|
|
177
|
+
const threadMessages = ((_b = threadMessagesData == null ? void 0 : threadMessagesData.threadMessages) == null ? void 0 : _b.data) || [];
|
|
178
|
+
const lastMessage = useMemo(() => {
|
|
179
|
+
return computeLastMessage(threadMessages);
|
|
180
|
+
}, [threadMessages]);
|
|
181
|
+
const servicePostParentId = useMemo(() => {
|
|
182
|
+
if (!lastMessage)
|
|
183
|
+
return null;
|
|
184
|
+
return (lastMessage == null ? void 0 : lastMessage.parentId) ? lastMessage == null ? void 0 : lastMessage.parentId : lastMessage == null ? void 0 : lastMessage.id;
|
|
185
|
+
}, [lastMessage]);
|
|
315
186
|
React__default.useEffect(() => {
|
|
316
|
-
var _a2;
|
|
317
|
-
if (channel == null ? void 0 : channel.id) {
|
|
318
|
-
safeSend({
|
|
319
|
-
type: Actions.INITIAL_CONTEXT,
|
|
320
|
-
data: {
|
|
321
|
-
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
322
|
-
currentUser,
|
|
323
|
-
role
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
safeSend({
|
|
327
|
-
type: Actions.SET_TITLE,
|
|
328
|
-
data: {
|
|
329
|
-
title: (channel == null ? void 0 : channel.title) || ""
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
187
|
return () => {
|
|
334
188
|
isMountedRef.current = false;
|
|
335
189
|
};
|
|
336
|
-
}, [
|
|
337
|
-
|
|
338
|
-
var _a2, _b2, _c2;
|
|
339
|
-
if (threadMessages && isMountedRef.current) {
|
|
340
|
-
console.log(`Updating thread messages for channel ${channel == null ? void 0 : channel.id}, count:`, ((_b2 = (_a2 = threadMessages == null ? void 0 : threadMessages.threadMessages) == null ? void 0 : _a2.data) == null ? void 0 : _b2.length) || 0);
|
|
341
|
-
safeSend({
|
|
342
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
343
|
-
data: {
|
|
344
|
-
threadMessages: ((_c2 = threadMessages == null ? void 0 : threadMessages.threadMessages) == null ? void 0 : _c2.data) || []
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}, [threadMessages, refreshing, channel == null ? void 0 : channel.id, safeSend]);
|
|
349
|
-
const lastMessage = safeContextProperty("lastMessage", null);
|
|
350
|
-
const servicePostParentId = safeContextProperty("servicePostParentId", null);
|
|
351
|
-
React__default.useEffect(() => {
|
|
352
|
-
if (lastMessage) {
|
|
353
|
-
const sParentId = (lastMessage == null ? void 0 : lastMessage.parentId) ? lastMessage == null ? void 0 : lastMessage.parentId : lastMessage == null ? void 0 : lastMessage.id;
|
|
354
|
-
if (sParentId !== safeContextProperty("servicePostParentId")) {
|
|
355
|
-
console.log(`Updating servicePostParentId for channel ${channel == null ? void 0 : channel.id} to:`, sParentId);
|
|
356
|
-
safeSend({
|
|
357
|
-
type: Actions.SET_SERVICE_POST_PARENT_ID,
|
|
358
|
-
data: {
|
|
359
|
-
servicePostParentId: sParentId
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}, [lastMessage, safeSend, channel == null ? void 0 : channel.id, safeContextProperty]);
|
|
365
|
-
const creatorAndMembersId = React__default.useMemo(() => {
|
|
366
|
-
var _a2, _b2, _c2, _d2, _e, _f;
|
|
190
|
+
}, []);
|
|
191
|
+
const creatorAndMembersId = useMemo(() => {
|
|
192
|
+
var _a2, _b2, _c2, _d2, _e2, _f;
|
|
367
193
|
if (!(channel == null ? void 0 : channel.members))
|
|
368
194
|
return null;
|
|
369
195
|
const membersIds = (_c2 = (_b2 = (_a2 = channel == null ? void 0 : channel.members) == null ? void 0 : _a2.filter((m) => {
|
|
@@ -374,10 +200,10 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
374
200
|
return (_a3 = mu == null ? void 0 : mu.user) == null ? void 0 : _a3.id;
|
|
375
201
|
})) != null ? _c2 : [];
|
|
376
202
|
const creatorId = (_d2 = channel == null ? void 0 : channel.creator) == null ? void 0 : _d2.id;
|
|
377
|
-
const mergedIds = (
|
|
203
|
+
const mergedIds = (_e2 = [].concat(membersIds, creatorId)) != null ? _e2 : [];
|
|
378
204
|
return (_f = mergedIds == null ? void 0 : mergedIds.filter((m, pos) => (mergedIds == null ? void 0 : mergedIds.indexOf(m)) === pos)) != null ? _f : [];
|
|
379
205
|
}, [channel, currentUser]);
|
|
380
|
-
const postParentId =
|
|
206
|
+
const postParentId = useMemo(() => {
|
|
381
207
|
var _a2;
|
|
382
208
|
if (!(creatorAndMembersId == null ? void 0 : creatorAndMembersId.length))
|
|
383
209
|
return null;
|
|
@@ -387,232 +213,175 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
387
213
|
var _a2;
|
|
388
214
|
if ((channel == null ? void 0 : channel.id) && isMountedRef.current) {
|
|
389
215
|
console.log("Forcing thread state refresh for channel:", channel == null ? void 0 : channel.id);
|
|
390
|
-
safeSend({
|
|
391
|
-
type: Actions.START_LOADING
|
|
392
|
-
});
|
|
393
216
|
refetchThreadMessages({
|
|
394
217
|
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
395
218
|
role,
|
|
396
219
|
limit: 2
|
|
397
|
-
}).then((result) => {
|
|
398
|
-
var _a3, _b2;
|
|
399
|
-
if (((_b2 = (_a3 = result.data) == null ? void 0 : _a3.threadMessages) == null ? void 0 : _b2.data) && isMountedRef.current) {
|
|
400
|
-
console.log(`Refreshed ${result.data.threadMessages.data.length} thread messages for channel ${channel == null ? void 0 : channel.id}`);
|
|
401
|
-
safeSend({
|
|
402
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
403
|
-
data: {
|
|
404
|
-
threadMessages: result.data.threadMessages.data
|
|
405
|
-
}
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
safeSend({
|
|
409
|
-
type: Actions.STOP_LOADING
|
|
410
|
-
});
|
|
411
220
|
}).catch((err) => {
|
|
412
221
|
console.error("Error refreshing thread state:", err);
|
|
413
|
-
safeSend({
|
|
414
|
-
type: Actions.STOP_LOADING
|
|
415
|
-
});
|
|
416
222
|
});
|
|
417
223
|
}
|
|
418
|
-
}, [channel == null ? void 0 : channel.id, refetchThreadMessages,
|
|
419
|
-
const [subscriptionsTimestamp, setSubscriptionsTimestamp] = useState(Date.now());
|
|
224
|
+
}, [channel == null ? void 0 : channel.id, refetchThreadMessages, isMountedRef, role]);
|
|
420
225
|
useFocusEffect(React__default.useCallback(() => {
|
|
421
226
|
setSubscriptionsTimestamp(Date.now());
|
|
422
227
|
if (!(channel == null ? void 0 : channel.id))
|
|
423
228
|
return;
|
|
424
229
|
console.log("ServiceDialogsListItem focused for channel:", channel == null ? void 0 : channel.id);
|
|
425
|
-
safeSend({
|
|
426
|
-
type: Actions.START_LOADING
|
|
427
|
-
});
|
|
428
230
|
const fetchFreshData = async () => {
|
|
429
|
-
var _a2
|
|
231
|
+
var _a2;
|
|
430
232
|
try {
|
|
431
|
-
|
|
233
|
+
await refetchThreadMessages({
|
|
432
234
|
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
433
235
|
role,
|
|
434
236
|
limit: 2
|
|
435
237
|
});
|
|
436
|
-
console.log(`FOCUS EFFECT: Refetched ${((_d2 = (_c2 = (_b2 = result == null ? void 0 : result.data) == null ? void 0 : _b2.threadMessages) == null ? void 0 : _c2.data) == null ? void 0 : _d2.length) || 0} messages for channel ${channel == null ? void 0 : channel.id}`);
|
|
437
|
-
if (((_f = (_e = result == null ? void 0 : result.data) == null ? void 0 : _e.threadMessages) == null ? void 0 : _f.data) && isMountedRef.current) {
|
|
438
|
-
safeSend({
|
|
439
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
440
|
-
data: {
|
|
441
|
-
threadMessages: result.data.threadMessages.data
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
238
|
} catch (error2) {
|
|
446
239
|
console.error("Error refetching thread messages on focus:", error2);
|
|
447
|
-
} finally {
|
|
448
|
-
if (isMountedRef.current) {
|
|
449
|
-
safeSend({
|
|
450
|
-
type: Actions.STOP_LOADING
|
|
451
|
-
});
|
|
452
|
-
}
|
|
453
240
|
}
|
|
454
241
|
};
|
|
455
242
|
fetchFreshData();
|
|
456
243
|
return () => {
|
|
457
244
|
};
|
|
458
|
-
}, [refreshing, channel == null ? void 0 : channel.id, refetchThreadMessages,
|
|
459
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (!
|
|
489
|
-
console.log(`
|
|
245
|
+
}, [refreshing, channel == null ? void 0 : channel.id, refetchThreadMessages, role]));
|
|
246
|
+
return /* @__PURE__ */ React__default.createElement(
|
|
247
|
+
Pressable,
|
|
248
|
+
{
|
|
249
|
+
onPress: () => onOpen(channel == null ? void 0 : channel.id, channel == null ? void 0 : channel.title, postParentId),
|
|
250
|
+
className: "flex-1 rounded-md border-gray-200 dark:border-gray-600 dark:bg-gray-700",
|
|
251
|
+
style: {
|
|
252
|
+
borderBottomWidth: 1,
|
|
253
|
+
borderColor: "#e5e7eb",
|
|
254
|
+
marginVertical: 0
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
/* @__PURE__ */ React__default.createElement(HStack, { space: "md", className: "flex-1 w-[100%] px-2 py-3 items-center" }, /* @__PURE__ */ React__default.createElement(Box, { className: "flex-[0.1] items-start pl-3" }, /* @__PURE__ */ React__default.createElement(Avatar, { key: "service-channels-key-" + (channel == null ? void 0 : channel.id), size: "sm", className: "bg-transparent top-0 right-0 z-[1]" }, /* @__PURE__ */ React__default.createElement(AvatarFallbackText, null, " ", startCase((_d = (_c = channel == null ? void 0 : channel.creator) == null ? void 0 : _c.username) == null ? void 0 : _d.charAt(0))), /* @__PURE__ */ React__default.createElement(AvatarImage, { alt: "user image", style: {
|
|
258
|
+
borderRadius: 6,
|
|
259
|
+
borderWidth: 2,
|
|
260
|
+
borderColor: "#fff"
|
|
261
|
+
}, source: {
|
|
262
|
+
uri: (_e = channel == null ? void 0 : channel.creator) == null ? void 0 : _e.picture
|
|
263
|
+
} }))), /* @__PURE__ */ React__default.createElement(Box, { className: "flex-1" }, /* @__PURE__ */ React__default.createElement(ServiceChannelWithLastMessage, { key: `channel-${channel == null ? void 0 : channel.id}-${subscriptionsTimestamp}`, channel, lastMessage, subscribeToNewMessages: () => {
|
|
264
|
+
var _a2;
|
|
265
|
+
return subscribeToMore({
|
|
266
|
+
document: OnThreadCreatedUpdatedDocument,
|
|
267
|
+
variables: {
|
|
268
|
+
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
269
|
+
postParentId: postParentId || servicePostParentId || null
|
|
270
|
+
},
|
|
271
|
+
updateQuery: (prev, {
|
|
272
|
+
subscriptionData
|
|
273
|
+
}) => {
|
|
274
|
+
var _a3, _b2, _c2, _d2, _e2, _f, _g, _h, _i;
|
|
275
|
+
if (!(subscriptionData == null ? void 0 : subscriptionData.data)) {
|
|
276
|
+
console.log(`No subscription data for channel ${channel == null ? void 0 : channel.id}`);
|
|
490
277
|
return prev;
|
|
491
278
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
replyCount: newPostThreadData == null ? void 0 : newPostThreadData.replyCount,
|
|
505
|
-
lastReplyAt: newPostThreadData == null ? void 0 : newPostThreadData.lastReplyAt,
|
|
506
|
-
updatedAt: newPostThreadData == null ? void 0 : newPostThreadData.updatedAt
|
|
507
|
-
}) : t);
|
|
508
|
-
} else {
|
|
509
|
-
updatedThreads = [...prevThreads, newPostThreadData];
|
|
510
|
-
}
|
|
511
|
-
if (isMountedRef.current) {
|
|
512
|
-
safeSend({
|
|
513
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
514
|
-
data: {
|
|
515
|
-
threadMessages: updatedThreads,
|
|
516
|
-
directLastMessage: newMessage
|
|
517
|
-
}
|
|
279
|
+
try {
|
|
280
|
+
const newPostThreadData = (_b2 = (_a3 = subscriptionData == null ? void 0 : subscriptionData.data) == null ? void 0 : _a3.threadCreatedUpdated) == null ? void 0 : _b2.data;
|
|
281
|
+
const newMessage = (_d2 = (_c2 = subscriptionData == null ? void 0 : subscriptionData.data) == null ? void 0 : _c2.threadCreatedUpdated) == null ? void 0 : _d2.lastMessage;
|
|
282
|
+
if (!newPostThreadData || !newMessage) {
|
|
283
|
+
console.log(`Missing data in subscription for channel ${channel == null ? void 0 : channel.id}`);
|
|
284
|
+
return prev;
|
|
285
|
+
}
|
|
286
|
+
console.log("New thread message subscription update:", {
|
|
287
|
+
channelId: channel == null ? void 0 : channel.id,
|
|
288
|
+
threadId: newPostThreadData == null ? void 0 : newPostThreadData.id,
|
|
289
|
+
hasMessage: !!newMessage,
|
|
290
|
+
message: ((_e2 = newMessage == null ? void 0 : newMessage.message) == null ? void 0 : _e2.substring(0, 20)) + "..."
|
|
518
291
|
});
|
|
292
|
+
const prevThreads = ((_f = prev == null ? void 0 : prev.threadMessages) == null ? void 0 : _f.data) || [];
|
|
293
|
+
const threadExists = prevThreads.some((t) => t.id === (newPostThreadData == null ? void 0 : newPostThreadData.id));
|
|
294
|
+
let updatedThreads;
|
|
295
|
+
if (threadExists) {
|
|
296
|
+
updatedThreads = prevThreads.map((t) => t.id === (newPostThreadData == null ? void 0 : newPostThreadData.id) ? __spreadProps(__spreadValues({}, t), {
|
|
297
|
+
replies: [...(t == null ? void 0 : t.replies) || [], newMessage],
|
|
298
|
+
replyCount: newPostThreadData == null ? void 0 : newPostThreadData.replyCount,
|
|
299
|
+
lastReplyAt: newPostThreadData == null ? void 0 : newPostThreadData.lastReplyAt,
|
|
300
|
+
updatedAt: newPostThreadData == null ? void 0 : newPostThreadData.updatedAt
|
|
301
|
+
}) : t);
|
|
302
|
+
} else {
|
|
303
|
+
updatedThreads = [...prevThreads, newPostThreadData];
|
|
304
|
+
}
|
|
305
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
306
|
+
threadMessages: __spreadProps(__spreadValues({}, prev == null ? void 0 : prev.threadMessages), {
|
|
307
|
+
totalCount: (_i = (_h = newPostThreadData == null ? void 0 : newPostThreadData.totalCount) != null ? _h : (_g = prev == null ? void 0 : prev.threadMessages) == null ? void 0 : _g.totalCount) != null ? _i : 0,
|
|
308
|
+
data: updatedThreads
|
|
309
|
+
})
|
|
310
|
+
});
|
|
311
|
+
} catch (error2) {
|
|
312
|
+
console.error(`Error processing subscription data for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
313
|
+
return prev;
|
|
519
314
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
data: updatedThreads
|
|
524
|
-
})
|
|
525
|
-
});
|
|
526
|
-
} catch (error2) {
|
|
527
|
-
console.error(`Error processing subscription data for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
528
|
-
return prev;
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
onError: (error2) => {
|
|
532
|
-
console.error(`Thread subscription error for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
}, subscribeToChatMessages: () => {
|
|
536
|
-
var _a2;
|
|
537
|
-
return subscribeToMore({
|
|
538
|
-
document: OnThreadChatMessageAddedDocument,
|
|
539
|
-
variables: {
|
|
540
|
-
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
541
|
-
postParentId: postParentId || servicePostParentId || null
|
|
542
|
-
},
|
|
543
|
-
updateQuery: (prev, {
|
|
544
|
-
subscriptionData
|
|
545
|
-
}) => {
|
|
546
|
-
var _a3, _b2, _c2;
|
|
547
|
-
if (!(subscriptionData == null ? void 0 : subscriptionData.data)) {
|
|
548
|
-
console.log(`No chat message subscription data for channel ${channel == null ? void 0 : channel.id}`);
|
|
549
|
-
return prev;
|
|
315
|
+
},
|
|
316
|
+
onError: (error2) => {
|
|
317
|
+
console.error(`Thread subscription error for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
550
318
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
319
|
+
});
|
|
320
|
+
}, subscribeToChatMessages: () => {
|
|
321
|
+
var _a2;
|
|
322
|
+
return subscribeToMore({
|
|
323
|
+
document: OnThreadChatMessageAddedDocument,
|
|
324
|
+
variables: {
|
|
325
|
+
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
326
|
+
postParentId: postParentId || servicePostParentId || null
|
|
327
|
+
},
|
|
328
|
+
updateQuery: (prev, {
|
|
329
|
+
subscriptionData
|
|
330
|
+
}) => {
|
|
331
|
+
var _a3, _b2, _c2;
|
|
332
|
+
if (!(subscriptionData == null ? void 0 : subscriptionData.data)) {
|
|
333
|
+
console.log(`No chat message subscription data for channel ${channel == null ? void 0 : channel.id}`);
|
|
555
334
|
return prev;
|
|
556
335
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
const prevThreads = ((_c2 = prev == null ? void 0 : prev.threadMessages) == null ? void 0 : _c2.data) || [];
|
|
563
|
-
const threadIndex = prevThreads.findIndex((t) => {
|
|
564
|
-
var _a4;
|
|
565
|
-
if (newMessage.parentId && ((_a4 = t.post) == null ? void 0 : _a4.id) === newMessage.parentId) {
|
|
566
|
-
return true;
|
|
567
|
-
}
|
|
568
|
-
if (t.replies && t.replies.some((r) => r.id === newMessage.parentId)) {
|
|
569
|
-
return true;
|
|
336
|
+
try {
|
|
337
|
+
const newMessage = (_a3 = subscriptionData == null ? void 0 : subscriptionData.data) == null ? void 0 : _a3.chatMessageAdded;
|
|
338
|
+
if (!newMessage) {
|
|
339
|
+
console.log(`Missing chat message data in subscription for channel ${channel == null ? void 0 : channel.id}`);
|
|
340
|
+
return prev;
|
|
570
341
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
return prev;
|
|
584
|
-
}
|
|
585
|
-
const updatedThreads = [...prevThreads];
|
|
586
|
-
const thread = __spreadValues({}, updatedThreads[threadIndex]);
|
|
587
|
-
thread.replies = [...thread.replies || [], newMessage];
|
|
588
|
-
const currentReplyCount = typeof thread.replyCount === "number" ? thread.replyCount : 0;
|
|
589
|
-
thread.replyCount = currentReplyCount + 1;
|
|
590
|
-
thread.lastReplyAt = newMessage.createdAt;
|
|
591
|
-
thread.updatedAt = newMessage.createdAt;
|
|
592
|
-
updatedThreads[threadIndex] = thread;
|
|
593
|
-
if (isMountedRef.current) {
|
|
594
|
-
safeSend({
|
|
595
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
596
|
-
data: {
|
|
597
|
-
threadMessages: updatedThreads,
|
|
598
|
-
directLastMessage: newMessage
|
|
342
|
+
console.log("New chat message subscription update:", {
|
|
343
|
+
channelId: channel == null ? void 0 : channel.id,
|
|
344
|
+
messageId: newMessage == null ? void 0 : newMessage.id,
|
|
345
|
+
message: ((_b2 = newMessage == null ? void 0 : newMessage.message) == null ? void 0 : _b2.substring(0, 20)) + "..."
|
|
346
|
+
});
|
|
347
|
+
const prevThreads = ((_c2 = prev == null ? void 0 : prev.threadMessages) == null ? void 0 : _c2.data) || [];
|
|
348
|
+
const threadIndex = prevThreads.findIndex((t) => {
|
|
349
|
+
var _a4;
|
|
350
|
+
if (newMessage.parentId && ((_a4 = t.post) == null ? void 0 : _a4.id) === newMessage.parentId) {
|
|
351
|
+
return true;
|
|
599
352
|
}
|
|
353
|
+
if (t.replies && t.replies.some((r) => r.id === newMessage.parentId)) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
600
357
|
});
|
|
358
|
+
if (threadIndex === -1) {
|
|
359
|
+
console.log(`Cannot find thread for chat message in channel ${channel == null ? void 0 : channel.id}`);
|
|
360
|
+
return prev;
|
|
361
|
+
}
|
|
362
|
+
const updatedThreads = [...prevThreads];
|
|
363
|
+
const thread = __spreadValues({}, updatedThreads[threadIndex]);
|
|
364
|
+
thread.replies = [...thread.replies || [], newMessage];
|
|
365
|
+
const currentReplyCount = typeof thread.replyCount === "number" ? thread.replyCount : 0;
|
|
366
|
+
thread.replyCount = currentReplyCount + 1;
|
|
367
|
+
thread.lastReplyAt = newMessage.createdAt;
|
|
368
|
+
thread.updatedAt = newMessage.createdAt;
|
|
369
|
+
updatedThreads[threadIndex] = thread;
|
|
370
|
+
return __spreadProps(__spreadValues({}, prev), {
|
|
371
|
+
threadMessages: __spreadProps(__spreadValues({}, prev == null ? void 0 : prev.threadMessages), {
|
|
372
|
+
data: updatedThreads
|
|
373
|
+
})
|
|
374
|
+
});
|
|
375
|
+
} catch (error2) {
|
|
376
|
+
console.error(`Error processing chat message subscription for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
377
|
+
return prev;
|
|
601
378
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
})
|
|
606
|
-
});
|
|
607
|
-
} catch (error2) {
|
|
608
|
-
console.error(`Error processing chat message subscription for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
609
|
-
return prev;
|
|
379
|
+
},
|
|
380
|
+
onError: (error2) => {
|
|
381
|
+
console.error(`Chat message subscription error for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
610
382
|
}
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
});
|
|
616
|
-
} }))));
|
|
383
|
+
});
|
|
384
|
+
} })))
|
|
385
|
+
);
|
|
617
386
|
};
|
|
618
387
|
const ServiceDialogsListItem = React__default.memo(ServiceDialogsListItemComponent);export{ServiceDialogsListItem,ServiceDialogsListItemComponent};//# sourceMappingURL=ServiceDialogsListItem.js.map
|