@tellescope/chat 0.0.48 → 0.0.51
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/lib/cjs/chat.d.ts +6 -4
- package/lib/cjs/chat.d.ts.map +1 -1
- package/lib/cjs/chat.js +43 -49
- package/lib/cjs/chat.js.map +1 -1
- package/lib/esm/chat.d.ts +6 -4
- package/lib/esm/chat.d.ts.map +1 -1
- package/lib/esm/chat.js +18 -24
- package/lib/esm/chat.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/src/chat.tsx +34 -53
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tellescope/chat",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.51",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/cjs/index.js",
|
|
6
6
|
"module": "./lib/esm/index.js",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
"@fontsource/roboto": "^4.5.1",
|
|
34
34
|
"@mui/icons-material": "^5.0.1",
|
|
35
35
|
"@mui/material": "^5.0.2",
|
|
36
|
-
"@tellescope/constants": "^0.0.
|
|
37
|
-
"@tellescope/react-components": "^0.0.
|
|
38
|
-
"@tellescope/sdk": "^0.0.
|
|
39
|
-
"@tellescope/types-client": "^0.0.
|
|
40
|
-
"@tellescope/types-models": "^0.0.
|
|
41
|
-
"@tellescope/types-utilities": "^0.0.
|
|
42
|
-
"@tellescope/utilities": "^0.0.
|
|
36
|
+
"@tellescope/constants": "^0.0.51",
|
|
37
|
+
"@tellescope/react-components": "^0.0.51",
|
|
38
|
+
"@tellescope/sdk": "^0.0.51",
|
|
39
|
+
"@tellescope/types-client": "^0.0.51",
|
|
40
|
+
"@tellescope/types-models": "^0.0.51",
|
|
41
|
+
"@tellescope/types-utilities": "^0.0.51",
|
|
42
|
+
"@tellescope/utilities": "^0.0.51",
|
|
43
43
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
44
44
|
"@typescript-eslint/parser": "^4.33.0",
|
|
45
45
|
"eslint": "^7.32.0",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"react": "^17.0.2",
|
|
51
51
|
"react-dom": "^17.0.2"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "de84d254e82de300d57202602db9ddd5f373806c",
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|
|
56
56
|
}
|
package/src/chat.tsx
CHANGED
|
@@ -1,45 +1,26 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState, CSSProperties } from "react"
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
+
AsyncIconButton,
|
|
4
5
|
DisplayPicture,
|
|
5
6
|
IN_REACT_WEB,
|
|
6
|
-
} from "@tellescope/react-components"
|
|
7
|
-
import {
|
|
8
7
|
List,
|
|
9
8
|
Flex,
|
|
10
|
-
} from "@tellescope/react-components/lib/esm/layout"
|
|
11
|
-
import {
|
|
12
|
-
AsyncIconButton,
|
|
13
|
-
} from "@tellescope/react-components/lib/esm/controls"
|
|
14
|
-
import {
|
|
15
9
|
Badge,
|
|
16
10
|
SendIcon,
|
|
17
11
|
Styled,
|
|
18
12
|
Typography,
|
|
19
13
|
TextField,
|
|
20
|
-
} from "@tellescope/react-components/lib/esm/mui"
|
|
21
|
-
import {
|
|
22
14
|
LoadingLinear,
|
|
23
|
-
Resolver,
|
|
24
15
|
value_is_loaded,
|
|
25
|
-
} from "@tellescope/react-components/lib/esm/loading"
|
|
26
|
-
import {
|
|
27
16
|
useSession,
|
|
28
17
|
useEnduserSession,
|
|
29
18
|
useResolvedSession,
|
|
30
|
-
} from "@tellescope/react-components/lib/esm/authentication"
|
|
31
|
-
import {
|
|
32
19
|
useChatRooms,
|
|
33
20
|
useChats,
|
|
34
21
|
useChatRoomDisplayInfo,
|
|
35
22
|
ChatRoomDisplayInfo,
|
|
36
|
-
} from "@tellescope/react-components
|
|
37
|
-
import {
|
|
38
|
-
useEndusers,
|
|
39
|
-
} from "@tellescope/react-components/lib/esm/user_state"
|
|
40
|
-
import {
|
|
41
|
-
useUserDisplayInfo,
|
|
42
|
-
} from "@tellescope/react-components/lib/esm/enduser_state"
|
|
23
|
+
} from "@tellescope/react-components"
|
|
43
24
|
|
|
44
25
|
import {
|
|
45
26
|
ChatRoom,
|
|
@@ -52,9 +33,7 @@ import {
|
|
|
52
33
|
} from "@tellescope/types-models"
|
|
53
34
|
|
|
54
35
|
import {
|
|
55
|
-
Indexable,
|
|
56
36
|
LoadedData,
|
|
57
|
-
LoadingStatus,
|
|
58
37
|
SessionType,
|
|
59
38
|
} from "@tellescope/types-utilities"
|
|
60
39
|
|
|
@@ -251,7 +230,21 @@ export interface ConversationPreviewProps {
|
|
|
251
230
|
selectedStyle?: CSSProperties;
|
|
252
231
|
}
|
|
253
232
|
|
|
254
|
-
|
|
233
|
+
export const resolve_chat_room_name = (room: ChatRoom, displayInfo: { [index: string]: UserDisplayInfo }, userType: SessionType, currentUserId: string) => {
|
|
234
|
+
if (room.recentSender !== currentUserId) {
|
|
235
|
+
return user_display_name(displayInfo[room.recentSender ?? ''])
|
|
236
|
+
}
|
|
237
|
+
if (userType === 'user') {
|
|
238
|
+
return user_display_name(displayInfo[room?.enduserIds?.[0] ?? room.creator ?? ''])
|
|
239
|
+
}
|
|
240
|
+
if (userType === 'enduser') {
|
|
241
|
+
console.log(room.recentSender, room.creator, displayInfo[room.creator])
|
|
242
|
+
return user_display_name(displayInfo[room?.userIds?.[0] ?? room.creator ?? ''])
|
|
243
|
+
}
|
|
244
|
+
return ''
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export type PreviewComponentType = React.JSXElementConstructor<ConversationPreviewProps>
|
|
255
248
|
|
|
256
249
|
interface SidebarInfo {
|
|
257
250
|
selectedRoom?: string;
|
|
@@ -264,19 +257,23 @@ interface SidebarInfo {
|
|
|
264
257
|
previewStyle?: CSSProperties;
|
|
265
258
|
}
|
|
266
259
|
|
|
267
|
-
const ConversationPreview = ({ onClick, selected, room, style, selectedStyle }: ConversationPreviewProps) =>
|
|
268
|
-
|
|
269
|
-
style={selected ? (selectedStyle ?? defaultSidebarItemStyleSelected) : (style ?? defaultSidebarItemStyle) }
|
|
270
|
-
>
|
|
271
|
-
<Typography style={defaultMessageNameStyle}>
|
|
272
|
-
|
|
273
|
-
</Typography>
|
|
260
|
+
const ConversationPreview = ({ onClick, selected, room, style, displayInfo, selectedStyle }: ConversationPreviewProps) => {
|
|
261
|
+
const session = useResolvedSession()
|
|
274
262
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
263
|
+
return (
|
|
264
|
+
<Flex flex={1} column onClick={() => !selected && onClick?.(room)}
|
|
265
|
+
style={selected ? (selectedStyle ?? defaultSidebarItemStyleSelected) : (style ?? defaultSidebarItemStyle) }
|
|
266
|
+
>
|
|
267
|
+
<Typography style={defaultMessageNameStyle}>
|
|
268
|
+
{resolve_chat_room_name(room, displayInfo, session.type, session.userInfo.id)}
|
|
269
|
+
</Typography>
|
|
270
|
+
|
|
271
|
+
<Typography style={defaultMessagePreviewStyle}>
|
|
272
|
+
{room.recentMessage ?? room.title}
|
|
273
|
+
</Typography>
|
|
274
|
+
</Flex>
|
|
275
|
+
)
|
|
276
|
+
}
|
|
280
277
|
|
|
281
278
|
const PreviewWithData = ({ PreviewComponent=ConversationPreview, ...props }: Omit<ConversationPreviewProps, 'displayInfo'> & Pick<SidebarInfo, 'PreviewComponent'>) => {
|
|
282
279
|
const session = useResolvedSession()
|
|
@@ -408,22 +405,6 @@ export const EnduserChatSplit = ({ style=defaultSplitChatStyle } : Styled) => {
|
|
|
408
405
|
)
|
|
409
406
|
}
|
|
410
407
|
|
|
411
|
-
export const useUserDisplayNamesForEnduser = (userIds: string[]): Indexable<UserDisplayInfo | undefined> => {
|
|
412
|
-
const [userInfo, { findById: findUser }] = useUserDisplayInfo()
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
if (!userIds || userIds?.length === 0) return {}
|
|
416
|
-
|
|
417
|
-
const idToInfo = {} as Indexable
|
|
418
|
-
if (userInfo.status !== LoadingStatus.Loaded) return idToInfo
|
|
419
|
-
|
|
420
|
-
for (const id of userIds) {
|
|
421
|
-
idToInfo[id] = findUser(id)
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return idToInfo
|
|
425
|
-
}
|
|
426
|
-
|
|
427
408
|
const defaultColorForStatus: { [K in UserActivityStatus]: CSSProperties['color'] } = {
|
|
428
409
|
Active: '#15ba11',
|
|
429
410
|
Away: '#FFD125',
|