Skip to content

Commit

Permalink
Merge pull request #30 from 1eeing/main
Browse files Browse the repository at this point in the history
update 10.3.3
  • Loading branch information
shine2008 authored Aug 30, 2024
2 parents ee31364 + 3456d43 commit f8621b3
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
6 changes: 3 additions & 3 deletions react/src/YXUIKit/im-kit-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xkit-yx/im-kit-ui",
"version": "10.3.1",
"version": "10.3.3",
"description": "云信即时通讯组件",
"license": "MIT",
"main": "lib/index.js",
Expand Down Expand Up @@ -54,7 +54,7 @@
},
"dependencies": {
"@ant-design/icons": "^5.0.1",
"@xkit-yx/im-store-v2": "^0.2.0",
"@xkit-yx/im-store-v2": "^0.2.1",
"@xkit-yx/utils": "^0.7.1",
"antd": "^4.16.3",
"mobx": "^6.6.1",
Expand All @@ -63,5 +63,5 @@
"react-string-replace": "^1.1.0",
"react-virtualized": "^9.22.5"
},
"gitHead": "45e04861b1ab80e65b14e6b57c9fd1de60a9a1b0"
"gitHead": "92925c6ca2358ac833adfd557c54b79e0345a01e"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export interface ChatAITranslateProps {
prefix?: string
}

const defaultLangs = ['英语', '日语', '韩语', '俄语', '法语', '德语']

export const ChatAITranslate: FC<ChatAITranslateProps> = observer(
({ inputValue, setInputValue, onClose, visible, prefix = 'chat' }) => {
const _prefix = `${prefix}-ai-translate`
Expand All @@ -28,7 +30,11 @@ export const ChatAITranslate: FC<ChatAITranslateProps> = observer(

const aiErrorMap = getAIErrorMap(t)

const options = store.aiUserStore.getAITranslateLangs().map((lang) => ({
const options = (
store.aiUserStore.getAITranslateLangs().length
? store.aiUserStore.getAITranslateLangs()
: defaultLangs
).map((lang) => ({
label: lang,
value: lang,
}))
Expand All @@ -37,10 +43,10 @@ export const ChatAITranslate: FC<ChatAITranslateProps> = observer(
? store.aiUserStore.aiResMsgs[0]
: ''

const [selectedLang, setSelectedLang] = useState(options[0].value)
const [selectedLang, setSelectedLang] = useState(options[0]?.value || '')

const resetState = () => {
setSelectedLang(options[0].value)
setSelectedLang(options[0]?.value || '')
}

useEffect(() => {
Expand Down
65 changes: 42 additions & 23 deletions react/src/components/IMApp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ import {
import { LocalOptions } from '@xkit-yx/im-store-v2/dist/types/types'
import V2NIM, { V2NIMConst } from 'nim-web-sdk-ng'
import { V2NIMAIUser } from 'nim-web-sdk-ng/dist/v2/NIM_BROWSER_SDK/V2NIMAIService'
import { RenderP2pCustomMessageOptions } from '@xkit-yx/im-kit-ui/src/chat/components/ChatP2pMessageList'
import {
NIMInitializeOptions,
NIMOtherOptions,
} from 'nim-web-sdk-ng/dist/v2/NIM_BROWSER_SDK/NIMInterface'
import { RenderP2pCustomMessageOptions } from '@xkit-yx/im-kit-ui/es/chat/components/ChatP2pMessageList'

interface IMContainerProps {
appkey: string //传入您的App Key
account: string // 传入您的云信IM账号
token: string // 传入您的Token
initOptions?: NIMInitializeOptions
otherOptions?: NIMOtherOptions
onLogout?: () => void
changeLanguage?: (value: 'zh' | 'en') => void
}
Expand Down Expand Up @@ -319,7 +325,6 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
[nim.V2NIMConversationIdUtil, nim.V2NIMMessageCreator, store.msgStore]
)


const renderContent = useCallback(() => {
return (
<>
Expand All @@ -341,7 +346,7 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
className={classNames('chat-icon', {
active: model === 'chat',
})}
onClick={goChat}
onClick={() => setModel('chat')}
>
<i className="iconfont">&#xe6c9;</i>
<div className="icon-label">{t('session')}</div>
Expand Down Expand Up @@ -430,11 +435,10 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
teamMsgReceiptVisible,
renderP2pCustomMessage,
store.sysMsgStore,
store.msgStore,
nim.V2NIMMessageCreator,
nim.V2NIMConversationIdUtil,
needMention,
teamManagerVisible,
afterAcceptApplyFriend,
goChat,
])

return (
Expand All @@ -456,7 +460,7 @@ const IMApp: React.FC<IMAppProps> = observer((props) => {
})

const IMAppContainer: React.FC<IMContainerProps> = (props) => {
const { appkey, account, token, onLogout } = props
const { appkey, account, token, initOptions, otherOptions, onLogout } = props
// 国际化语言类型
const [curLanguage, setCurLanguage] = useState<'zh' | 'en'>('zh')
// 添加好友是否需要验证
Expand Down Expand Up @@ -566,26 +570,41 @@ const IMAppContainer: React.FC<IMContainerProps> = (props) => {
}, [])

const nim = useMemo(() => {
const nim = V2NIM.getInstance({
appkey,
account,
token,
debugLevel: 'debug',
apiVersion: 'v2',
})
console.log(
'V2NIM.getInstance: ',
{
appkey,
debugLevel: 'debug',
apiVersion: 'v2',
...initOptions,
},
otherOptions
)
const nim = V2NIM.getInstance(
{
appkey,
debugLevel: 'debug',
apiVersion: 'v2',
...initOptions,
},
otherOptions
)

return nim
}, [account, token, appkey])
}, [appkey, initOptions, otherOptions])

useEffect(() => {
nim.V2NIMLoginService.login(account, token, {
retryCount: 5,
})

return () => {
nim.V2NIMLoginService.logout()
if (account && token) {
nim.V2NIMLoginService.login(account, token, {
retryCount: 5,
})
}
}, [nim, account, token])
}, [account, token, nim.V2NIMLoginService])

const handleLogout = useCallback(async () => {
await nim.V2NIMLoginService.logout()
onLogout?.()
}, [onLogout, nim.V2NIMLoginService])

return (
<ConfigProvider locale={curLanguage === 'zh' ? zhCN : enUS}>
Expand All @@ -598,7 +617,7 @@ const IMAppContainer: React.FC<IMContainerProps> = (props) => {
singleton={true}
>
<IMApp
onLogout={onLogout}
onLogout={handleLogout}
appkey={appkey}
account={account}
locale={curLanguage}
Expand Down

0 comments on commit f8621b3

Please sign in to comment.