@blocklet/discuss-kit-ux 2.3.61 → 2.3.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/chat/hooks.d.ts +4 -1
- package/dist/components/chat/unread-notification.d.ts +5 -2
- package/dist/{editor-Y6zGiG3X.mjs → editor-DcVbeMRW.mjs} +1 -1
- package/dist/{index-BPktVpJK.mjs → index-CM3uCkTS.mjs} +51 -39
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +49 -37
- package/package.json +3 -3
|
@@ -7,6 +7,9 @@ export declare const useChatInWallet: () => {
|
|
|
7
7
|
isChatInWalletV2: boolean;
|
|
8
8
|
isWebNavbar: boolean;
|
|
9
9
|
isInArcSphere: boolean;
|
|
10
|
-
updateUnreadState: (unread
|
|
10
|
+
updateUnreadState: ({ unread, unreadMessageCount }: {
|
|
11
|
+
unread: boolean;
|
|
12
|
+
unreadMessageCount: number;
|
|
13
|
+
}) => void;
|
|
11
14
|
chatInWallet: import('react-router-dom').PathMatch<"chatId"> | null;
|
|
12
15
|
};
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
2
|
interface UnreadNotificationProviderProps {
|
|
3
|
-
fetchUnreadState: () => Promise<
|
|
3
|
+
fetchUnreadState: () => Promise<Record<string, number>>;
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
}
|
|
6
6
|
interface UnreadNotificationContextType {
|
|
7
7
|
unread: boolean | undefined;
|
|
8
|
-
|
|
8
|
+
chatUnreadCounts: Record<string, number>;
|
|
9
|
+
incrementUnreadCount: (chatId: string, count: number) => void;
|
|
10
|
+
markChatAsRead: (chatId: string) => void;
|
|
11
|
+
unreadMessageCount: number;
|
|
9
12
|
}
|
|
10
13
|
export declare const UnreadNotificationContext: import('react').Context<UnreadNotificationContextType>;
|
|
11
14
|
export declare const useUnreadNotification: () => UnreadNotificationContextType;
|
|
@@ -4,7 +4,7 @@ import { OnContentChangePlugin } from "@blocklet/editor/lib/ext/OnContentChangeP
|
|
|
4
4
|
import { CtrlsShortcutPlugin } from "@blocklet/editor/lib/ext/ShortcutPlugin";
|
|
5
5
|
import { SafeAreaPlugin } from "@blocklet/editor/lib/ext/SafeAreaPlugin";
|
|
6
6
|
import { lazyRetry } from "@arcblock/ux/lib/Util";
|
|
7
|
-
import { i as inferInitialEditorState, I as ImagePathFixerPlugin, V as VideoPathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-
|
|
7
|
+
import { i as inferInitialEditorState, I as ImagePathFixerPlugin, V as VideoPathFixerPlugin, a as isEmptyContent, s as stringify, g as getExcerptSync } from "./index-CM3uCkTS.mjs";
|
|
8
8
|
const BlockletEditor = lazyRetry(() => import("@blocklet/editor"));
|
|
9
9
|
const Root = styled(Box)`
|
|
10
10
|
.be-editable,
|
|
@@ -7,7 +7,7 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
|
7
7
|
import { useTheme, ThemeProvider, styled as styled$2 } from "@mui/material/styles";
|
|
8
8
|
import { create as create$1, styled } from "@arcblock/ux/lib/Theme";
|
|
9
9
|
import { useEffect, useRef, useState, createElement, useContext, useMemo, useLayoutEffect, useCallback, isValidElement, Suspense, createContext, Fragment as Fragment$1, forwardRef, useImperativeHandle } from "react";
|
|
10
|
-
import { Box, useTheme as useTheme$1, useMediaQuery, styled as styled$1, Button as Button$1, Stack as Stack$1, Dialog, DialogTitle, DialogContent, DialogActions, DialogContentText, IconButton as IconButton$3, Tooltip as Tooltip$1, Chip as Chip$1, alpha, ClickAwayListener, Divider, Skeleton, InputBase, tooltipClasses as tooltipClasses$1, CircularProgress, Backdrop, Autocomplete, Typography as Typography$1, TextField, InputAdornment, SwipeableDrawer,
|
|
10
|
+
import { Box, useTheme as useTheme$1, useMediaQuery, styled as styled$1, Button as Button$1, Stack as Stack$1, Dialog, DialogTitle, DialogContent, DialogActions, DialogContentText, IconButton as IconButton$3, Tooltip as Tooltip$1, Chip as Chip$1, alpha, ClickAwayListener, Divider, Skeleton, InputBase, Badge as Badge$1, tooltipClasses as tooltipClasses$1, CircularProgress, Backdrop, Autocomplete, Typography as Typography$1, TextField, InputAdornment, SwipeableDrawer, ToggleButtonGroup, ToggleButton } from "@mui/material";
|
|
11
11
|
import isNil from "lodash/isNil";
|
|
12
12
|
import { useEditorConfig, EditorConfigProvider } from "@blocklet/editor/lib/config";
|
|
13
13
|
import { lazyWithPreload } from "react-lazy-with-preload";
|
|
@@ -1220,9 +1220,17 @@ const useChatInWallet = () => {
|
|
|
1220
1220
|
const navigateToChatList = () => {
|
|
1221
1221
|
navigate("/chat-in-wallet");
|
|
1222
1222
|
};
|
|
1223
|
-
const updateUnreadState = useCallback(
|
|
1224
|
-
|
|
1225
|
-
|
|
1223
|
+
const updateUnreadState = useCallback(
|
|
1224
|
+
({ unread, unreadMessageCount }) => {
|
|
1225
|
+
bridge.call("updateUnreadState", {
|
|
1226
|
+
unread,
|
|
1227
|
+
unreadMessageCount,
|
|
1228
|
+
appId: window.blocklet.appPid,
|
|
1229
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
1230
|
+
});
|
|
1231
|
+
},
|
|
1232
|
+
[]
|
|
1233
|
+
);
|
|
1226
1234
|
return {
|
|
1227
1235
|
navigateToChat,
|
|
1228
1236
|
navigateToChatList,
|
|
@@ -3930,11 +3938,21 @@ const UnreadNotificationContext = createContext(
|
|
|
3930
3938
|
const useUnreadNotification = () => useContext(UnreadNotificationContext);
|
|
3931
3939
|
function UnreadNotificationProvider({ fetchUnreadState, children }) {
|
|
3932
3940
|
const { session } = useSessionContext();
|
|
3933
|
-
const [
|
|
3934
|
-
const
|
|
3941
|
+
const [chatUnreadCounts, setChatUnreadCounts] = useState({});
|
|
3942
|
+
const unread = useMemo(() => Object.values(chatUnreadCounts).some((x) => x > 0), [chatUnreadCounts]);
|
|
3943
|
+
const unreadMessageCount = useMemo(
|
|
3944
|
+
() => Object.values(chatUnreadCounts).reduce((acc, x) => acc + x, 0),
|
|
3945
|
+
[chatUnreadCounts]
|
|
3946
|
+
);
|
|
3947
|
+
const incrementUnreadCount = useCallback((chatId, count) => {
|
|
3948
|
+
setChatUnreadCounts((prev) => ({ ...prev, [chatId]: (prev[chatId] || 0) + count }));
|
|
3949
|
+
}, []);
|
|
3950
|
+
const markChatAsRead = useCallback((chatId) => {
|
|
3951
|
+
setChatUnreadCounts((prev) => ({ ...prev, [chatId]: 0 }));
|
|
3952
|
+
}, []);
|
|
3935
3953
|
const update = async () => {
|
|
3936
3954
|
const unreadState = await fetchUnreadState();
|
|
3937
|
-
|
|
3955
|
+
setChatUnreadCounts(unreadState);
|
|
3938
3956
|
};
|
|
3939
3957
|
useEffect(() => {
|
|
3940
3958
|
if (session.user && preferences.enableNotificationBadge && preferences.chatEnabled) {
|
|
@@ -3944,10 +3962,12 @@ function UnreadNotificationProvider({ fetchUnreadState, children }) {
|
|
|
3944
3962
|
const value = useMemo(
|
|
3945
3963
|
() => ({
|
|
3946
3964
|
unread,
|
|
3947
|
-
|
|
3965
|
+
chatUnreadCounts,
|
|
3966
|
+
unreadMessageCount,
|
|
3967
|
+
incrementUnreadCount,
|
|
3968
|
+
markChatAsRead
|
|
3948
3969
|
}),
|
|
3949
|
-
|
|
3950
|
-
[unread]
|
|
3970
|
+
[unread, chatUnreadCounts, unreadMessageCount, incrementUnreadCount, markChatAsRead]
|
|
3951
3971
|
);
|
|
3952
3972
|
return /* @__PURE__ */ jsx(UnreadNotificationContext.Provider, { value, children });
|
|
3953
3973
|
}
|
|
@@ -3973,7 +3993,7 @@ function ChatProvider({
|
|
|
3973
3993
|
editingChannel: null,
|
|
3974
3994
|
error: void 0
|
|
3975
3995
|
});
|
|
3976
|
-
const {
|
|
3996
|
+
const { incrementUnreadCount, markChatAsRead } = useUnreadNotification();
|
|
3977
3997
|
const navigate = useNavigate();
|
|
3978
3998
|
const { session } = useSessionContext();
|
|
3979
3999
|
const currentUser = session == null ? void 0 : session.user;
|
|
@@ -3986,10 +4006,6 @@ function ChatProvider({
|
|
|
3986
4006
|
}
|
|
3987
4007
|
return false;
|
|
3988
4008
|
};
|
|
3989
|
-
const hasAnyUnreadMessages = useMemo(
|
|
3990
|
-
() => state.chats.filter((chat) => chat.type !== "channel" || chat.hasJoined).some(hasUnreadMessages),
|
|
3991
|
-
[state.chats]
|
|
3992
|
-
);
|
|
3993
4009
|
const isActiveChat = (chatId) => state.activeChatId === chatId;
|
|
3994
4010
|
const updateChat = (chatId, mapper) => {
|
|
3995
4011
|
setState((prev) => {
|
|
@@ -4005,6 +4021,7 @@ function ChatProvider({
|
|
|
4005
4021
|
};
|
|
4006
4022
|
const updateLastAckTime = async (chatId, clientOnly) => {
|
|
4007
4023
|
updateChat(chatId, (chat) => ({ ...chat, lastAckTime: chat.lastMessageAt }));
|
|
4024
|
+
markChatAsRead(chatId);
|
|
4008
4025
|
if (!clientOnly) {
|
|
4009
4026
|
await client2.updateLastAckTime(chatId);
|
|
4010
4027
|
}
|
|
@@ -4192,6 +4209,8 @@ function ChatProvider({
|
|
|
4192
4209
|
updateLastAckTime(chatId, true);
|
|
4193
4210
|
} else if (isActiveChat(chatId)) {
|
|
4194
4211
|
updateLastAckTime(chatId);
|
|
4212
|
+
} else {
|
|
4213
|
+
incrementUnreadCount(chatId, 1);
|
|
4195
4214
|
}
|
|
4196
4215
|
}),
|
|
4197
4216
|
client2.onJoinChannel(({ chatId, participant }) => addParticipant(chatId, participant)),
|
|
@@ -4203,11 +4222,6 @@ function ChatProvider({
|
|
|
4203
4222
|
cancels.forEach((cancel) => cancel == null ? void 0 : cancel());
|
|
4204
4223
|
};
|
|
4205
4224
|
}, [state]);
|
|
4206
|
-
useEffect(() => {
|
|
4207
|
-
if (state.initialized) {
|
|
4208
|
-
markAsUnread(hasAnyUnreadMessages);
|
|
4209
|
-
}
|
|
4210
|
-
}, [state.initialized, hasAnyUnreadMessages, markAsUnread]);
|
|
4211
4225
|
const value = useMemo(() => {
|
|
4212
4226
|
return {
|
|
4213
4227
|
...state,
|
|
@@ -4272,7 +4286,8 @@ function ChannelGroup({ size = "normal", chat, children, ...rest }) {
|
|
|
4272
4286
|
}
|
|
4273
4287
|
function ChatList({ inWallet, ...rest }) {
|
|
4274
4288
|
const { t } = useLocaleContext();
|
|
4275
|
-
const { orderedChats, activeChatId, setActiveChat, getOppositeUser,
|
|
4289
|
+
const { orderedChats, activeChatId, setActiveChat, getOppositeUser, getLastMessageText } = useChatContext();
|
|
4290
|
+
const { chatUnreadCounts } = useUnreadNotification();
|
|
4276
4291
|
const { navigateToChat } = useChatInWallet();
|
|
4277
4292
|
const renderItem = (chat) => {
|
|
4278
4293
|
if (chat.type === "notification") {
|
|
@@ -4306,7 +4321,7 @@ function ChatList({ inWallet, ...rest }) {
|
|
|
4306
4321
|
};
|
|
4307
4322
|
return /* @__PURE__ */ jsx(Box$1, { ...rest, children: /* @__PURE__ */ jsx(Flipper, { flipKey: orderedChats.map((x) => x.id).join(""), children: orderedChats.map((chat) => {
|
|
4308
4323
|
const isActiveChat = activeChatId === chat.id;
|
|
4309
|
-
const
|
|
4324
|
+
const unreadCount = chatUnreadCounts[chat.id];
|
|
4310
4325
|
return /* @__PURE__ */ jsx(Flipped, { flipId: chat.id, children: /* @__PURE__ */ jsxs(
|
|
4311
4326
|
Box$1,
|
|
4312
4327
|
{
|
|
@@ -4351,19 +4366,18 @@ function ChatList({ inWallet, ...rest }) {
|
|
|
4351
4366
|
},
|
|
4352
4367
|
children: [
|
|
4353
4368
|
renderItem(chat),
|
|
4354
|
-
|
|
4355
|
-
|
|
4369
|
+
unreadCount > 0 && /* @__PURE__ */ jsx(
|
|
4370
|
+
Badge$1,
|
|
4356
4371
|
{
|
|
4372
|
+
badgeContent: unreadCount,
|
|
4373
|
+
color: "primary",
|
|
4357
4374
|
sx: {
|
|
4358
4375
|
position: "absolute",
|
|
4359
4376
|
top: "50%",
|
|
4360
|
-
right: 16,
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
bgcolor: "error.light",
|
|
4365
|
-
borderRadius: "100%"
|
|
4366
|
-
}
|
|
4377
|
+
right: { xs: 28, md: 16 },
|
|
4378
|
+
transform: "translateY(-50%)"
|
|
4379
|
+
},
|
|
4380
|
+
children: /* @__PURE__ */ jsx(Box$1, { sx: { width: 1, height: 1 } })
|
|
4367
4381
|
}
|
|
4368
4382
|
)
|
|
4369
4383
|
]
|
|
@@ -4954,7 +4968,7 @@ function Back({ url, fallbackUrl, iconOnly, sx, icon, ...rest }) {
|
|
|
4954
4968
|
}
|
|
4955
4969
|
const tablerSend = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M10 14L21 3m0 0l-6.5 18a.55.55 0 0 1-1 0L10 14l-7-3.5a.55.55 0 0 1 0-1z" }) });
|
|
4956
4970
|
const tablerLetterCase = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M14 15.5a3.5 3.5 0 1 0 7 0a3.5 3.5 0 1 0-7 0M3 19V8.5a3.5 3.5 0 0 1 7 0V19m-7-6h7m11-1v7" }) });
|
|
4957
|
-
const Editor = lazyRetry(() => import("./editor-
|
|
4971
|
+
const Editor = lazyRetry(() => import("./editor-DcVbeMRW.mjs"));
|
|
4958
4972
|
function LazyEditor(props) {
|
|
4959
4973
|
const fallback2 = /* @__PURE__ */ jsxs(Box, { sx: { px: 3 }, children: [
|
|
4960
4974
|
/* @__PURE__ */ jsx(Skeleton, {}),
|
|
@@ -5826,13 +5840,11 @@ function ChatListInWallet({ sx, ...rest }) {
|
|
|
5826
5840
|
var _a2, _b2, _c2, _d2;
|
|
5827
5841
|
const { session } = useSessionContext();
|
|
5828
5842
|
const { initialized, chats, activeChatId } = useChatContext();
|
|
5829
|
-
const {
|
|
5843
|
+
const { unreadMessageCount } = useUnreadNotification();
|
|
5830
5844
|
const { navigateToChatList, updateUnreadState, isWebNavbar } = useChatInWallet();
|
|
5831
5845
|
useEffect(() => {
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
}
|
|
5835
|
-
}, [unread, updateUnreadState]);
|
|
5846
|
+
updateUnreadState({ unread: unreadMessageCount > 0, unreadMessageCount });
|
|
5847
|
+
}, [unreadMessageCount, updateUnreadState]);
|
|
5836
5848
|
if (!initialized) {
|
|
5837
5849
|
return /* @__PURE__ */ jsx(Backdrop, { open: true, sx: { zIndex: (theme) => theme.zIndex.drawer + 1, bgcolor: "transparent" }, children: /* @__PURE__ */ jsx(CircularProgress$1, {}) });
|
|
5838
5850
|
}
|
|
@@ -5934,7 +5946,7 @@ function ChatListInWallet({ sx, ...rest }) {
|
|
|
5934
5946
|
}
|
|
5935
5947
|
const tablerMessageCircle = (props) => /* @__PURE__ */ jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "m3 20l1.3-3.9C1.976 12.663 2.874 8.228 6.4 5.726c3.526-2.501 8.59-2.296 11.845.48c3.255 2.777 3.695 7.266 1.029 10.501S11.659 20.922 7.7 19z" }) });
|
|
5936
5948
|
function ChatHeaderAddon({ ...rest }) {
|
|
5937
|
-
const { unread } = useUnreadNotification();
|
|
5949
|
+
const { unread, unreadMessageCount } = useUnreadNotification();
|
|
5938
5950
|
if (!preferences.enableNotificationBadge || !preferences.chatEnabled) {
|
|
5939
5951
|
return null;
|
|
5940
5952
|
}
|
|
@@ -5942,7 +5954,7 @@ function ChatHeaderAddon({ ...rest }) {
|
|
|
5942
5954
|
AddonButton,
|
|
5943
5955
|
{
|
|
5944
5956
|
size: "medium",
|
|
5945
|
-
icon: /* @__PURE__ */ jsx(Badge$1, { color: "error",
|
|
5957
|
+
icon: /* @__PURE__ */ jsx(Badge$1, { color: "error", invisible: !unread, badgeContent: unreadMessageCount, children: /* @__PURE__ */ jsx(tablerMessageCircle, {}) }),
|
|
5946
5958
|
...rest,
|
|
5947
5959
|
component: Link,
|
|
5948
5960
|
to: "/chat"
|
package/dist/index.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from "@blocklet/labels";
|
|
2
|
-
import { W, o, Y, A, n, af, B, G, N, L, O, ar, _, Z, a1, $, a0, a3, x, C, y, z, F, a7, a8, aj, aa, T, U, ae, D, ai, ah, K, H, J, aG, aH, b, m, ag, M, P, aC, aq, w, v, aE, aF, R, S, ab, as, aD, q, a4, a6, ak, an, am, aA, at, Q, ao, au, ax, ay, l, az, h, p, r, k, aw, t, j, ac, aB, X, c, a2, E, a9, ad, e, u, ap, d, av, a5, al, f } from "./index-
|
|
2
|
+
import { W, o, Y, A, n, af, B, G, N, L, O, ar, _, Z, a1, $, a0, a3, x, C, y, z, F, a7, a8, aj, aa, T, U, ae, D, ai, ah, K, H, J, aG, aH, b, m, ag, M, P, aC, aq, w, v, aE, aF, R, S, ab, as, aD, q, a4, a6, ak, an, am, aA, at, Q, ao, au, ax, ay, l, az, h, p, r, k, aw, t, j, ac, aB, X, c, a2, E, a9, ad, e, u, ap, d, av, a5, al, f } from "./index-CM3uCkTS.mjs";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
5
|
import "@mui/material/Box";
|
package/dist/index.umd.js
CHANGED
|
@@ -1142,9 +1142,17 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1142
1142
|
const navigateToChatList = () => {
|
|
1143
1143
|
navigate("/chat-in-wallet");
|
|
1144
1144
|
};
|
|
1145
|
-
const updateUnreadState = react.useCallback(
|
|
1146
|
-
|
|
1147
|
-
|
|
1145
|
+
const updateUnreadState = react.useCallback(
|
|
1146
|
+
({ unread, unreadMessageCount }) => {
|
|
1147
|
+
bridge.call("updateUnreadState", {
|
|
1148
|
+
unread,
|
|
1149
|
+
unreadMessageCount,
|
|
1150
|
+
appId: window.blocklet.appPid,
|
|
1151
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
1152
|
+
});
|
|
1153
|
+
},
|
|
1154
|
+
[]
|
|
1155
|
+
);
|
|
1148
1156
|
return {
|
|
1149
1157
|
navigateToChat,
|
|
1150
1158
|
navigateToChatList,
|
|
@@ -3852,11 +3860,21 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3852
3860
|
const useUnreadNotification = () => react.useContext(UnreadNotificationContext);
|
|
3853
3861
|
function UnreadNotificationProvider({ fetchUnreadState, children }) {
|
|
3854
3862
|
const { session } = useSessionContext();
|
|
3855
|
-
const [
|
|
3856
|
-
const
|
|
3863
|
+
const [chatUnreadCounts, setChatUnreadCounts] = react.useState({});
|
|
3864
|
+
const unread = react.useMemo(() => Object.values(chatUnreadCounts).some((x) => x > 0), [chatUnreadCounts]);
|
|
3865
|
+
const unreadMessageCount = react.useMemo(
|
|
3866
|
+
() => Object.values(chatUnreadCounts).reduce((acc, x) => acc + x, 0),
|
|
3867
|
+
[chatUnreadCounts]
|
|
3868
|
+
);
|
|
3869
|
+
const incrementUnreadCount = react.useCallback((chatId, count) => {
|
|
3870
|
+
setChatUnreadCounts((prev) => ({ ...prev, [chatId]: (prev[chatId] || 0) + count }));
|
|
3871
|
+
}, []);
|
|
3872
|
+
const markChatAsRead = react.useCallback((chatId) => {
|
|
3873
|
+
setChatUnreadCounts((prev) => ({ ...prev, [chatId]: 0 }));
|
|
3874
|
+
}, []);
|
|
3857
3875
|
const update = async () => {
|
|
3858
3876
|
const unreadState = await fetchUnreadState();
|
|
3859
|
-
|
|
3877
|
+
setChatUnreadCounts(unreadState);
|
|
3860
3878
|
};
|
|
3861
3879
|
react.useEffect(() => {
|
|
3862
3880
|
if (session.user && preferences.enableNotificationBadge && preferences.chatEnabled) {
|
|
@@ -3866,10 +3884,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3866
3884
|
const value = react.useMemo(
|
|
3867
3885
|
() => ({
|
|
3868
3886
|
unread,
|
|
3869
|
-
|
|
3887
|
+
chatUnreadCounts,
|
|
3888
|
+
unreadMessageCount,
|
|
3889
|
+
incrementUnreadCount,
|
|
3890
|
+
markChatAsRead
|
|
3870
3891
|
}),
|
|
3871
|
-
|
|
3872
|
-
[unread]
|
|
3892
|
+
[unread, chatUnreadCounts, unreadMessageCount, incrementUnreadCount, markChatAsRead]
|
|
3873
3893
|
);
|
|
3874
3894
|
return /* @__PURE__ */ jsxRuntime.jsx(UnreadNotificationContext.Provider, { value, children });
|
|
3875
3895
|
}
|
|
@@ -3895,7 +3915,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3895
3915
|
editingChannel: null,
|
|
3896
3916
|
error: void 0
|
|
3897
3917
|
});
|
|
3898
|
-
const {
|
|
3918
|
+
const { incrementUnreadCount, markChatAsRead } = useUnreadNotification();
|
|
3899
3919
|
const navigate = reactRouterDom.useNavigate();
|
|
3900
3920
|
const { session } = useSessionContext();
|
|
3901
3921
|
const currentUser = session == null ? void 0 : session.user;
|
|
@@ -3908,10 +3928,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3908
3928
|
}
|
|
3909
3929
|
return false;
|
|
3910
3930
|
};
|
|
3911
|
-
const hasAnyUnreadMessages = react.useMemo(
|
|
3912
|
-
() => state.chats.filter((chat) => chat.type !== "channel" || chat.hasJoined).some(hasUnreadMessages),
|
|
3913
|
-
[state.chats]
|
|
3914
|
-
);
|
|
3915
3931
|
const isActiveChat = (chatId) => state.activeChatId === chatId;
|
|
3916
3932
|
const updateChat = (chatId, mapper) => {
|
|
3917
3933
|
setState((prev) => {
|
|
@@ -3927,6 +3943,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3927
3943
|
};
|
|
3928
3944
|
const updateLastAckTime = async (chatId, clientOnly) => {
|
|
3929
3945
|
updateChat(chatId, (chat) => ({ ...chat, lastAckTime: chat.lastMessageAt }));
|
|
3946
|
+
markChatAsRead(chatId);
|
|
3930
3947
|
if (!clientOnly) {
|
|
3931
3948
|
await client2.updateLastAckTime(chatId);
|
|
3932
3949
|
}
|
|
@@ -4114,6 +4131,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4114
4131
|
updateLastAckTime(chatId, true);
|
|
4115
4132
|
} else if (isActiveChat(chatId)) {
|
|
4116
4133
|
updateLastAckTime(chatId);
|
|
4134
|
+
} else {
|
|
4135
|
+
incrementUnreadCount(chatId, 1);
|
|
4117
4136
|
}
|
|
4118
4137
|
}),
|
|
4119
4138
|
client2.onJoinChannel(({ chatId, participant }) => addParticipant(chatId, participant)),
|
|
@@ -4125,11 +4144,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4125
4144
|
cancels.forEach((cancel) => cancel == null ? void 0 : cancel());
|
|
4126
4145
|
};
|
|
4127
4146
|
}, [state]);
|
|
4128
|
-
react.useEffect(() => {
|
|
4129
|
-
if (state.initialized) {
|
|
4130
|
-
markAsUnread(hasAnyUnreadMessages);
|
|
4131
|
-
}
|
|
4132
|
-
}, [state.initialized, hasAnyUnreadMessages, markAsUnread]);
|
|
4133
4147
|
const value = react.useMemo(() => {
|
|
4134
4148
|
return {
|
|
4135
4149
|
...state,
|
|
@@ -4194,7 +4208,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4194
4208
|
}
|
|
4195
4209
|
function ChatList({ inWallet, ...rest }) {
|
|
4196
4210
|
const { t } = context.useLocaleContext();
|
|
4197
|
-
const { orderedChats, activeChatId, setActiveChat, getOppositeUser,
|
|
4211
|
+
const { orderedChats, activeChatId, setActiveChat, getOppositeUser, getLastMessageText } = useChatContext();
|
|
4212
|
+
const { chatUnreadCounts } = useUnreadNotification();
|
|
4198
4213
|
const { navigateToChat } = useChatInWallet();
|
|
4199
4214
|
const renderItem = (chat) => {
|
|
4200
4215
|
if (chat.type === "notification") {
|
|
@@ -4228,7 +4243,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4228
4243
|
};
|
|
4229
4244
|
return /* @__PURE__ */ jsxRuntime.jsx(Box, { ...rest, children: /* @__PURE__ */ jsxRuntime.jsx(reactFlipToolkit.Flipper, { flipKey: orderedChats.map((x) => x.id).join(""), children: orderedChats.map((chat) => {
|
|
4230
4245
|
const isActiveChat = activeChatId === chat.id;
|
|
4231
|
-
const
|
|
4246
|
+
const unreadCount = chatUnreadCounts[chat.id];
|
|
4232
4247
|
return /* @__PURE__ */ jsxRuntime.jsx(reactFlipToolkit.Flipped, { flipId: chat.id, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4233
4248
|
Box,
|
|
4234
4249
|
{
|
|
@@ -4273,19 +4288,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4273
4288
|
},
|
|
4274
4289
|
children: [
|
|
4275
4290
|
renderItem(chat),
|
|
4276
|
-
|
|
4277
|
-
|
|
4291
|
+
unreadCount > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4292
|
+
material.Badge,
|
|
4278
4293
|
{
|
|
4294
|
+
badgeContent: unreadCount,
|
|
4295
|
+
color: "primary",
|
|
4279
4296
|
sx: {
|
|
4280
4297
|
position: "absolute",
|
|
4281
4298
|
top: "50%",
|
|
4282
|
-
right: 16,
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
bgcolor: "error.light",
|
|
4287
|
-
borderRadius: "100%"
|
|
4288
|
-
}
|
|
4299
|
+
right: { xs: 28, md: 16 },
|
|
4300
|
+
transform: "translateY(-50%)"
|
|
4301
|
+
},
|
|
4302
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Box, { sx: { width: 1, height: 1 } })
|
|
4289
4303
|
}
|
|
4290
4304
|
)
|
|
4291
4305
|
]
|
|
@@ -5748,13 +5762,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5748
5762
|
var _a2, _b2, _c2, _d2;
|
|
5749
5763
|
const { session } = useSessionContext();
|
|
5750
5764
|
const { initialized, chats, activeChatId } = useChatContext();
|
|
5751
|
-
const {
|
|
5765
|
+
const { unreadMessageCount } = useUnreadNotification();
|
|
5752
5766
|
const { navigateToChatList, updateUnreadState, isWebNavbar } = useChatInWallet();
|
|
5753
5767
|
react.useEffect(() => {
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
}
|
|
5757
|
-
}, [unread, updateUnreadState]);
|
|
5768
|
+
updateUnreadState({ unread: unreadMessageCount > 0, unreadMessageCount });
|
|
5769
|
+
}, [unreadMessageCount, updateUnreadState]);
|
|
5758
5770
|
if (!initialized) {
|
|
5759
5771
|
return /* @__PURE__ */ jsxRuntime.jsx(material.Backdrop, { open: true, sx: { zIndex: (theme) => theme.zIndex.drawer + 1, bgcolor: "transparent" }, children: /* @__PURE__ */ jsxRuntime.jsx(CircularProgress, {}) });
|
|
5760
5772
|
}
|
|
@@ -5856,7 +5868,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5856
5868
|
}
|
|
5857
5869
|
const tablerMessageCircle = (props) => /* @__PURE__ */ jsxRuntime.jsx("svg", { viewBox: "0 0 24 24", width: "1.2em", height: "1.2em", ...props, children: /* @__PURE__ */ jsxRuntime.jsx("path", { fill: "none", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "m3 20l1.3-3.9C1.976 12.663 2.874 8.228 6.4 5.726c3.526-2.501 8.59-2.296 11.845.48c3.255 2.777 3.695 7.266 1.029 10.501S11.659 20.922 7.7 19z" }) });
|
|
5858
5870
|
function ChatHeaderAddon({ ...rest }) {
|
|
5859
|
-
const { unread } = useUnreadNotification();
|
|
5871
|
+
const { unread, unreadMessageCount } = useUnreadNotification();
|
|
5860
5872
|
if (!preferences.enableNotificationBadge || !preferences.chatEnabled) {
|
|
5861
5873
|
return null;
|
|
5862
5874
|
}
|
|
@@ -5864,7 +5876,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5864
5876
|
addonButton.AddonButton,
|
|
5865
5877
|
{
|
|
5866
5878
|
size: "medium",
|
|
5867
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(material.Badge, { color: "error",
|
|
5879
|
+
icon: /* @__PURE__ */ jsxRuntime.jsx(material.Badge, { color: "error", invisible: !unread, badgeContent: unreadMessageCount, children: /* @__PURE__ */ jsxRuntime.jsx(tablerMessageCircle, {}) }),
|
|
5868
5880
|
...rest,
|
|
5869
5881
|
component: reactRouterDom.Link,
|
|
5870
5882
|
to: "/chat"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blocklet/discuss-kit-ux",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.63",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"ufo": "^1.5.4",
|
|
46
46
|
"unstated-next": "^1.1.0",
|
|
47
47
|
"url-join": "^4.0.1",
|
|
48
|
-
"@blocklet/editor": "^2.3.
|
|
49
|
-
"@blocklet/labels": "^2.3.
|
|
48
|
+
"@blocklet/editor": "^2.3.63",
|
|
49
|
+
"@blocklet/labels": "^2.3.63"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@arcblock/did-connect": "^2.10.36",
|