@ermis-network/ermis-chat-react 1.0.6 → 1.0.8
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/index.cjs +3802 -1772
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +836 -25
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +304 -1
- package/dist/index.d.ts +304 -1
- package/dist/index.mjs +3755 -1761
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/channelRoleUtils.ts +73 -0
- package/src/channelTypeUtils.ts +46 -0
- package/src/components/Avatar.tsx +57 -31
- package/src/components/BannedOverlay.tsx +40 -0
- package/src/components/ChannelActions.tsx +233 -0
- package/src/components/ChannelHeader.tsx +126 -5
- package/src/components/ChannelInfo/ChannelInfo.tsx +128 -24
- package/src/components/ChannelInfo/ChannelInfoTabs.tsx +67 -28
- package/src/components/ChannelInfo/ChannelSettingsPanel.tsx +90 -1
- package/src/components/ChannelInfo/EditChannelModal.tsx +5 -4
- package/src/components/ChannelInfo/MemberListItem.tsx +2 -1
- package/src/components/ChannelList.tsx +514 -47
- package/src/components/ClosedTopicOverlay.tsx +38 -0
- package/src/components/CreateChannelModal.tsx +53 -16
- package/src/components/EditPreview.tsx +2 -1
- package/src/components/ForwardMessageModal.tsx +2 -1
- package/src/components/MediaLightbox.tsx +314 -0
- package/src/components/MessageInput.tsx +21 -3
- package/src/components/MessageItem.tsx +10 -12
- package/src/components/MessageQuickReactions.tsx +3 -2
- package/src/components/MessageReactions.tsx +8 -3
- package/src/components/MessageRenderers.tsx +174 -54
- package/src/components/PendingOverlay.tsx +51 -0
- package/src/components/PinnedMessages.tsx +2 -1
- package/src/components/ReplyPreview.tsx +2 -1
- package/src/components/SkippedOverlay.tsx +36 -0
- package/src/components/TopicModal.tsx +189 -0
- package/src/components/UserPicker.tsx +1 -1
- package/src/components/VirtualMessageList.tsx +162 -47
- package/src/hooks/useBannedState.ts +27 -3
- package/src/hooks/useBlockedState.ts +3 -2
- package/src/hooks/useChannelCapabilities.ts +10 -8
- package/src/hooks/useChannelData.ts +1 -1
- package/src/hooks/useChannelListUpdates.ts +28 -5
- package/src/hooks/useChannelMessages.ts +2 -3
- package/src/hooks/useChannelRowUpdates.ts +9 -2
- package/src/hooks/useMessageActions.ts +23 -9
- package/src/hooks/useOnlineStatus.ts +71 -0
- package/src/hooks/useOnlineUsers.ts +115 -0
- package/src/hooks/usePendingState.ts +8 -3
- package/src/index.ts +67 -10
- package/src/messageTypeUtils.ts +64 -0
- package/src/styles/_channel-info.css +21 -0
- package/src/styles/_channel-list.css +276 -6
- package/src/styles/_media-lightbox.css +263 -0
- package/src/styles/_message-bubble.css +170 -13
- package/src/styles/_message-input.css +24 -0
- package/src/styles/_message-list.css +76 -6
- package/src/styles/_message-quick-reactions.css +5 -0
- package/src/styles/_message-reactions.css +7 -0
- package/src/styles/_topic-modal.css +154 -0
- package/src/styles/index.css +2 -0
- package/src/types.ts +203 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
import type { Channel, Event } from '@ermis-network/ermis-chat-sdk';
|
|
3
|
+
import { useChatClient } from './useChatClient';
|
|
4
|
+
import { isFriendChannel } from '../channelRoleUtils';
|
|
5
|
+
|
|
6
|
+
export type OnlineStatus = 'online' | 'offline' | 'unknown';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook that returns the online/offline status of a specific user.
|
|
10
|
+
*
|
|
11
|
+
* The status is determined by checking `channel.state.watchers` on the
|
|
12
|
+
* "friend" channel (direct channel where both members have `owner` role).
|
|
13
|
+
* Real-time updates are received via `user.watching.start` and
|
|
14
|
+
* `user.watching.stop` WebSocket events on that channel.
|
|
15
|
+
*
|
|
16
|
+
* Returns `'unknown'` if the user is not a friend (no qualifying channel found).
|
|
17
|
+
*
|
|
18
|
+
* @param userId – The user ID to check the online status of.
|
|
19
|
+
* @param channels – The full list of loaded channels (from ChannelList).
|
|
20
|
+
*/
|
|
21
|
+
export function useOnlineStatus(
|
|
22
|
+
userId: string | undefined,
|
|
23
|
+
channels: Channel[],
|
|
24
|
+
): OnlineStatus {
|
|
25
|
+
const { client } = useChatClient();
|
|
26
|
+
const currentUserId = client.userID;
|
|
27
|
+
|
|
28
|
+
// Find the friend channel for this user — memoized to avoid re-scans.
|
|
29
|
+
const friendChannel = useMemo(() => {
|
|
30
|
+
if (!userId || !currentUserId || userId === currentUserId) return null;
|
|
31
|
+
return channels.find((ch) => isFriendChannel(ch, userId, currentUserId)) || null;
|
|
32
|
+
}, [channels, userId, currentUserId]);
|
|
33
|
+
|
|
34
|
+
// Derive initial status from watchers state.
|
|
35
|
+
const [status, setStatus] = useState<OnlineStatus>(() => {
|
|
36
|
+
if (!friendChannel || !userId) return 'unknown';
|
|
37
|
+
return friendChannel.state?.watchers?.[userId] ? 'online' : 'offline';
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (!friendChannel || !userId) {
|
|
42
|
+
setStatus('unknown');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Sync initial state (in case friendChannel ref changed).
|
|
47
|
+
setStatus(friendChannel.state?.watchers?.[userId] ? 'online' : 'offline');
|
|
48
|
+
|
|
49
|
+
const handleWatchingStart = (event: Event) => {
|
|
50
|
+
if (event.user?.id === userId) {
|
|
51
|
+
setStatus('online');
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const handleWatchingStop = (event: Event) => {
|
|
56
|
+
if (event.user?.id === userId) {
|
|
57
|
+
setStatus('offline');
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const sub1 = friendChannel.on('user.watching.start', handleWatchingStart);
|
|
62
|
+
const sub2 = friendChannel.on('user.watching.stop', handleWatchingStop);
|
|
63
|
+
|
|
64
|
+
return () => {
|
|
65
|
+
sub1.unsubscribe();
|
|
66
|
+
sub2.unsubscribe();
|
|
67
|
+
};
|
|
68
|
+
}, [friendChannel, userId]);
|
|
69
|
+
|
|
70
|
+
return status;
|
|
71
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo, useRef } from 'react';
|
|
2
|
+
import type { Channel, Event } from '@ermis-network/ermis-chat-sdk';
|
|
3
|
+
import { useChatClient } from './useChatClient';
|
|
4
|
+
import { isFriendChannel } from '../channelRoleUtils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bulk hook that returns a `Set<string>` of user IDs that are currently online.
|
|
8
|
+
*
|
|
9
|
+
* Only users who are "friends" (exist in a direct channel where both
|
|
10
|
+
* members have `owner` role) are tracked. The status is derived from
|
|
11
|
+
* `channel.state.watchers` and kept in sync via `user.watching.start`
|
|
12
|
+
* and `user.watching.stop` WebSocket events at the **client** level
|
|
13
|
+
* for efficiency (single subscription instead of N per-channel ones).
|
|
14
|
+
*
|
|
15
|
+
* Usage in ChannelList: `const onlineUsers = useOnlineUsers(channels);`
|
|
16
|
+
* Then check: `onlineUsers.has(userId)`.
|
|
17
|
+
*
|
|
18
|
+
* @param channels – The full list of loaded channels (from ChannelList).
|
|
19
|
+
*/
|
|
20
|
+
export function useOnlineUsers(channels: Channel[]): Set<string> {
|
|
21
|
+
const { client } = useChatClient();
|
|
22
|
+
const currentUserId = client.userID;
|
|
23
|
+
|
|
24
|
+
// Build a map: friendUserId → Channel (the friend channel).
|
|
25
|
+
// This memoizes the friend channel lookup so we only iterate once per channels change.
|
|
26
|
+
const friendMap = useMemo(() => {
|
|
27
|
+
const map = new Map<string, Channel>();
|
|
28
|
+
if (!currentUserId) return map;
|
|
29
|
+
|
|
30
|
+
for (const ch of channels) {
|
|
31
|
+
const members = ch.state?.members;
|
|
32
|
+
if (!members) continue;
|
|
33
|
+
|
|
34
|
+
// Find the "other" user in this channel
|
|
35
|
+
for (const memberId of Object.keys(members)) {
|
|
36
|
+
if (memberId === currentUserId) continue;
|
|
37
|
+
if (isFriendChannel(ch, memberId, currentUserId)) {
|
|
38
|
+
map.set(memberId, ch);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}, [channels, currentUserId]);
|
|
44
|
+
|
|
45
|
+
// Compute the initial set of online users from watchers.
|
|
46
|
+
const computeOnlineSet = (): Set<string> => {
|
|
47
|
+
const set = new Set<string>();
|
|
48
|
+
for (const [userId, ch] of friendMap.entries()) {
|
|
49
|
+
if (ch.state?.watchers?.[userId]) {
|
|
50
|
+
set.add(userId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return set;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const [onlineUsers, setOnlineUsers] = useState<Set<string>>(() => computeOnlineSet());
|
|
57
|
+
|
|
58
|
+
// Keep friendMap in a ref so that event handlers always see the latest version.
|
|
59
|
+
const friendMapRef = useRef(friendMap);
|
|
60
|
+
friendMapRef.current = friendMap;
|
|
61
|
+
|
|
62
|
+
// Re-compute when friendMap changes (new channels loaded, channels array mutated).
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
setOnlineUsers(computeOnlineSet());
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [friendMap]);
|
|
67
|
+
|
|
68
|
+
// Subscribe at the client level for efficiency.
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!currentUserId) return;
|
|
71
|
+
|
|
72
|
+
const handleWatchingStart = (event: Event) => {
|
|
73
|
+
const userId = event.user?.id;
|
|
74
|
+
const eventCid = event.cid;
|
|
75
|
+
if (!userId || !eventCid) return;
|
|
76
|
+
|
|
77
|
+
// Check if this userId belongs to a tracked friend channel
|
|
78
|
+
const tracked = friendMapRef.current.get(userId);
|
|
79
|
+
if (tracked && tracked.cid === eventCid) {
|
|
80
|
+
setOnlineUsers((prev) => {
|
|
81
|
+
if (prev.has(userId)) return prev;
|
|
82
|
+
const next = new Set(prev);
|
|
83
|
+
next.add(userId);
|
|
84
|
+
return next;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const handleWatchingStop = (event: Event) => {
|
|
90
|
+
const userId = event.user?.id;
|
|
91
|
+
const eventCid = event.cid;
|
|
92
|
+
if (!userId || !eventCid) return;
|
|
93
|
+
|
|
94
|
+
const tracked = friendMapRef.current.get(userId);
|
|
95
|
+
if (tracked && tracked.cid === eventCid) {
|
|
96
|
+
setOnlineUsers((prev) => {
|
|
97
|
+
if (!prev.has(userId)) return prev;
|
|
98
|
+
const next = new Set(prev);
|
|
99
|
+
next.delete(userId);
|
|
100
|
+
return next;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const sub1 = client.on('user.watching.start', handleWatchingStart);
|
|
106
|
+
const sub2 = client.on('user.watching.stop', handleWatchingStop);
|
|
107
|
+
|
|
108
|
+
return () => {
|
|
109
|
+
sub1.unsubscribe();
|
|
110
|
+
sub2.unsubscribe();
|
|
111
|
+
};
|
|
112
|
+
}, [client, currentUserId]);
|
|
113
|
+
|
|
114
|
+
return onlineUsers;
|
|
115
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
2
|
import type { Channel } from '@ermis-network/ermis-chat-sdk';
|
|
3
|
+
import { isPendingMember } from '../channelRoleUtils';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Hook that tracks whether the current user is in a 'pending' state for the given channel.
|
|
@@ -7,7 +8,7 @@ import type { Channel } from '@ermis-network/ermis-chat-sdk';
|
|
|
7
8
|
export function usePendingState(channel: Channel | null | undefined, currentUserId?: string) {
|
|
8
9
|
const [isPending, setIsPending] = useState<boolean>(() => {
|
|
9
10
|
const membership = channel?.state?.membership || channel?.state?.members?.[currentUserId || ''];
|
|
10
|
-
return membership?.channel_role
|
|
11
|
+
return isPendingMember(membership?.channel_role as string);
|
|
11
12
|
});
|
|
12
13
|
|
|
13
14
|
useEffect(() => {
|
|
@@ -18,7 +19,7 @@ export function usePendingState(channel: Channel | null | undefined, currentUser
|
|
|
18
19
|
|
|
19
20
|
const checkPending = () => {
|
|
20
21
|
const membership = channel.state?.membership || channel.state?.members?.[currentUserId];
|
|
21
|
-
return membership?.channel_role
|
|
22
|
+
return isPendingMember(membership?.channel_role as string);
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
// Sync initial state
|
|
@@ -42,7 +43,9 @@ export function usePendingState(channel: Channel | null | undefined, currentUser
|
|
|
42
43
|
if (eventUserId !== currentUserId) return; // Only react to own invite events
|
|
43
44
|
|
|
44
45
|
const eventCid =
|
|
45
|
-
event.cid ||
|
|
46
|
+
event.cid ||
|
|
47
|
+
(event.channel as Record<string, unknown>)?.cid ||
|
|
48
|
+
(event.channel_id ? `${event.channel_type}:${event.channel_id}` : undefined);
|
|
46
49
|
if (eventCid === channel.cid) {
|
|
47
50
|
defensiveUpdateState(event);
|
|
48
51
|
setIsPending(checkPending());
|
|
@@ -52,10 +55,12 @@ export function usePendingState(channel: Channel | null | undefined, currentUser
|
|
|
52
55
|
const client = channel.getClient();
|
|
53
56
|
const sub1 = client.on('notification.invite_accepted', handleInviteAction);
|
|
54
57
|
const sub2 = client.on('notification.invite_rejected', handleInviteAction);
|
|
58
|
+
const sub3 = client.on('notification.invite_messaging_skipped', handleInviteAction);
|
|
55
59
|
|
|
56
60
|
return () => {
|
|
57
61
|
sub1.unsubscribe();
|
|
58
62
|
sub2.unsubscribe();
|
|
63
|
+
sub3.unsubscribe();
|
|
59
64
|
};
|
|
60
65
|
}, [channel, currentUserId]);
|
|
61
66
|
|
package/src/index.ts
CHANGED
|
@@ -13,15 +13,21 @@ export { useChannelListUpdates } from './hooks/useChannelListUpdates';
|
|
|
13
13
|
export { useChannelRowUpdates } from './hooks/useChannelRowUpdates';
|
|
14
14
|
export { useBannedState } from './hooks/useBannedState';
|
|
15
15
|
export { useBlockedState } from './hooks/useBlockedState';
|
|
16
|
+
export { useOnlineStatus } from './hooks/useOnlineStatus';
|
|
17
|
+
export type { OnlineStatus } from './hooks/useOnlineStatus';
|
|
18
|
+
export { useOnlineUsers } from './hooks/useOnlineUsers';
|
|
16
19
|
export { usePendingState } from './hooks/usePendingState';
|
|
17
20
|
|
|
18
21
|
// Components
|
|
19
22
|
export { Avatar } from './components/Avatar';
|
|
20
23
|
export type { AvatarProps } from './components/Avatar';
|
|
21
24
|
|
|
22
|
-
export { ChannelList, ChannelItem } from './components/ChannelList';
|
|
25
|
+
export { ChannelList, ChannelItem, ChannelTopicGroup } from './components/ChannelList';
|
|
23
26
|
export type { ChannelListProps, ChannelItemProps } from './components/ChannelList';
|
|
24
27
|
|
|
28
|
+
export { DefaultChannelActions, computeDefaultActions } from './components/ChannelActions';
|
|
29
|
+
export type { ChannelAction, ChannelActionsProps } from './types';
|
|
30
|
+
|
|
25
31
|
export { Channel } from './components/Channel';
|
|
26
32
|
export type { ChannelProps } from './components/Channel';
|
|
27
33
|
|
|
@@ -29,7 +35,14 @@ export { ChannelHeader } from './components/ChannelHeader';
|
|
|
29
35
|
export type { ChannelHeaderProps } from './components/ChannelHeader';
|
|
30
36
|
export type { ChannelHeaderData } from './types';
|
|
31
37
|
|
|
32
|
-
export type {
|
|
38
|
+
export type {
|
|
39
|
+
MessageListProps,
|
|
40
|
+
MessageBubbleProps,
|
|
41
|
+
MessageItemProps,
|
|
42
|
+
SystemMessageItemProps,
|
|
43
|
+
DateSeparatorProps,
|
|
44
|
+
JumpToLatestProps,
|
|
45
|
+
} from './types';
|
|
33
46
|
|
|
34
47
|
export { VirtualMessageList } from './components/VirtualMessageList';
|
|
35
48
|
|
|
@@ -51,6 +64,44 @@ export { MessageQuickReactions } from './components/MessageQuickReactions';
|
|
|
51
64
|
export { useMessageActions } from './hooks/useMessageActions';
|
|
52
65
|
|
|
53
66
|
export { formatTime, getDateKey, formatDateLabel, getMessageUserId, replaceMentionsForPreview } from './utils';
|
|
67
|
+
export {
|
|
68
|
+
isGroupChannel,
|
|
69
|
+
isDirectChannel,
|
|
70
|
+
isTopicChannel,
|
|
71
|
+
isPublicGroupChannel,
|
|
72
|
+
isGeneralProxy,
|
|
73
|
+
hasTopicsEnabled,
|
|
74
|
+
supportsBlocking,
|
|
75
|
+
} from './channelTypeUtils';
|
|
76
|
+
export {
|
|
77
|
+
CHANNEL_ROLES,
|
|
78
|
+
isPendingMember,
|
|
79
|
+
isSkippedMember,
|
|
80
|
+
isOwnerMember,
|
|
81
|
+
isFriendChannel,
|
|
82
|
+
canManageChannel,
|
|
83
|
+
canRemoveTargetMember,
|
|
84
|
+
canBanTargetMember,
|
|
85
|
+
canPromoteTargetMember,
|
|
86
|
+
canDemoteTargetMember,
|
|
87
|
+
} from './channelRoleUtils';
|
|
88
|
+
export type { ChannelRole } from './channelRoleUtils';
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
MESSAGE_TYPES,
|
|
92
|
+
ATTACHMENT_TYPES,
|
|
93
|
+
isSystemMessage,
|
|
94
|
+
isStickerMessage,
|
|
95
|
+
isRegularMessage,
|
|
96
|
+
isSignalMessage,
|
|
97
|
+
isImageAttachment,
|
|
98
|
+
isVideoAttachment,
|
|
99
|
+
isVoiceRecordingAttachment,
|
|
100
|
+
isLinkPreviewAttachment,
|
|
101
|
+
isImage,
|
|
102
|
+
isVideo,
|
|
103
|
+
} from './messageTypeUtils';
|
|
104
|
+
export type { MessageType, AttachmentType } from './messageTypeUtils';
|
|
54
105
|
|
|
55
106
|
export {
|
|
56
107
|
defaultMessageRenderers,
|
|
@@ -65,8 +116,17 @@ export {
|
|
|
65
116
|
} from './components/MessageRenderers';
|
|
66
117
|
export type { MessageRendererProps, AttachmentProps } from './components/MessageRenderers';
|
|
67
118
|
|
|
119
|
+
export { MediaLightbox } from './components/MediaLightbox';
|
|
120
|
+
export type { MediaLightboxProps, MediaLightboxItem } from './types';
|
|
121
|
+
|
|
68
122
|
export { MessageInput } from './components/MessageInput';
|
|
69
|
-
export type {
|
|
123
|
+
export type {
|
|
124
|
+
MessageInputProps,
|
|
125
|
+
SendButtonProps,
|
|
126
|
+
AttachButtonProps,
|
|
127
|
+
EmojiPickerProps,
|
|
128
|
+
EmojiButtonProps,
|
|
129
|
+
} from './components/MessageInput';
|
|
70
130
|
|
|
71
131
|
export { FilesPreview } from './components/FilesPreview';
|
|
72
132
|
export type { FilePreviewItem, FilesPreviewProps } from './components/FilesPreview';
|
|
@@ -94,6 +154,8 @@ export type { ReplyPreviewProps } from './types';
|
|
|
94
154
|
export { ForwardMessageModal } from './components/ForwardMessageModal';
|
|
95
155
|
export type { ForwardMessageModalProps, ForwardChannelItemProps } from './components/ForwardMessageModal';
|
|
96
156
|
|
|
157
|
+
export { TopicModal } from './components/TopicModal';
|
|
158
|
+
|
|
97
159
|
export { TypingIndicator } from './components/TypingIndicator';
|
|
98
160
|
export type { TypingIndicatorProps } from './components/TypingIndicator';
|
|
99
161
|
export { useTypingIndicator } from './hooks/useTypingIndicator';
|
|
@@ -104,7 +166,7 @@ export {
|
|
|
104
166
|
DefaultChannelInfoHeader,
|
|
105
167
|
DefaultChannelInfoCover,
|
|
106
168
|
DefaultChannelInfoActions,
|
|
107
|
-
DefaultChannelInfoTabs
|
|
169
|
+
DefaultChannelInfoTabs,
|
|
108
170
|
} from './components/ChannelInfo';
|
|
109
171
|
|
|
110
172
|
export { Modal } from './components/Modal';
|
|
@@ -129,12 +191,7 @@ export type {
|
|
|
129
191
|
} from './types';
|
|
130
192
|
|
|
131
193
|
export { UserPicker } from './components/UserPicker';
|
|
132
|
-
export type {
|
|
133
|
-
UserPickerProps,
|
|
134
|
-
UserPickerUser,
|
|
135
|
-
UserPickerItemProps,
|
|
136
|
-
UserPickerSelectedBoxProps,
|
|
137
|
-
} from './types';
|
|
194
|
+
export type { UserPickerProps, UserPickerUser, UserPickerItemProps, UserPickerSelectedBoxProps } from './types';
|
|
138
195
|
|
|
139
196
|
export { CreateChannelModal } from './components/CreateChannelModal';
|
|
140
197
|
export type { CreateChannelModalProps } from './types';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export const MESSAGE_TYPES = {
|
|
2
|
+
REGULAR: 'regular',
|
|
3
|
+
SYSTEM: 'system',
|
|
4
|
+
STICKER: 'sticker',
|
|
5
|
+
SIGNAL: 'signal',
|
|
6
|
+
ERROR: 'error',
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export const ATTACHMENT_TYPES = {
|
|
10
|
+
IMAGE: 'image',
|
|
11
|
+
VIDEO: 'video',
|
|
12
|
+
VOICE_RECORDING: 'voiceRecording',
|
|
13
|
+
LINK_PREVIEW: 'linkPreview',
|
|
14
|
+
FILE: 'file',
|
|
15
|
+
AUDIO: 'audio',
|
|
16
|
+
} as const;
|
|
17
|
+
|
|
18
|
+
export type MessageType = (typeof MESSAGE_TYPES)[keyof typeof MESSAGE_TYPES] | string;
|
|
19
|
+
export type AttachmentType = (typeof ATTACHMENT_TYPES)[keyof typeof ATTACHMENT_TYPES] | string;
|
|
20
|
+
|
|
21
|
+
// Helpers cho message
|
|
22
|
+
export function isSystemMessage(message: any): boolean {
|
|
23
|
+
return message?.type === MESSAGE_TYPES.SYSTEM;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isStickerMessage(message: any): boolean {
|
|
27
|
+
return message?.type === MESSAGE_TYPES.STICKER;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function isRegularMessage(message: any): boolean {
|
|
31
|
+
return !message?.type || message?.type === MESSAGE_TYPES.REGULAR;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isSignalMessage(message: any): boolean {
|
|
35
|
+
return message?.type === MESSAGE_TYPES.SIGNAL;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Helpers cho attachment
|
|
39
|
+
export function isImageAttachment(attachment: any): boolean {
|
|
40
|
+
return attachment?.type === ATTACHMENT_TYPES.IMAGE;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isVideoAttachment(attachment: any): boolean {
|
|
44
|
+
return attachment?.type === ATTACHMENT_TYPES.VIDEO;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function isVoiceRecordingAttachment(attachment: any): boolean {
|
|
48
|
+
return attachment?.type === ATTACHMENT_TYPES.VOICE_RECORDING;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isLinkPreviewAttachment(attachment: any): boolean {
|
|
52
|
+
return attachment?.type === ATTACHMENT_TYPES.LINK_PREVIEW;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function isImage(attachment: any): boolean {
|
|
56
|
+
return Boolean(
|
|
57
|
+
isImageAttachment(attachment) ||
|
|
58
|
+
(!attachment?.type && (attachment?.mime_type?.startsWith('image/') || attachment?.image_url)),
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isVideo(attachment: any): boolean {
|
|
63
|
+
return !!(isVideoAttachment(attachment) || (!attachment.type && attachment.mime_type?.startsWith('video/')));
|
|
64
|
+
}
|
|
@@ -74,6 +74,27 @@
|
|
|
74
74
|
margin: 0;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
.ermis-channel-info__parent-name {
|
|
78
|
+
font-size: 13px;
|
|
79
|
+
color: var(--ermis-accent);
|
|
80
|
+
margin-top: -4px;
|
|
81
|
+
margin-bottom: 8px;
|
|
82
|
+
font-weight: 500;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.ermis-channel-info__topic-emoji-avatar {
|
|
86
|
+
font-size: 48px;
|
|
87
|
+
line-height: 80px;
|
|
88
|
+
width: 80px;
|
|
89
|
+
height: 80px;
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
background: var(--ermis-bg-secondary);
|
|
94
|
+
border-radius: 50%;
|
|
95
|
+
margin-bottom: 16px;
|
|
96
|
+
}
|
|
97
|
+
|
|
77
98
|
.ermis-channel-info__cover-edit-btn {
|
|
78
99
|
background: transparent;
|
|
79
100
|
border: none;
|