@messenger-box/platform-mobile 10.0.3-alpha.34 → 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 +8 -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 +80 -256
- package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +222 -324
- 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 +487 -888
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +243 -547
- 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 +4 -4
- package/src/screens/inbox/components/CachedImage/index.tsx +191 -140
- package/src/screens/inbox/components/DialogsListItem.tsx +112 -345
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +316 -437
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +2 -4
- package/src/screens/inbox/containers/ConversationView.tsx +676 -993
- package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
- package/src/screens/inbox/containers/Dialogs.tsx +345 -636
- 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,177 +44,77 @@ 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,
|
|
207
|
-
subscribeToNewMessages
|
|
85
|
+
subscribeToNewMessages,
|
|
86
|
+
subscribeToChatMessages
|
|
208
87
|
}) => {
|
|
209
88
|
var _a, _b, _c, _d, _e;
|
|
210
89
|
React__default.useEffect(() => {
|
|
211
|
-
|
|
90
|
+
console.log(`Setting up subscriptions for channel ${channel == null ? void 0 : channel.id}`);
|
|
91
|
+
let threadUnsubscribe;
|
|
92
|
+
let chatUnsubscribe;
|
|
93
|
+
try {
|
|
94
|
+
threadUnsubscribe = subscribeToNewMessages();
|
|
95
|
+
chatUnsubscribe = subscribeToChatMessages();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error(`Error setting up subscriptions for channel ${channel == null ? void 0 : channel.id}:`, error);
|
|
98
|
+
}
|
|
212
99
|
return () => {
|
|
213
|
-
if (
|
|
214
|
-
|
|
100
|
+
if (threadUnsubscribe && typeof threadUnsubscribe === "function") {
|
|
101
|
+
try {
|
|
102
|
+
console.log(`Cleaning up thread subscription for channel ${channel == null ? void 0 : channel.id}`);
|
|
103
|
+
threadUnsubscribe();
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(`Error cleaning up thread subscription for channel ${channel == null ? void 0 : channel.id}:`, error);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (chatUnsubscribe && typeof chatUnsubscribe === "function") {
|
|
109
|
+
try {
|
|
110
|
+
console.log(`Cleaning up chat subscription for channel ${channel == null ? void 0 : channel.id}`);
|
|
111
|
+
chatUnsubscribe();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error(`Error cleaning up chat subscription for channel ${channel == null ? void 0 : channel.id}:`, error);
|
|
114
|
+
}
|
|
215
115
|
}
|
|
216
116
|
};
|
|
217
|
-
}, [subscribeToNewMessages]);
|
|
117
|
+
}, [subscribeToNewMessages, subscribeToChatMessages, channel == null ? void 0 : channel.id]);
|
|
218
118
|
React__default.useEffect(() => {
|
|
219
119
|
var _a2, _b2, _c2;
|
|
220
120
|
console.log(`ServiceChannelWithLastMessage rendered for channel ${channel == null ? void 0 : channel.id}:`, {
|
|
@@ -250,27 +150,11 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
250
150
|
refreshing,
|
|
251
151
|
role
|
|
252
152
|
}) {
|
|
253
|
-
var _a, _b, _c, _d;
|
|
153
|
+
var _a, _b, _c, _d, _e;
|
|
254
154
|
const isMountedRef = useRef(true);
|
|
255
|
-
const [
|
|
256
|
-
const safeContextProperty = useCallback((property, defaultValue = null) => {
|
|
257
|
-
var _a2, _b2;
|
|
258
|
-
try {
|
|
259
|
-
return (_b2 = (_a2 = state == null ? void 0 : state.context) == null ? void 0 : _a2[property]) != null ? _b2 : defaultValue;
|
|
260
|
-
} catch (error2) {
|
|
261
|
-
console.error(`Error accessing state.context.${property}:`, error2);
|
|
262
|
-
return defaultValue;
|
|
263
|
-
}
|
|
264
|
-
}, [state]);
|
|
265
|
-
const safeSend = useCallback((event) => {
|
|
266
|
-
try {
|
|
267
|
-
send(event);
|
|
268
|
-
} catch (error2) {
|
|
269
|
-
console.error("Error sending event to state machine:", error2, event);
|
|
270
|
-
}
|
|
271
|
-
}, [send]);
|
|
155
|
+
const [subscriptionsTimestamp, setSubscriptionsTimestamp] = useState(Date.now());
|
|
272
156
|
const {
|
|
273
|
-
data:
|
|
157
|
+
data: threadMessagesData,
|
|
274
158
|
loading: threadMessageLoading,
|
|
275
159
|
error,
|
|
276
160
|
refetch: refetchThreadMessages,
|
|
@@ -290,55 +174,22 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
290
174
|
console.error(`Error fetching thread messages for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
291
175
|
}
|
|
292
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]);
|
|
293
186
|
React__default.useEffect(() => {
|
|
294
|
-
var _a2;
|
|
295
|
-
if (channel == null ? void 0 : channel.id) {
|
|
296
|
-
safeSend({
|
|
297
|
-
type: Actions.INITIAL_CONTEXT,
|
|
298
|
-
data: {
|
|
299
|
-
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
300
|
-
currentUser,
|
|
301
|
-
role
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
safeSend({
|
|
305
|
-
type: Actions.SET_TITLE,
|
|
306
|
-
data: {
|
|
307
|
-
title: (channel == null ? void 0 : channel.title) || ""
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
187
|
return () => {
|
|
312
188
|
isMountedRef.current = false;
|
|
313
189
|
};
|
|
314
|
-
}, [
|
|
315
|
-
|
|
316
|
-
var _a2, _b2, _c2;
|
|
317
|
-
if (threadMessages && isMountedRef.current) {
|
|
318
|
-
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);
|
|
319
|
-
safeSend({
|
|
320
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
321
|
-
data: {
|
|
322
|
-
threadMessages: ((_c2 = threadMessages == null ? void 0 : threadMessages.threadMessages) == null ? void 0 : _c2.data) || []
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
}, [threadMessages, refreshing, channel == null ? void 0 : channel.id, safeSend]);
|
|
327
|
-
const lastMessage = safeContextProperty("lastMessage", null);
|
|
328
|
-
const servicePostParentId = safeContextProperty("servicePostParentId", null);
|
|
329
|
-
React__default.useEffect(() => {
|
|
330
|
-
if (lastMessage) {
|
|
331
|
-
const sParentId = (lastMessage == null ? void 0 : lastMessage.parentId) ? lastMessage == null ? void 0 : lastMessage.parentId : lastMessage == null ? void 0 : lastMessage.id;
|
|
332
|
-
safeSend({
|
|
333
|
-
type: Actions.SET_SERVICE_POST_PARENT_ID,
|
|
334
|
-
data: {
|
|
335
|
-
servicePostParentId: sParentId
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}, [lastMessage, safeSend]);
|
|
340
|
-
const creatorAndMembersId = React__default.useMemo(() => {
|
|
341
|
-
var _a2, _b2, _c2, _d2, _e, _f;
|
|
190
|
+
}, []);
|
|
191
|
+
const creatorAndMembersId = useMemo(() => {
|
|
192
|
+
var _a2, _b2, _c2, _d2, _e2, _f;
|
|
342
193
|
if (!(channel == null ? void 0 : channel.members))
|
|
343
194
|
return null;
|
|
344
195
|
const membersIds = (_c2 = (_b2 = (_a2 = channel == null ? void 0 : channel.members) == null ? void 0 : _a2.filter((m) => {
|
|
@@ -349,10 +200,10 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
349
200
|
return (_a3 = mu == null ? void 0 : mu.user) == null ? void 0 : _a3.id;
|
|
350
201
|
})) != null ? _c2 : [];
|
|
351
202
|
const creatorId = (_d2 = channel == null ? void 0 : channel.creator) == null ? void 0 : _d2.id;
|
|
352
|
-
const mergedIds = (
|
|
203
|
+
const mergedIds = (_e2 = [].concat(membersIds, creatorId)) != null ? _e2 : [];
|
|
353
204
|
return (_f = mergedIds == null ? void 0 : mergedIds.filter((m, pos) => (mergedIds == null ? void 0 : mergedIds.indexOf(m)) === pos)) != null ? _f : [];
|
|
354
205
|
}, [channel, currentUser]);
|
|
355
|
-
const postParentId =
|
|
206
|
+
const postParentId = useMemo(() => {
|
|
356
207
|
var _a2;
|
|
357
208
|
if (!(creatorAndMembersId == null ? void 0 : creatorAndMembersId.length))
|
|
358
209
|
return null;
|
|
@@ -362,128 +213,175 @@ const ServiceDialogsListItemComponent = function DialogsListItem({
|
|
|
362
213
|
var _a2;
|
|
363
214
|
if ((channel == null ? void 0 : channel.id) && isMountedRef.current) {
|
|
364
215
|
console.log("Forcing thread state refresh for channel:", channel == null ? void 0 : channel.id);
|
|
365
|
-
safeSend({
|
|
366
|
-
type: Actions.START_LOADING
|
|
367
|
-
});
|
|
368
216
|
refetchThreadMessages({
|
|
369
217
|
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
370
218
|
role,
|
|
371
219
|
limit: 2
|
|
372
|
-
}).then((result) => {
|
|
373
|
-
var _a3, _b2;
|
|
374
|
-
if (((_b2 = (_a3 = result.data) == null ? void 0 : _a3.threadMessages) == null ? void 0 : _b2.data) && isMountedRef.current) {
|
|
375
|
-
console.log(`Refreshed ${result.data.threadMessages.data.length} thread messages for channel ${channel == null ? void 0 : channel.id}`);
|
|
376
|
-
safeSend({
|
|
377
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
378
|
-
data: {
|
|
379
|
-
threadMessages: result.data.threadMessages.data
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
safeSend({
|
|
384
|
-
type: Actions.STOP_LOADING
|
|
385
|
-
});
|
|
386
220
|
}).catch((err) => {
|
|
387
221
|
console.error("Error refreshing thread state:", err);
|
|
388
|
-
safeSend({
|
|
389
|
-
type: Actions.STOP_LOADING
|
|
390
|
-
});
|
|
391
222
|
});
|
|
392
223
|
}
|
|
393
|
-
}, [channel == null ? void 0 : channel.id, refetchThreadMessages,
|
|
224
|
+
}, [channel == null ? void 0 : channel.id, refetchThreadMessages, isMountedRef, role]);
|
|
394
225
|
useFocusEffect(React__default.useCallback(() => {
|
|
226
|
+
setSubscriptionsTimestamp(Date.now());
|
|
395
227
|
if (!(channel == null ? void 0 : channel.id))
|
|
396
228
|
return;
|
|
397
229
|
console.log("ServiceDialogsListItem focused for channel:", channel == null ? void 0 : channel.id);
|
|
398
|
-
safeSend({
|
|
399
|
-
type: Actions.START_LOADING
|
|
400
|
-
});
|
|
401
230
|
const fetchFreshData = async () => {
|
|
402
|
-
var _a2
|
|
231
|
+
var _a2;
|
|
403
232
|
try {
|
|
404
|
-
|
|
233
|
+
await refetchThreadMessages({
|
|
405
234
|
channelId: (_a2 = channel == null ? void 0 : channel.id) == null ? void 0 : _a2.toString(),
|
|
406
235
|
role,
|
|
407
236
|
limit: 2
|
|
408
237
|
});
|
|
409
|
-
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}`);
|
|
410
|
-
if (((_f = (_e = result == null ? void 0 : result.data) == null ? void 0 : _e.threadMessages) == null ? void 0 : _f.data) && isMountedRef.current) {
|
|
411
|
-
safeSend({
|
|
412
|
-
type: Actions.UPDATE_THREAD_MESSAGES,
|
|
413
|
-
data: {
|
|
414
|
-
threadMessages: result.data.threadMessages.data
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
238
|
} catch (error2) {
|
|
419
239
|
console.error("Error refetching thread messages on focus:", error2);
|
|
420
|
-
} finally {
|
|
421
|
-
if (isMountedRef.current) {
|
|
422
|
-
safeSend({
|
|
423
|
-
type: Actions.STOP_LOADING
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
240
|
}
|
|
427
241
|
};
|
|
428
242
|
fetchFreshData();
|
|
429
243
|
return () => {
|
|
430
244
|
};
|
|
431
|
-
}, [refreshing, channel == null ? void 0 : channel.id, refetchThreadMessages,
|
|
432
|
-
return /* @__PURE__ */ React__default.createElement(
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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}`);
|
|
277
|
+
return prev;
|
|
278
|
+
}
|
|
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)) + "..."
|
|
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];
|
|
476
304
|
}
|
|
477
|
-
|
|
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;
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
onError: (error2) => {
|
|
317
|
+
console.error(`Thread subscription error for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
478
318
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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}`);
|
|
334
|
+
return prev;
|
|
335
|
+
}
|
|
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;
|
|
341
|
+
}
|
|
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;
|
|
352
|
+
}
|
|
353
|
+
if (t.replies && t.replies.some((r) => r.id === newMessage.parentId)) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
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;
|
|
378
|
+
}
|
|
379
|
+
},
|
|
380
|
+
onError: (error2) => {
|
|
381
|
+
console.error(`Chat message subscription error for channel ${channel == null ? void 0 : channel.id}:`, error2);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
} })))
|
|
385
|
+
);
|
|
488
386
|
};
|
|
489
387
|
const ServiceDialogsListItem = React__default.memo(ServiceDialogsListItemComponent);export{ServiceDialogsListItem,ServiceDialogsListItemComponent};//# sourceMappingURL=ServiceDialogsListItem.js.map
|