Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
Madara
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
viitto
Madara
Commits
4669e85c
Commit
4669e85c
authored
Sep 29, 2019
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
93929c38
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
708 additions
and
696 deletions
+708
-696
index.js
src/configs/index.js
+33
-33
index.js
src/main/index.js
+11
-7
App.vue
src/renderer/App.vue
+3
-0
index.vue
src/renderer/components/index.vue
+0
-1
chateditor.vue
src/renderer/components/msssage/chateditor.vue
+1
-0
index.vue
src/renderer/components/msssage/index.vue
+3
-1
session.js
src/store/actions/session.js
+78
-78
index.js
src/store/mutations/index.js
+579
-576
No files found.
src/configs/index.js
View file @
4669e85c
let
config
=
{
let
config
=
{
sdk
:
'NIM_Web_SDK_nodejs_v5.9.1'
,
sdk
:
'NIM_Web_SDK_nodejs_v5.9.1'
,
// 用户自定义的登录注册地址
// 用户自定义的登录注册地址
loginUrl
:
'/webdemo/h5/login.html'
,
loginUrl
:
'/webdemo/h5/login.html'
,
registUrl
:
'/webdemo/h5/regist.html'
,
registUrl
:
'/webdemo/h5/regist.html'
,
homeUrl
:
'/webdemo/h5/index.html#/session'
,
homeUrl
:
'/webdemo/h5/index.html#/session'
,
// 资源路径根目录,为了方便用户部署在二级以上URL路径上
// 资源路径根目录,为了方便用户部署在二级以上URL路径上
resourceUrl
:
'http://yx-web.nos.netease.com/webdoc/h5'
,
resourceUrl
:
'http://yx-web.nos.netease.com/webdoc/h5'
,
// 用户logo地址
// 用户logo地址
logo
:
'http://yx-web.nos.netease.com/webdoc/h5/im/logo.png'
,
logo
:
'http://yx-web.nos.netease.com/webdoc/h5/im/logo.png'
,
// 默认用户头像
// 默认用户头像
defaultUserIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/default-icon.png'
,
defaultUserIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/default-icon.png'
,
// 默认普通群头像
// 默认普通群头像
defaultGroupIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/default-group.png'
,
defaultGroupIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/default-group.png'
,
// 默认高级群头像
// 默认高级群头像
defaultAdvancedIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/default-advanced.png'
,
defaultAdvancedIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/default-advanced.png'
,
// 系统通知图标
// 系统通知图标
noticeIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/notice-icon.png'
,
noticeIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/notice-icon.png'
,
// 我的手机图标
// 我的手机图标
myPhoneIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/my-phone.png'
,
myPhoneIcon
:
'http://yx-web.nos.netease.com/webdoc/h5/im/my-phone.png'
,
// 本地消息显示数量,会影响性能
// 本地消息显示数量,会影响性能
localMsglimit
:
36
,
localMsglimit
:
36
,
useDb
:
false
useDb
:
false
}
}
const
env
=
'online'
const
env
=
'online'
let
appConfig
=
{
let
appConfig
=
{
// 用户的appkey
// 用户的appkey
// 用于在web demo中注册账号异步请求demo 服务器中使用
// 用于在web demo中注册账号异步请求demo 服务器中使用
test
:
{
test
:
{
appkey
:
'b612b31e837c79c68f141aeb719d2b20'
,
appkey
:
'b612b31e837c79c68f141aeb719d2b20'
,
postUrl
:
'https://apptest.netease.im'
postUrl
:
'https://apptest.netease.im'
},
},
online
:
{
online
:
{
appkey
:
'b612b31e837c79c68f141aeb719d2b20'
,
appkey
:
'b612b31e837c79c68f141aeb719d2b20'
,
postUrl
:
'https://app.netease.im'
postUrl
:
'https://app.netease.im'
}
}
}
}
config
=
Object
.
assign
(
config
,
appConfig
[
env
])
config
=
Object
.
assign
(
config
,
appConfig
[
env
])
export
default
config
export
default
config
\ No newline at end of file
src/main/index.js
View file @
4669e85c
...
@@ -79,6 +79,8 @@ const addnewuserUrl = process.env.NODE_ENV === 'development' ? `http://localhost
...
@@ -79,6 +79,8 @@ const addnewuserUrl = process.env.NODE_ENV === 'development' ? `http://localhost
const appXmlPath = process.execPath.substring(0, process.execPath.lastIndexOf('
\\
') + 1) + '
app
.
json
'
const appXmlPath = process.execPath.substring(0, process.execPath.lastIndexOf('
\\
') + 1) + '
app
.
json
'
const forwardUrl = process.env.NODE_ENV === '
development
' ? `http://localhost:9080/#/forwardMsg` : `file://${__dirname}/index.html#/forwardMsg`
const forwardUrl = process.env.NODE_ENV === '
development
' ? `http://localhost:9080/#/forwardMsg` : `file://${__dirname}/index.html#/forwardMsg`
if (process.env.NODE_ENV !== '
development
') {
if (process.env.NODE_ENV !== '
development
') {
global.__static = require('
path
').join(__dirname, '
/
static
').replace(/
\\
/g, '
\\\\
')
global.__static = require('
path
').join(__dirname, '
/
static
').replace(/
\\
/g, '
\\\\
')
...
@@ -290,8 +292,8 @@ app.on('activate', () => {
...
@@ -290,8 +292,8 @@ app.on('activate', () => {
createWindow()
createWindow()
}
}
})
})
ipc.on('
reconnect
',
function(event)
{
ipc.on('
reconnect
',
function(event)
{
nim
=
null
nim
=
null
initNIM(global.LOGINUSER.ImAccount, global.LOGINUSER.ImToken)
initNIM(global.LOGINUSER.ImAccount, global.LOGINUSER.ImToken)
})
})
ipc.on('
loginSuccess
', function(event, userInfo) {
ipc.on('
loginSuccess
', function(event, userInfo) {
...
@@ -697,6 +699,7 @@ ipc.on('send-file', function(event, obj) {
...
@@ -697,6 +699,7 @@ ipc.on('send-file', function(event, obj) {
custom: JSON.stringify(customMsg),
custom: JSON.stringify(customMsg),
uploadprogress: function(data) {
uploadprogress: function(data) {
file.progess = data.percentage
file.progess = data.percentage
console.log(file)
event.sender.send('
sending
-
process
', file)
event.sender.send('
sending
-
process
', file)
},
},
uploaderror: function() {
uploaderror: function() {
...
@@ -814,8 +817,8 @@ let getMainWinodw = function(isLoad) {
...
@@ -814,8 +817,8 @@ let getMainWinodw = function(isLoad) {
mainWindow
.
show
()
mainWindow
.
show
()
mainWindow
.
setAlwaysOnTop
(
true
)
mainWindow
.
setAlwaysOnTop
(
true
)
mainWindow
.
setAlwaysOnTop
(
false
)
mainWindow
.
setAlwaysOnTop
(
false
)
//mainWindow.webContents.openDevTools(true);
//mainWindow.webContents.openDevTools(true);
//getNoticeWindows()
//getNoticeWindows()
})
})
}
}
//加载隐藏窗口防止用户关闭
//加载隐藏窗口防止用户关闭
...
@@ -936,7 +939,8 @@ let getNoticeWindows = function() {
...
@@ -936,7 +939,8 @@ let getNoticeWindows = function() {
width
:
300
,
width
:
300
,
height
:
115
,
height
:
115
,
skipTaskbar
:
true
,
skipTaskbar
:
true
,
alwaysOnTop
:
true
alwaysOnTop
:
false
,
focusable
:
false
})
})
noticeWindows
.
setBounds
({
noticeWindows
.
setBounds
({
y
:
electron
.
screen
.
getPrimaryDisplay
().
workAreaSize
.
height
-
115
,
y
:
electron
.
screen
.
getPrimaryDisplay
().
workAreaSize
.
height
-
115
,
...
@@ -970,7 +974,7 @@ let getAddNewUserWinodes = function() {
...
@@ -970,7 +974,7 @@ let getAddNewUserWinodes = function() {
addNewUserWinodes
.
setMenu
(
null
)
addNewUserWinodes
.
setMenu
(
null
)
addNewUserWinodes
.
once
(
'ready-to-show'
,
()
=>
{
addNewUserWinodes
.
once
(
'ready-to-show'
,
()
=>
{
addNewUserWinodes
.
show
()
addNewUserWinodes
.
show
()
//addNewUserWinodes.webContents.openDevTools(true);
//addNewUserWinodes.webContents.openDevTools(true);
})
})
}
else
{
}
else
{
addNewUserWinodes
.
focus
()
addNewUserWinodes
.
focus
()
...
@@ -1099,7 +1103,6 @@ let initNIM = function(uid, token) {
...
@@ -1099,7 +1103,6 @@ let initNIM = function(uid, token) {
function onDisconnect(error) {
function onDisconnect(error) {
// 此时说明 SDK 处于断开状态, 开发者此时应该根据错误码提示相应的错误信息, 并且跳转到登录页面
// 此时说明 SDK 处于断开状态, 开发者此时应该根据错误码提示相应的错误信息, 并且跳转到登录页面
if (error) {
if (error) {
switch (error.code) {
switch (error.code) {
// 账号或者密码错误, 请跳转到登录页面并提示错误
// 账号或者密码错误, 请跳转到登录页面并提示错误
...
@@ -1115,6 +1118,7 @@ let initNIM = function(uid, token) {
...
@@ -1115,6 +1118,7 @@ let initNIM = function(uid, token) {
break;
break;
}
}
}
}
console.log('
异常了
');
}
}
function onError(error) {
function onError(error) {
...
...
src/renderer/App.vue
View file @
4669e85c
...
@@ -9,6 +9,9 @@
...
@@ -9,6 +9,9 @@
export
default
{
export
default
{
name
:
"MageOffice"
,
name
:
"MageOffice"
,
mounted
()
{
mounted
()
{
window
.
alert
=
function
()
{
return
false
;
}
document
.
querySelector
(
'#app'
).
addEventListener
(
document
.
querySelector
(
'#app'
).
addEventListener
(
"dragover"
,
"dragover"
,
function
(
e
)
{
function
(
e
)
{
...
...
src/renderer/components/index.vue
View file @
4669e85c
...
@@ -195,7 +195,6 @@ export default {
...
@@ -195,7 +195,6 @@ export default {
},
8
*
1000
);
},
8
*
1000
);
},
},
atMsg
(){
atMsg
(){
console
.
log
(
11111111111111
)
this
.
MsgBus
.
$emit
(
'send-at-name'
,
this
.
atInfo
.
atName
)
this
.
MsgBus
.
$emit
(
'send-at-name'
,
this
.
atInfo
.
atName
)
},
},
showCard
(
e
){
showCard
(
e
){
...
...
src/renderer/components/msssage/chateditor.vue
View file @
4669e85c
...
@@ -85,6 +85,7 @@ export default {
...
@@ -85,6 +85,7 @@ export default {
});
});
this
.
$electron
.
ipcRenderer
.
on
(
"sending-process"
,
(
event
,
file
)
=>
{
this
.
$electron
.
ipcRenderer
.
on
(
"sending-process"
,
(
event
,
file
)
=>
{
console
.
log
(
file
)
this
.
GLOBALSENDING
.
forEach
(
x
=>
{
this
.
GLOBALSENDING
.
forEach
(
x
=>
{
if
((
x
.
msgId
=
file
.
msgId
))
{
if
((
x
.
msgId
=
file
.
msgId
))
{
x
=
file
;
x
=
file
;
...
...
src/renderer/components/msssage/index.vue
View file @
4669e85c
...
@@ -590,7 +590,9 @@ export default {
...
@@ -590,7 +590,9 @@ export default {
lastMsg
.
type
===
"notification"
&&
lastMsg
.
type
===
"notification"
&&
lastMsg
.
attach
&&
lastMsg
.
attach
&&
lastMsg
.
attach
.
team
&&
lastMsg
.
attach
.
team
&&
lastMsg
.
attach
.
team
.
custom
lastMsg
.
attach
.
team
.
custom
&&
this
.
$store
.
state
.
msgs
[
item
.
id
]
&&
this
.
$store
.
state
.
msgs
[
item
.
id
].
length
>
0
)
{
)
{
for
(
let
i
=
this
.
$store
.
state
.
msgs
[
item
.
id
].
length
-
1
;
i
>=
0
;
i
--
)
{
for
(
let
i
=
this
.
$store
.
state
.
msgs
[
item
.
id
].
length
-
1
;
i
>=
0
;
i
--
)
{
lastMsg
=
this
.
$store
.
state
.
msgs
[
item
.
id
][
i
]
lastMsg
=
this
.
$store
.
state
.
msgs
[
item
.
id
][
i
]
...
...
src/store/actions/session.js
View file @
4669e85c
...
@@ -5,96 +5,96 @@
...
@@ -5,96 +5,96 @@
import
store
from
'../'
import
store
from
'../'
// 如果会话对象不是好友,需要更新好友名片
// 如果会话对象不是好友,需要更新好友名片
function
updateSessionAccount
(
sessions
)
{
function
updateSessionAccount
(
sessions
)
{
let
accountsNeedSearch
=
[]
let
accountsNeedSearch
=
[]
sessions
.
forEach
(
item
=>
{
sessions
.
forEach
(
item
=>
{
if
(
item
.
scene
===
'p2p'
)
{
if
(
item
.
scene
===
'p2p'
)
{
// 如果不存在缓存资料
// 如果不存在缓存资料
if
(
!
store
.
state
.
userInfos
[
item
.
to
])
{
if
(
!
store
.
state
.
userInfos
[
item
.
to
])
{
accountsNeedSearch
.
push
(
item
.
to
)
accountsNeedSearch
.
push
(
item
.
to
)
}
}
}
}
})
if
(
accountsNeedSearch
.
length
>
0
)
{
store
.
dispatch
(
'searchUsers'
,
{
accounts
:
accountsNeedSearch
})
})
}
if
(
accountsNeedSearch
.
length
>
0
)
{
store
.
dispatch
(
'searchUsers'
,
{
accounts
:
accountsNeedSearch
})
}
}
}
// onSessions只在初始化完成后回调
// onSessions只在初始化完成后回调
export
function
onSessions
(
sessions
)
{
export
function
onSessions
(
sessions
)
{
updateSessionAccount
(
sessions
)
updateSessionAccount
(
sessions
)
store
.
commit
(
'updateSessions'
,
sessions
)
store
.
commit
(
'updateSessions'
,
sessions
)
}
}
export
function
onUpdateSession
(
session
)
{
export
function
onUpdateSession
(
session
)
{
let
sessions
=
[
session
]
let
sessions
=
[
session
]
updateSessionAccount
(
sessions
)
updateSessionAccount
(
sessions
)
store
.
commit
(
'updateSessions'
,
sessions
)
store
.
commit
(
'updateSessions'
,
sessions
)
}
}
export
function
deleteSession
({
state
,
commit
},
sessionId
)
{
export
function
deleteSession
({
state
,
commit
},
sessionId
)
{
const
nim
=
state
.
nim
const
nim
=
state
.
nim
sessionId
=
sessionId
||
''
sessionId
=
sessionId
||
''
let
scene
=
null
let
scene
=
null
let
account
=
null
let
account
=
null
if
(
/^p2p-/
.
test
(
sessionId
))
{
if
(
/^p2p-/
.
test
(
sessionId
))
{
scene
=
'p2p'
scene
=
'p2p'
account
=
sessionId
.
replace
(
/^p2p-/
,
''
)
account
=
sessionId
.
replace
(
/^p2p-/
,
''
)
}
else
if
(
/^team-/
.
test
(
sessionId
))
{
}
else
if
(
/^team-/
.
test
(
sessionId
))
{
scene
=
'team'
scene
=
'team'
account
=
sessionId
.
replace
(
/^team-/
,
''
)
account
=
sessionId
.
replace
(
/^team-/
,
''
)
}
}
if
(
account
&&
scene
)
{
if
(
account
&&
scene
)
{
nim
.
deleteSession
({
nim
.
deleteSession
({
scene
,
scene
,
to
:
account
,
to
:
account
,
done
:
function
deleteServerSessionDone
(
error
,
obj
)
{
done
:
function
deleteServerSessionDone
(
error
,
obj
)
{
if
(
error
)
{
if
(
error
)
{
//alert(error)
//alert(error)
return
return
}
}
nim
.
deleteLocalSession
({
nim
.
deleteLocalSession
({
id
:
sessionId
,
id
:
sessionId
,
done
:
function
deleteLocalSessionDone
(
error
,
obj
)
{
done
:
function
deleteLocalSessionDone
(
error
,
obj
)
{
if
(
error
)
{
if
(
error
)
{
//alert(error)
//alert(error)
return
return
}
commit
(
'deleteSessions'
,
[
sessionId
])
}
})
}
}
commit
(
'deleteSessions'
,
[
sessionId
])
}
})
})
}
}
})
}
}
}
export
function
setCurrSession
({
state
,
commit
,
dispatch
},
sessionId
)
{
export
function
setCurrSession
({
state
,
commit
,
dispatch
},
sessionId
)
{
const
nim
=
state
.
nim
const
nim
=
state
.
nim
if
(
sessionId
)
{
if
(
sessionId
)
{
commit
(
'updateCurrSessionId'
,
{
commit
(
'updateCurrSessionId'
,
{
type
:
'init'
,
type
:
'init'
,
sessionId
sessionId
})
})
if
(
nim
)
{
if
(
nim
)
{
// 如果在聊天页面刷新,此时还没有nim实例,需要在onSessions里同步
// 如果在聊天页面刷新,此时还没有nim实例,需要在onSessions里同步
nim
.
setCurrSession
(
sessionId
)
nim
.
setCurrSession
(
sessionId
)
commit
(
'updateCurrSessionMsgs'
,
{
commit
(
'updateCurrSessionMsgs'
,
{
type
:
'init'
,
type
:
'init'
,
sessionId
sessionId
})
})
// 发送已读回执
// 发送已读回执
dispatch
(
'sendMsgReceipt'
)
dispatch
(
'sendMsgReceipt'
)
}
}
}
}
}
}
export
function
resetCurrSession
({
state
,
commit
})
{
export
function
resetCurrSession
({
state
,
commit
})
{
const
nim
=
state
.
nim
const
nim
=
state
.
nim
nim
.
resetCurrSession
()
nim
.
resetCurrSession
()
commit
(
'updateCurrSessionMsgs'
,
{
commit
(
'updateCurrSessionMsgs'
,
{
type
:
'destroy'
type
:
'destroy'
})
})
}
}
\ No newline at end of file
src/store/mutations/index.js
View file @
4669e85c
...
@@ -8,598 +8,601 @@ import config from '../../configs'
...
@@ -8,598 +8,601 @@ import config from '../../configs'
import
Vue
from
'Vue'
import
Vue
from
'Vue'
export
default
{
export
default
{
updateRefreshState
(
state
)
{
updateRefreshState
(
state
)
{
state
.
isRefresh
=
false
state
.
isRefresh
=
false
},
},
updateLoading
(
state
,
status
)
{
updateLoading
(
state
,
status
)
{
clearTimeout
(
state
.
loadingTimer
)
clearTimeout
(
state
.
loadingTimer
)
state
.
loadingTimer
=
setTimeout
(()
=>
{
state
.
loadingTimer
=
setTimeout
(()
=>
{
state
.
isLoading
=
status
state
.
isLoading
=
status
},
20
)
},
20
)
},
},
updateFullscreenImage
(
state
,
obj
)
{
updateFullscreenImage
(
state
,
obj
)
{
obj
=
obj
||
{}
obj
=
obj
||
{}
if
(
obj
.
src
&&
obj
.
type
===
'show'
)
{
if
(
obj
.
src
&&
obj
.
type
===
'show'
)
{
state
.
fullscreenImgSrc
=
obj
.
src
state
.
fullscreenImgSrc
=
obj
.
src
state
.
isFullscreenImgShow
=
true
state
.
isFullscreenImgShow
=
true
}
else
if
(
obj
.
type
===
'hide'
)
{
}
else
if
(
obj
.
type
===
'hide'
)
{
state
.
fullscreenImgSrc
=
' '
state
.
fullscreenImgSrc
=
' '
state
.
isFullscreenImgShow
=
false
state
.
isFullscreenImgShow
=
false
}
}
},
},
updateUserUID
(
state
,
loginInfo
)
{
updateUserUID
(
state
,
loginInfo
)
{
state
.
userUID
=
loginInfo
.
uid
state
.
userUID
=
loginInfo
.
uid
state
.
sdktoken
=
loginInfo
.
sdktoken
state
.
sdktoken
=
loginInfo
.
sdktoken
cookie
.
setCookie
(
'uid'
,
loginInfo
.
uid
)
cookie
.
setCookie
(
'uid'
,
loginInfo
.
uid
)
cookie
.
setCookie
(
'sdktoken'
,
loginInfo
.
sdktoken
)
cookie
.
setCookie
(
'sdktoken'
,
loginInfo
.
sdktoken
)
},
},
updateMyInfo
(
state
,
myInfo
)
{
updateMyInfo
(
state
,
myInfo
)
{
state
.
myInfo
=
util
.
mergeObject
(
state
.
myInfo
,
myInfo
)
state
.
myInfo
=
util
.
mergeObject
(
state
.
myInfo
,
myInfo
)
},
},
updateUserInfo
(
state
,
users
)
{
updateUserInfo
(
state
,
users
)
{
let
userInfos
=
state
.
userInfos
let
userInfos
=
state
.
userInfos
users
.
forEach
(
user
=>
{
users
.
forEach
(
user
=>
{
let
account
=
user
.
account
let
account
=
user
.
account
if
(
account
)
{
if
(
account
)
{
userInfos
[
account
]
=
util
.
mergeObject
(
userInfos
[
account
],
user
)
userInfos
[
account
]
=
util
.
mergeObject
(
userInfos
[
account
],
user
)
}
}
})
state
.
userInfos
=
util
.
mergeObject
(
state
.
userInfos
,
userInfos
)
},
updateFriends
(
state
,
friends
,
cutFriends
=
[])
{
const
nim
=
state
.
nim
state
.
friendslist
=
nim
.
mergeFriends
(
state
.
friendslist
,
friends
)
// state.friendslist = nim.cutFriends(state.friendslist, cutFriends)
state
.
friendslist
=
nim
.
cutFriends
(
state
.
friendslist
,
friends
.
invalid
)
},
updateRobots
(
state
,
robots
)
{
const
nim
=
state
.
nim
robots
=
robots
.
map
(
item
=>
{
if
(
item
.
avatar
)
{
item
.
originAvatar
=
item
.
avatar
item
.
avatar
=
nim
.
viewImageSync
({
url
:
item
.
avatar
,
// 必填
thumbnail
:
{
// 生成缩略图, 可选填
width
:
40
,
height
:
40
,
mode
:
'cover'
}
})
})
}
else
{
state
.
userInfos
=
util
.
mergeObject
(
state
.
userInfos
,
userInfos
)
item
.
avatar
=
config
.
defaultUserIcon
},
}
updateFriends
(
state
,
friends
,
cutFriends
=
[])
{
return
item
const
nim
=
state
.
nim
})
state
.
friendslist
=
nim
.
mergeFriends
(
state
.
friendslist
,
friends
)
state
.
robotslist
=
robots
// state.friendslist = nim.cutFriends(state.friendslist, cutFriends)
state
.
robotInfos
=
Object
.
create
(
null
)
state
.
friendslist
=
nim
.
cutFriends
(
state
.
friendslist
,
friends
.
invalid
)
robots
.
forEach
(
robot
=>
{
},
state
.
robotInfos
[
robot
.
account
]
=
robot
updateRobots
(
state
,
robots
)
{
state
.
robotInfosByNick
[
robot
.
nick
]
=
robot
const
nim
=
state
.
nim
})
robots
=
robots
.
map
(
item
=>
{
},
if
(
item
.
avatar
)
{
updateBlacklist
(
state
,
blacks
)
{
item
.
originAvatar
=
item
.
avatar
const
nim
=
state
.
nim
item
.
avatar
=
nim
.
viewImageSync
({
state
.
blacklist
=
nim
.
cutFriends
(
state
.
blacklist
,
blacks
.
invalid
)
url
:
item
.
avatar
,
// 必填
let
addBlacks
=
blacks
.
filter
(
item
=>
{
thumbnail
:
{
// 生成缩略图, 可选填
return
item
.
isBlack
===
true
width
:
40
,
})
height
:
40
,
let
remBlacks
=
blacks
.
filter
(
item
=>
{
mode
:
'cover'
return
item
.
isBlack
===
false
}
})
})
// 添加黑名单
}
else
{
state
.
blacklist
=
nim
.
mergeFriends
(
state
.
blacklist
,
addBlacks
)
item
.
avatar
=
config
.
defaultUserIcon
// 解除黑名单
}
state
.
blacklist
=
nim
.
cutFriends
(
state
.
blacklist
,
remBlacks
)
return
item
},
})
updateSearchlist
(
state
,
obj
)
{
state
.
robotslist
=
robots
const
type
=
obj
.
type
state
.
robotInfos
=
Object
.
create
(
null
)
switch
(
type
)
{
robots
.
forEach
(
robot
=>
{
case
'user'
:
state
.
robotInfos
[
robot
.
account
]
=
robot
if
(
obj
.
list
.
length
!==
0
||
state
.
searchedUsers
.
length
!==
0
)
{
state
.
robotInfosByNick
[
robot
.
nick
]
=
robot
state
.
searchedUsers
=
obj
.
list
})
}
else
{
},
state
.
searchedUsers
=
[]
updateBlacklist
(
state
,
blacks
)
{
const
nim
=
state
.
nim
state
.
blacklist
=
nim
.
cutFriends
(
state
.
blacklist
,
blacks
.
invalid
)
let
addBlacks
=
blacks
.
filter
(
item
=>
{
return
item
.
isBlack
===
true
})
let
remBlacks
=
blacks
.
filter
(
item
=>
{
return
item
.
isBlack
===
false
})
// 添加黑名单
state
.
blacklist
=
nim
.
mergeFriends
(
state
.
blacklist
,
addBlacks
)
// 解除黑名单
state
.
blacklist
=
nim
.
cutFriends
(
state
.
blacklist
,
remBlacks
)
},
updateSearchlist
(
state
,
obj
)
{
const
type
=
obj
.
type
switch
(
type
)
{
case
'user'
:
if
(
obj
.
list
.
length
!==
0
||
state
.
searchedUsers
.
length
!==
0
)
{
state
.
searchedUsers
=
obj
.
list
}
else
{
state
.
searchedUsers
=
[]
}
break
case
'team'
:
if
(
obj
.
list
.
length
!==
0
||
state
.
searchedTeams
.
length
!==
0
)
{
state
.
searchedTeams
=
obj
.
list
}
else
{
state
.
searchedTeams
=
[]
}
break
}
},
updateSessions
(
state
,
sessions
)
{
const
nim
=
state
.
nim
state
.
sessionlist
=
nim
.
mergeSessions
(
state
.
sessionlist
,
sessions
)
state
.
sessionlist
.
sort
((
a
,
b
)
=>
{
return
b
.
updateTime
-
a
.
updateTime
})
state
.
sessionlist
.
forEach
(
item
=>
{
state
.
sessionMap
[
item
.
id
]
=
item
})
},
deleteSessions
(
state
,
sessionIds
)
{
const
nim
=
state
.
nim
state
.
sessionlist
=
nim
.
cutSessionsByIds
(
state
.
sessionlist
,
sessionIds
)
},
addToMutelist
(
state
,
obj
)
{
const
nim
=
state
.
nim
state
.
mutelist
=
nim
.
mergeRelations
(
state
.
mutelist
,
obj
.
record
);
},
removeFromMutelist
(
state
,
obj
)
{
const
nim
=
state
.
nim
state
.
mutelist
=
nim
.
cutRelations
(
state
.
mutelist
,
obj
.
record
);
},
updateMutelist
(
state
,
mutelist
)
{
const
nim
=
state
.
nim
state
.
mutelist
=
nim
.
mergeRelations
(
state
.
mutelist
,
mutelist
)
state
.
mutelist
=
nim
.
cutRelations
(
state
.
mutelist
,
mutelist
.
invalid
)
},
updateNetError
(
state
,
status
)
{
state
.
isNetError
=
status
},
// 初始化,收到离线漫游消息时调用
updateMsgs
(
state
,
msgs
)
{
const
nim
=
state
.
nim
let
tempSessionMap
=
{}
msgs
.
forEach
(
msg
=>
{
let
sessionId
=
msg
.
sessionId
tempSessionMap
[
sessionId
]
=
true
if
(
!
state
.
msgs
[
sessionId
])
{
state
.
msgs
[
sessionId
]
=
[]
}
// sdk会做消息去重
state
.
msgs
[
sessionId
]
=
nim
.
mergeMsgs
(
state
.
msgs
[
sessionId
],
[
msg
])
// state.msgs[sessionId].push(msg)
})
store
.
commit
(
'updateMsgByIdClient'
,
msgs
)
for
(
let
sessionId
in
tempSessionMap
)
{
state
.
msgs
[
sessionId
].
sort
((
a
,
b
)
=>
{
if
(
a
.
time
===
b
.
time
)
{
// 机器人消息,回复消息时间和提问消息时间相同,提问在前,回复在后
if
(
a
.
type
===
'robot'
&&
b
.
type
===
'robot'
)
{
if
(
a
.
content
&&
a
.
content
.
msgOut
)
{
return
1
}
if
(
b
.
content
&&
b
.
content
.
msgOut
)
{
return
-
1
}
}
}
return
a
.
time
-
b
.
time
})
if
(
sessionId
===
state
.
currSessionId
)
{
store
.
commit
(
'updateCurrSessionMsgs'
,
{
type
:
'init'
})
}
}
},
// 更新追加消息,追加一条消息
putMsg
(
state
,
msg
)
{
let
sessionId
=
msg
.
sessionId
if
(
!
state
.
msgs
[
sessionId
])
{
state
.
msgs
[
sessionId
]
=
[]
}
}
break
store
.
commit
(
'updateMsgByIdClient'
,
msg
)
case
'team'
:
let
tempMsgs
=
state
.
msgs
[
sessionId
]
if
(
obj
.
list
.
length
!==
0
||
state
.
searchedTeams
.
length
!==
0
)
{
let
lastMsgIndex
=
tempMsgs
.
length
-
1
state
.
searchedTeams
=
obj
.
list
if
(
msg
.
isLocal
&&
lastMsgIndex
>=
0
)
{
msg
.
time
=
tempMsgs
[
lastMsgIndex
].
time
+
1
}
if
(
tempMsgs
.
length
===
0
||
msg
.
time
>=
tempMsgs
[
lastMsgIndex
].
time
)
{
tempMsgs
.
push
(
msg
)
}
else
{
}
else
{
state
.
searchedTeams
=
[]
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
let
currMsg
=
tempMsgs
[
i
]
if
(
msg
.
time
>=
currMsg
.
time
)
{
state
.
msgs
[
sessionId
].
splice
(
i
,
0
,
msg
)
break
}
}
}
}
break
},
}
// 删除消息列表消息
},
deleteMsg
(
state
,
msg
)
{
updateSessions
(
state
,
sessions
)
{
let
sessionId
=
msg
.
sessionId
const
nim
=
state
.
nim
let
tempMsgs
=
state
.
msgs
[
sessionId
]
state
.
sessionlist
=
nim
.
mergeSessions
(
state
.
sessionlist
,
sessions
)
if
(
!
tempMsgs
||
tempMsgs
.
length
===
0
)
{
state
.
sessionlist
.
sort
((
a
,
b
)
=>
{
return
return
b
.
updateTime
-
a
.
updateTime
}
})
let
lastMsgIndex
=
tempMsgs
.
length
-
1
state
.
sessionlist
.
forEach
(
item
=>
{
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
state
.
sessionMap
[
item
.
id
]
=
item
let
currMsg
=
tempMsgs
[
i
]
})
if
(
msg
.
idClient
===
currMsg
.
idClient
)
{
},
state
.
msgs
[
sessionId
].
splice
(
i
,
1
)
deleteSessions
(
state
,
sessionIds
)
{
break
const
nim
=
state
.
nim
state
.
sessionlist
=
nim
.
cutSessionsByIds
(
state
.
sessionlist
,
sessionIds
)
},
addToMutelist
(
state
,
obj
){
const
nim
=
state
.
nim
state
.
mutelist
=
nim
.
mergeRelations
(
state
.
mutelist
,
obj
.
record
);
},
removeFromMutelist
(
state
,
obj
){
const
nim
=
state
.
nim
state
.
mutelist
=
nim
.
cutRelations
(
state
.
mutelist
,
obj
.
record
);
},
updateMutelist
(
state
,
mutelist
)
{
const
nim
=
state
.
nim
state
.
mutelist
=
nim
.
mergeRelations
(
state
.
mutelist
,
mutelist
)
state
.
mutelist
=
nim
.
cutRelations
(
state
.
mutelist
,
mutelist
.
invalid
)
},
updateNetError
(
state
,
status
)
{
state
.
isNetError
=
status
},
// 初始化,收到离线漫游消息时调用
updateMsgs
(
state
,
msgs
)
{
const
nim
=
state
.
nim
let
tempSessionMap
=
{}
msgs
.
forEach
(
msg
=>
{
let
sessionId
=
msg
.
sessionId
tempSessionMap
[
sessionId
]
=
true
if
(
!
state
.
msgs
[
sessionId
])
{
state
.
msgs
[
sessionId
]
=
[]
}
// sdk会做消息去重
state
.
msgs
[
sessionId
]
=
nim
.
mergeMsgs
(
state
.
msgs
[
sessionId
],
[
msg
])
// state.msgs[sessionId].push(msg)
})
store
.
commit
(
'updateMsgByIdClient'
,
msgs
)
for
(
let
sessionId
in
tempSessionMap
)
{
state
.
msgs
[
sessionId
].
sort
((
a
,
b
)
=>
{
if
(
a
.
time
===
b
.
time
)
{
// 机器人消息,回复消息时间和提问消息时间相同,提问在前,回复在后
if
(
a
.
type
===
'robot'
&&
b
.
type
===
'robot'
)
{
if
(
a
.
content
&&
a
.
content
.
msgOut
)
{
return
1
}
}
if
(
b
.
content
&&
b
.
content
.
msgOut
)
{
}
return
-
1
},
// 替换消息列表消息,如消息撤回
replaceMsg
(
state
,
obj
)
{
let
{
sessionId
,
idClient
,
msg
}
=
obj
let
tempMsgs
=
state
.
msgs
[
sessionId
]
if
(
!
tempMsgs
||
tempMsgs
.
length
===
0
)
{
return
}
let
lastMsgIndex
=
tempMsgs
.
length
-
1
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
let
currMsg
=
tempMsgs
[
i
]
if
(
idClient
===
currMsg
.
idClient
)
{
state
.
msgs
[
sessionId
].
splice
(
i
,
1
,
msg
)
break
}
}
}
}
}
return
a
.
time
-
b
.
time
},
})
// 用idClient 更新消息,目前用于消息撤回
if
(
sessionId
===
state
.
currSessionId
)
{
updateMsgByIdClient
(
state
,
msgs
)
{
store
.
commit
(
'updateCurrSessionMsgs'
,
{
if
(
!
Array
.
isArray
(
msgs
))
{
type
:
'init'
msgs
=
[
msgs
]
}
let
tempTime
=
(
new
Date
()).
getTime
()
msgs
.
forEach
(
msg
=>
{
// 有idClient 且 5分钟以内的消息
if
(
msg
.
idClient
&&
(
tempTime
-
msg
.
time
<
1000
*
300
))
{
state
.
msgsMap
[
msg
.
idClient
]
=
msg
}
})
})
}
},
}
// 更新当前会话id,用于唯一判定是否在current session状态
},
updateCurrSessionId
(
state
,
obj
)
{
// 更新追加消息,追加一条消息
let
type
=
obj
.
type
||
''
putMsg
(
state
,
msg
)
{
if
(
type
===
'destroy'
)
{
let
sessionId
=
msg
.
sessionId
state
.
currSessionId
=
null
if
(
!
state
.
msgs
[
sessionId
])
{
}
else
if
(
type
===
'init'
)
{
state
.
msgs
[
sessionId
]
=
[]
if
(
obj
.
sessionId
&&
(
obj
.
sessionId
!==
state
.
currSessionId
))
{
}
state
.
currSessionId
=
obj
.
sessionId
store
.
commit
(
'updateMsgByIdClient'
,
msg
)
}
let
tempMsgs
=
state
.
msgs
[
sessionId
]
let
lastMsgIndex
=
tempMsgs
.
length
-
1
if
(
msg
.
isLocal
&&
lastMsgIndex
>=
0
){
msg
.
time
=
tempMsgs
[
lastMsgIndex
].
time
+
1
}
if
(
tempMsgs
.
length
===
0
||
msg
.
time
>=
tempMsgs
[
lastMsgIndex
].
time
)
{
tempMsgs
.
push
(
msg
)
}
else
{
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
let
currMsg
=
tempMsgs
[
i
]
if
(
msg
.
time
>=
currMsg
.
time
)
{
state
.
msgs
[
sessionId
].
splice
(
i
,
0
,
msg
)
break
}
}
}
},
}
// clearMsgs(state, obj) {
},
// state.msgs = []
// 删除消息列表消息
// },
deleteMsg
(
state
,
msg
)
{
// 更新当前会话列表的聊天记录,包括历史消息、单聊消息等,不包括聊天室消息
let
sessionId
=
msg
.
sessionId
// replace: 替换idClient的消息
let
tempMsgs
=
state
.
msgs
[
sessionId
]
updateCurrSessionMsgs
(
state
,
obj
)
{
if
(
!
tempMsgs
||
tempMsgs
.
length
===
0
)
{
let
type
=
obj
.
type
||
''
return
if
(
type
===
'destroy'
)
{
// 清空会话消息
}
state
.
currSessionMsgs
=
[]
let
lastMsgIndex
=
tempMsgs
.
length
-
1
state
.
currSessionLastMsg
=
null
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
store
.
commit
(
'updateCurrSessionId'
,
{
let
currMsg
=
tempMsgs
[
i
]
type
:
'destroy'
if
(
msg
.
idClient
===
currMsg
.
idClient
)
{
})
state
.
msgs
[
sessionId
].
splice
(
i
,
1
)
}
else
if
(
type
===
'init'
)
{
// 初始化会话消息列表
break
if
(
state
.
currSessionId
)
{
}
let
sessionId
=
state
.
currSessionId
}
let
currSessionMsgs
=
[].
concat
(
state
.
msgs
[
sessionId
]
||
[])
},
// 做消息截断
// 替换消息列表消息,如消息撤回
let
limit
=
config
.
localMsglimit
replaceMsg
(
state
,
obj
)
{
let
msgLen
=
currSessionMsgs
.
length
let
{
sessionId
,
idClient
,
msg
}
=
obj
if
(
msgLen
-
limit
>
0
)
{
let
tempMsgs
=
state
.
msgs
[
sessionId
]
state
.
currSessionLastMsg
=
currSessionMsgs
[
msgLen
-
limit
]
if
(
!
tempMsgs
||
tempMsgs
.
length
===
0
)
{
currSessionMsgs
=
currSessionMsgs
.
slice
(
msgLen
-
limit
,
msgLen
)
return
}
else
if
(
msgLen
>
0
)
{
}
state
.
currSessionLastMsg
=
currSessionMsgs
[
0
]
let
lastMsgIndex
=
tempMsgs
.
length
-
1
}
else
{
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
state
.
currSessionLastMsg
=
null
let
currMsg
=
tempMsgs
[
i
]
}
if
(
idClient
===
currMsg
.
idClient
)
{
state
.
currSessionMsgs
=
[]
state
.
msgs
[
sessionId
].
splice
(
i
,
1
,
msg
)
let
lastMsgTime
=
0
break
currSessionMsgs
.
forEach
(
msg
=>
{
}
if
((
msg
.
time
-
lastMsgTime
)
>
1000
*
60
*
5
)
{
}
lastMsgTime
=
msg
.
time
},
state
.
currSessionMsgs
.
push
({
// 用idClient 更新消息,目前用于消息撤回
type
:
'timeTag'
,
updateMsgByIdClient
(
state
,
msgs
)
{
text
:
util
.
formatDate
(
msg
.
time
,
false
)
if
(
!
Array
.
isArray
(
msgs
))
{
})
msgs
=
[
msgs
]
}
}
state
.
currSessionMsgs
.
push
(
msg
)
let
tempTime
=
(
new
Date
()).
getTime
()
})
msgs
.
forEach
(
msg
=>
{
store
.
dispatch
(
'checkTeamMsgReceipt'
,
state
.
currSessionMsgs
)
// 有idClient 且 5分钟以内的消息
}
if
(
msg
.
idClient
&&
(
tempTime
-
msg
.
time
<
1000
*
300
))
{
}
else
if
(
type
===
'put'
)
{
// 追加一条消息
state
.
msgsMap
[
msg
.
idClient
]
=
msg
let
newMsg
=
obj
.
msg
}
let
lastMsgTime
=
0
})
let
lenCurrMsgs
=
state
.
currSessionMsgs
.
length
},
if
(
lenCurrMsgs
>
0
)
{
// 更新当前会话id,用于唯一判定是否在current session状态
lastMsgTime
=
state
.
currSessionMsgs
[
lenCurrMsgs
-
1
].
time
updateCurrSessionId
(
state
,
obj
)
{
}
let
type
=
obj
.
type
||
''
if
(
newMsg
)
{
if
(
type
===
'destroy'
)
{
if
((
newMsg
.
time
-
lastMsgTime
)
>
1000
*
60
*
5
)
{
state
.
currSessionId
=
null
state
.
currSessionMsgs
.
push
({
}
else
if
(
type
===
'init'
)
{
type
:
'timeTag'
,
if
(
obj
.
sessionId
&&
(
obj
.
sessionId
!==
state
.
currSessionId
))
{
text
:
util
.
formatDate
(
newMsg
.
time
,
false
)
state
.
currSessionId
=
obj
.
sessionId
})
}
}
}
state
.
currSessionMsgs
.
push
(
newMsg
)
},
store
.
dispatch
(
'checkTeamMsgReceipt'
,
[
newMsg
])
// 更新当前会话列表的聊天记录,包括历史消息、单聊消息等,不包括聊天室消息
}
// replace: 替换idClient的消息
}
else
if
(
type
===
'concat'
)
{
updateCurrSessionMsgs
(
state
,
obj
)
{
// 一般用于历史消息拼接
let
type
=
obj
.
type
||
''
let
currSessionMsgs
=
[]
if
(
type
===
'destroy'
)
{
// 清空会话消息
let
lastMsgTime
=
0
state
.
currSessionMsgs
=
[]
obj
.
msgs
.
forEach
(
msg
=>
{
state
.
currSessionLastMsg
=
null
if
((
msg
.
time
-
lastMsgTime
)
>
1000
*
60
*
5
)
{
store
.
commit
(
'updateCurrSessionId'
,
{
lastMsgTime
=
msg
.
time
type
:
'destroy'
currSessionMsgs
.
push
({
})
type
:
'timeTag'
,
}
else
if
(
type
===
'init'
)
{
// 初始化会话消息列表
text
:
util
.
formatDate
(
msg
.
time
,
false
)
if
(
state
.
currSessionId
)
{
})
let
sessionId
=
state
.
currSessionId
}
let
currSessionMsgs
=
[].
concat
(
state
.
msgs
[
sessionId
]
||
[])
currSessionMsgs
.
push
(
msg
)
// 做消息截断
})
let
limit
=
config
.
localMsglimit
currSessionMsgs
.
reverse
()
let
msgLen
=
currSessionMsgs
.
length
currSessionMsgs
.
forEach
(
msg
=>
{
if
(
msgLen
-
limit
>
0
)
{
state
.
currSessionMsgs
.
unshift
(
msg
)
state
.
currSessionLastMsg
=
currSessionMsgs
[
msgLen
-
limit
]
})
currSessionMsgs
=
currSessionMsgs
.
slice
(
msgLen
-
limit
,
msgLen
)
if
(
obj
.
msgs
[
0
])
{
}
else
if
(
msgLen
>
0
)
{
state
.
currSessionLastMsg
=
obj
.
msgs
[
0
]
state
.
currSessionLastMsg
=
currSessionMsgs
[
0
]
}
}
else
{
//console.log(state.currSessionMsgs)
state
.
currSessionLastMsg
=
null
store
.
dispatch
(
'checkTeamMsgReceipt'
,
currSessionMsgs
)
}
else
if
(
type
===
'replace'
)
{
let
msgLen
=
state
.
currSessionMsgs
.
length
let
lastMsgIndex
=
msgLen
-
1
if
(
msgLen
>
0
)
{
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
if
(
state
.
currSessionMsgs
[
i
].
idClient
===
obj
.
idClient
)
{
state
.
currSessionMsgs
.
splice
(
i
,
1
,
obj
.
msg
)
break
}
}
}
}
}
state
.
currSessionMsgs
=
[]
},
let
lastMsgTime
=
0
updateSysMsgs
(
state
,
sysMsgs
)
{
currSessionMsgs
.
forEach
(
msg
=>
{
const
nim
=
state
.
nim
if
((
msg
.
time
-
lastMsgTime
)
>
1000
*
60
*
5
)
{
if
(
!
Array
.
isArray
(
sysMsgs
))
{
lastMsgTime
=
msg
.
time
sysMsgs
=
[
sysMsgs
]
state
.
currSessionMsgs
.
push
({
}
type
:
'timeTag'
,
sysMsgs
=
sysMsgs
.
map
(
msg
=>
{
text
:
util
.
formatDate
(
msg
.
time
,
false
)
msg
.
showTime
=
util
.
formatDate
(
msg
.
time
,
false
)
return
msg
})
})
}
// state.sysMsgs = nim.mergeSysMsgs(state.sysMsgs, sysMsgs)
state
.
currSessionMsgs
.
push
(
msg
)
state
.
sysMsgs
=
[].
concat
(
nim
.
mergeSysMsgs
(
state
.
sysMsgs
,
sysMsgs
))
Vue
.
set
(
state
,
sysMsgs
,
state
.
sysMsgs
)
},
// 更新消息的状态,如管理员批准或拒绝入群后,会收到新消息,更新入群申请的状态
updateSysMsgState
(
state
,
sysMsg
)
{
let
exitMsg
=
state
.
sysMsgs
.
find
(
msg
=>
{
return
msg
.
idServer
===
sysMsg
.
idServer
})
})
store
.
dispatch
(
'checkTeamMsgReceipt'
,
state
.
currSessionMsgs
)
if
(
exitMsg
)
{
}
exitMsg
.
state
=
sysMsg
.
state
}
else
if
(
type
===
'put'
)
{
// 追加一条消息
let
newMsg
=
obj
.
msg
let
lastMsgTime
=
0
let
lenCurrMsgs
=
state
.
currSessionMsgs
.
length
if
(
lenCurrMsgs
>
0
)
{
lastMsgTime
=
state
.
currSessionMsgs
[
lenCurrMsgs
-
1
].
time
}
if
(
newMsg
)
{
if
((
newMsg
.
time
-
lastMsgTime
)
>
1000
*
60
*
5
)
{
state
.
currSessionMsgs
.
push
({
type
:
'timeTag'
,
text
:
util
.
formatDate
(
newMsg
.
time
,
false
)
})
}
state
.
currSessionMsgs
.
push
(
newMsg
)
store
.
dispatch
(
'checkTeamMsgReceipt'
,
[
newMsg
])
}
}
else
if
(
type
===
'concat'
)
{
// 一般用于历史消息拼接
let
currSessionMsgs
=
[]
let
lastMsgTime
=
0
obj
.
msgs
.
forEach
(
msg
=>
{
if
((
msg
.
time
-
lastMsgTime
)
>
1000
*
60
*
5
)
{
lastMsgTime
=
msg
.
time
currSessionMsgs
.
push
({
type
:
'timeTag'
,
text
:
util
.
formatDate
(
msg
.
time
,
false
)
})
}
}
currSessionMsgs
.
push
(
msg
)
},
})
updateSysMsgUnread
(
state
,
obj
)
{
currSessionMsgs
.
reverse
()
state
.
sysMsgUnread
=
Object
.
assign
({},
obj
)
currSessionMsgs
.
forEach
(
msg
=>
{
},
state
.
currSessionMsgs
.
unshift
(
msg
)
updateCustomSysMsgs
(
state
,
sysMsgs
)
{
})
const
nim
=
state
.
nim
if
(
obj
.
msgs
[
0
])
{
if
(
!
Array
.
isArray
(
sysMsgs
))
{
state
.
currSessionLastMsg
=
obj
.
msgs
[
0
]
sysMsgs
=
[
sysMsgs
]
}
//console.log(state.currSessionMsgs)
store
.
dispatch
(
'checkTeamMsgReceipt'
,
currSessionMsgs
)
}
else
if
(
type
===
'replace'
)
{
let
msgLen
=
state
.
currSessionMsgs
.
length
let
lastMsgIndex
=
msgLen
-
1
if
(
msgLen
>
0
)
{
for
(
let
i
=
lastMsgIndex
;
i
>=
0
;
i
--
)
{
if
(
state
.
currSessionMsgs
[
i
].
idClient
===
obj
.
idClient
)
{
state
.
currSessionMsgs
.
splice
(
i
,
1
,
obj
.
msg
)
break
}
}
}
}
sysMsgs
=
sysMsgs
.
map
(
msg
=>
{
}
msg
.
showTime
=
util
.
formatDate
(
msg
.
time
,
false
)
},
return
msg
updateSysMsgs
(
state
,
sysMsgs
)
{
})
const
nim
=
state
.
nim
// state.customSysMsgs = nim.mergeSysMsgs(state.customSysMsgs, sysMsgs)
if
(
!
Array
.
isArray
(
sysMsgs
))
{
state
.
customSysMsgs
=
state
.
customSysMsgs
.
concat
(
sysMsgs
)
sysMsgs
=
[
sysMsgs
]
Vue
.
set
(
state
,
sysMsgs
,
state
.
customSysMsgs
)
}
sysMsgs
=
sysMsgs
.
map
(
msg
=>
{
msg
.
showTime
=
util
.
formatDate
(
msg
.
time
,
false
)
return
msg
})
// state.sysMsgs = nim.mergeSysMsgs(state.sysMsgs, sysMsgs)
state
.
sysMsgs
=
[].
concat
(
nim
.
mergeSysMsgs
(
state
.
sysMsgs
,
sysMsgs
))
Vue
.
set
(
state
,
sysMsgs
,
state
.
sysMsgs
)
},
// 更新消息的状态,如管理员批准或拒绝入群后,会收到新消息,更新入群申请的状态
updateSysMsgState
(
state
,
sysMsg
)
{
let
exitMsg
=
state
.
sysMsgs
.
find
(
msg
=>
{
return
msg
.
idServer
===
sysMsg
.
idServer
})
if
(
exitMsg
)
{
exitMsg
.
state
=
sysMsg
.
state
}
},
updateSysMsgUnread
(
state
,
obj
)
{
state
.
sysMsgUnread
=
Object
.
assign
({},
obj
)
},
updateCustomSysMsgs
(
state
,
sysMsgs
)
{
const
nim
=
state
.
nim
if
(
!
Array
.
isArray
(
sysMsgs
))
{
sysMsgs
=
[
sysMsgs
]
}
sysMsgs
=
sysMsgs
.
map
(
msg
=>
{
msg
.
showTime
=
util
.
formatDate
(
msg
.
time
,
false
)
return
msg
})
// state.customSysMsgs = nim.mergeSysMsgs(state.customSysMsgs, sysMsgs)
state
.
customSysMsgs
=
state
.
customSysMsgs
.
concat
(
sysMsgs
)
Vue
.
set
(
state
,
sysMsgs
,
state
.
customSysMsgs
)
store
.
commit
(
'updateCustomSysMsgUnread'
,
{
type
:
'add'
,
unread
:
sysMsgs
.
length
})
},
updateCustomSysMsgUnread
(
state
,
obj
)
{
let
{
type
,
unread
}
=
obj
switch
(
type
)
{
case
'reset'
:
state
.
customSysMsgUnread
=
unread
||
0
break
case
'add'
:
state
.
customSysMsgUnread
+=
unread
break
}
},
resetSysMsgs
(
state
,
obj
)
{
let
type
=
obj
.
type
switch
(
type
)
{
case
0
:
state
.
sysMsgs
=
[]
break
case
1
:
state
.
customSysMsgs
=
[]
store
.
commit
(
'updateCustomSysMsgUnread'
,
{
store
.
commit
(
'updateCustomSysMsgUnread'
,
{
type
:
'reset'
type
:
'add'
,
unread
:
sysMsgs
.
length
})
})
break
},
}
updateCustomSysMsgUnread
(
state
,
obj
)
{
},
let
{
type
,
unread
}
=
obj
deleteSysMsgs
(
state
,
obj
)
{
switch
(
type
)
{
let
type
=
obj
.
type
case
'reset'
:
let
idServer
=
obj
.
idServer
state
.
customSysMsgUnread
=
unread
||
0
let
arr
=
type
===
0
?
state
.
sysMsgs
:
state
.
customSysMsgs
break
arr
=
arr
.
filter
(
msg
=>
{
case
'add'
:
return
msg
.
idServer
!==
idServer
state
.
customSysMsgUnread
+=
unread
})
break
Vue
.
set
(
state
,
'sysMsgs'
,
arr
)
}
},
},
setNoMoreHistoryMsgs
(
state
)
{
resetSysMsgs
(
state
,
obj
)
{
state
.
noMoreHistoryMsgs
=
true
let
type
=
obj
.
type
},
switch
(
type
)
{
resetNoMoreHistoryMsgs
(
state
)
{
case
0
:
state
.
noMoreHistoryMsgs
=
false
state
.
sysMsgs
=
[]
},
break
// 继续与机器人会话交互
case
1
:
continueRobotMsg
(
state
,
robotAccid
)
{
state
.
customSysMsgs
=
[]
state
.
continueRobotAccid
=
robotAccid
store
.
commit
(
'updateCustomSysMsgUnread'
,
{
},
type
:
'reset'
})
break
}
},
deleteSysMsgs
(
state
,
obj
)
{
let
type
=
obj
.
type
let
idServer
=
obj
.
idServer
let
arr
=
type
===
0
?
state
.
sysMsgs
:
state
.
customSysMsgs
arr
=
arr
.
filter
(
msg
=>
{
return
msg
.
idServer
!==
idServer
})
Vue
.
set
(
state
,
'sysMsgs'
,
arr
)
},
setNoMoreHistoryMsgs
(
state
)
{
state
.
noMoreHistoryMsgs
=
true
},
resetNoMoreHistoryMsgs
(
state
)
{
state
.
noMoreHistoryMsgs
=
false
},
// 继续与机器人会话交互
continueRobotMsg
(
state
,
robotAccid
)
{
state
.
continueRobotAccid
=
robotAccid
},
initChatroomInfos
(
state
,
obj
)
{
initChatroomInfos
(
state
,
obj
)
{
state
.
chatroomInfos
=
obj
state
.
chatroomInfos
=
obj
},
},
setCurrChatroom
(
state
,
chatroomId
)
{
setCurrChatroom
(
state
,
chatroomId
)
{
state
.
currChatroomId
=
chatroomId
state
.
currChatroomId
=
chatroomId
state
.
currChatroom
=
state
.
chatroomInsts
[
chatroomId
]
state
.
currChatroom
=
state
.
chatroomInsts
[
chatroomId
]
state
.
currChatroomMsgs
=
[]
state
.
currChatroomMsgs
=
[]
state
.
currChatroomInfo
=
{}
state
.
currChatroomInfo
=
{}
state
.
currChatroomMembers
=
[]
state
.
currChatroomMembers
=
[]
},
},
resetCurrChatroom
(
state
)
{
resetCurrChatroom
(
state
)
{
state
.
currChatroomId
=
null
state
.
currChatroomId
=
null
state
.
currChatroom
=
null
state
.
currChatroom
=
null
state
.
currChatroomMsgs
=
[]
state
.
currChatroomMsgs
=
[]
state
.
currChatroomInfo
=
{}
state
.
currChatroomInfo
=
{}
state
.
currChatroomMembers
=
[]
state
.
currChatroomMembers
=
[]
},
},
// 聊天室相关逻辑
// 聊天室相关逻辑
updateChatroomInfo
(
state
,
obj
)
{
updateChatroomInfo
(
state
,
obj
)
{
state
.
currChatroomInfo
=
Object
.
assign
(
state
.
currChatroomInfo
,
obj
)
state
.
currChatroomInfo
=
Object
.
assign
(
state
.
currChatroomInfo
,
obj
)
},
},
updateCurrChatroomMsgs
(
state
,
obj
)
{
updateCurrChatroomMsgs
(
state
,
obj
)
{
let
{
type
,
msgs
}
=
Object
.
assign
({},
obj
)
let
{
type
,
msgs
}
=
Object
.
assign
({},
obj
)
if
(
type
===
'put'
)
{
if
(
type
===
'put'
)
{
msgs
.
forEach
(
msg
=>
{
msgs
.
forEach
(
msg
=>
{
let
chatroomId
=
msg
.
chatroomId
let
chatroomId
=
msg
.
chatroomId
if
(
chatroomId
===
state
.
currChatroomId
)
{
if
(
chatroomId
===
state
.
currChatroomId
)
{
msgs
.
forEach
(
msg
=>
{
msgs
.
forEach
(
msg
=>
{
state
.
currChatroomMsgs
.
push
(
msg
)
state
.
currChatroomMsgs
.
push
(
msg
)
})
})
}
})
}
else
if
(
type
===
'concat'
)
{
// 一般用于历史消息拼接
let
currSessionMsgs
=
obj
.
msgs
currSessionMsgs
.
reverse
()
currSessionMsgs
.
forEach
(
msg
=>
{
state
.
currSessionMsgs
.
unshift
(
msg
)
})
if
(
obj
.
msgs
[
0
])
{
state
.
currSessionLastMsg
=
obj
.
msgs
[
0
]
}
}
},
getChatroomInfo
(
state
,
obj
)
{
state
.
currChatroomInfo
=
obj
},
updateChatroomMembers
(
state
,
obj
)
{
let
{
type
,
members
}
=
obj
if
(
type
===
'destroy'
)
{
state
.
currChatroomMembers
=
[]
}
else
if
(
type
===
'put'
)
{
members
.
forEach
(
member
=>
{
if
(
member
.
online
)
{
state
.
currChatroomMembers
.
push
(
member
)
}
})
}
}
})
},
}
else
if
(
type
===
'concat'
)
{
updateTeamList
(
state
,
teams
)
{
// 一般用于历史消息拼接
const
nim
=
state
.
nim
let
currSessionMsgs
=
obj
.
msgs
store
.
state
.
teamlist
=
nim
.
mergeTeams
(
store
.
state
.
teamlist
,
teams
)
currSessionMsgs
.
reverse
()
store
.
state
.
teamlist
=
nim
.
cutTeams
(
store
.
state
.
teamlist
,
teams
.
invalid
)
currSessionMsgs
.
forEach
(
msg
=>
{
},
state
.
currSessionMsgs
.
unshift
(
msg
)
updateTeamUserMute
(
state
,
map
)
{
})
store
.
state
.
teamlist
.
forEach
(
x
=>
{
if
(
obj
.
msgs
[
0
])
{
if
(
map
[
x
.
teamId
]
!=
undefined
&&
map
[
x
.
teamId
]
!=
null
)
{
state
.
currSessionLastMsg
=
obj
.
msgs
[
0
]
x
.
usermute
=
map
[
x
.
teamId
]
==
'1'
}
}
}
})
},
},
getChatroomInfo
(
state
,
obj
)
{
updateTeamMembers
(
state
,
obj
)
{
state
.
currChatroomInfo
=
obj
const
nim
=
state
.
nim
},
var
teamId
=
obj
.
teamId
updateChatroomMembers
(
state
,
obj
)
{
var
members
=
obj
.
members
let
{
type
,
members
}
=
obj
state
.
teamMembers
=
state
.
teamMembers
||
{}
if
(
type
===
'destroy'
)
{
state
.
teamMembers
[
teamId
]
=
nim
.
mergeTeamMembers
(
state
.
teamMembers
[
teamId
],
members
)
state
.
currChatroomMembers
=
[]
state
.
teamMembers
[
teamId
]
=
nim
.
cutTeamMembers
(
state
.
teamMembers
[
teamId
],
members
.
invalid
)
}
else
if
(
type
===
'put'
)
{
state
.
teamMembers
[
teamId
].
sort
((
a
,
b
)
=>
{
members
.
forEach
(
member
=>
{
// 将群主和管理员排在队列前方
if
(
member
.
online
)
{
if
(
a
.
type
===
'owner'
||
b
.
type
===
'owner'
)
{
state
.
currChatroomMembers
.
push
(
member
)
return
a
.
type
===
'owner'
?
-
1
:
1
}
if
(
a
.
type
===
'manager'
||
b
.
type
===
'manager'
)
{
return
a
.
type
===
'manager'
?
-
1
:
b
.
type
===
'manager'
?
1
:
0
}
return
-
1
})
state
.
teamMembers
=
Object
.
assign
({},
state
.
teamMembers
)
},
removeTeamMembersByAccounts
(
state
,
obj
)
{
var
teamId
=
obj
.
teamId
var
invalidAccounts
=
obj
.
accounts
if
(
state
.
teamMembers
[
teamId
]
===
undefined
)
return
state
.
teamMembers
[
teamId
]
=
state
.
teamMembers
[
teamId
].
filter
((
member
,
index
)
=>
{
return
invalidAccounts
.
indexOf
(
member
.
account
)
===
-
1
})
state
.
teamMembers
=
Object
.
assign
({},
state
.
teamMembers
)
},
updateTeamInfo
(
state
,
team
)
{
var
index
=
state
.
teamlist
.
findIndex
(
item
=>
{
return
item
.
teamId
===
team
.
teamId
})
if
(
index
===
-
1
)
return
for
(
const
key
in
team
)
{
if
(
key
!==
'teamId'
&&
team
.
hasOwnProperty
(
key
)
&&
team
[
key
])
{
state
.
teamlist
[
index
][
key
]
=
team
[
key
]
}
}
},
updateTeamSettingConfig
(
state
,
obj
)
{
state
.
teamSettingConfig
=
obj
},
updateSentReceipedMap
(
state
,
obj
)
{
if
(
!
obj
||
obj
.
length
<
1
)
{
return
}
var
teamId
=
obj
[
0
].
teamId
if
(
!
state
.
sentReceipedMap
[
teamId
])
{
state
.
sentReceipedMap
[
teamId
]
=
[]
}
state
.
sentReceipedMap
[
teamId
].
push
(...
obj
.
map
(
msg
=>
msg
.
idServer
))
},
updateReceiptQueryList
(
state
,
obj
)
{
if
(
state
.
currReceiptQueryTeamId
!==
obj
.
teamId
)
{
state
.
receiptQueryList
=
[]
state
.
teamMsgReads
=
[]
state
.
currReceiptQueryTeamId
=
obj
.
teamId
}
var
needQuery
=
obj
.
msgs
.
filter
(
msg
=>
msg
.
needMsgReceipt
&&
msg
.
from
===
state
.
myInfo
.
account
&&
!
state
.
receiptQueryList
.
find
(
item
=>
item
.
idServer
===
msg
.
idServer
)
)
.
map
(
msg
=>
{
return
{
teamId
:
obj
.
teamId
,
idServer
:
msg
.
idServer
}
})
if
(
needQuery
.
length
>
0
)
{
state
.
receiptQueryList
.
push
(...
needQuery
)
}
if
(
needQuery
.
length
>
0
)
{
store
.
dispatch
(
'getTeamMsgReads'
,
needQuery
)
}
},
updateTeamMsgReads
(
state
,
obj
)
{
state
.
teamMsgReads
.
push
(...
obj
.
teamMsgReceipts
)
},
updateSingleTeamMsgReads
(
state
,
obj
)
{
state
.
teamMsgReads
.
forEach
(
item
=>
{
if
(
item
.
idServer
===
obj
.
idServer
)
{
item
.
unread
=
obj
.
unread
item
.
read
=
obj
.
read
}
})
// 更新已读未读账号列表
var
unreadAccounts
=
state
.
teamMsgReadsDetail
.
unreadAccounts
var
findIndex
=
unreadAccounts
.
findIndex
(
account
=>
account
===
obj
.
account
)
if
(
findIndex
>=
0
)
{
unreadAccounts
.
splice
(
findIndex
,
1
)
state
.
teamMsgReadsDetail
.
readAccounts
.
push
(
obj
.
account
)
}
}
})
},
}
initMsgReceiptDetail
(
state
,
obj
)
{
},
state
.
teamMsgReadsDetail
.
readAccounts
=
obj
.
readAccounts
updateTeamList
(
state
,
teams
)
{
state
.
teamMsgReadsDetail
.
unreadAccounts
=
obj
.
unreadAccounts
const
nim
=
state
.
nim
},
store
.
state
.
teamlist
=
nim
.
mergeTeams
(
store
.
state
.
teamlist
,
teams
)
}
store
.
state
.
teamlist
=
nim
.
cutTeams
(
store
.
state
.
teamlist
,
teams
.
invalid
)
\ No newline at end of file
},
updateTeamUserMute
(
state
,
map
)
{
store
.
state
.
teamlist
.
forEach
(
x
=>
{
if
(
map
[
x
.
teamId
]
!=
undefined
&&
map
[
x
.
teamId
]
!=
null
){
x
.
usermute
=
map
[
x
.
teamId
]
==
'1'
}
})
},
updateTeamMembers
(
state
,
obj
)
{
const
nim
=
state
.
nim
var
teamId
=
obj
.
teamId
var
members
=
obj
.
members
state
.
teamMembers
=
state
.
teamMembers
||
{}
state
.
teamMembers
[
teamId
]
=
nim
.
mergeTeamMembers
(
state
.
teamMembers
[
teamId
],
members
)
state
.
teamMembers
[
teamId
]
=
nim
.
cutTeamMembers
(
state
.
teamMembers
[
teamId
],
members
.
invalid
)
state
.
teamMembers
[
teamId
].
sort
((
a
,
b
)
=>
{
// 将群主和管理员排在队列前方
if
(
a
.
type
===
'owner'
||
b
.
type
===
'owner'
)
{
return
a
.
type
===
'owner'
?
-
1
:
1
}
if
(
a
.
type
===
'manager'
||
b
.
type
===
'manager'
)
{
return
a
.
type
===
'manager'
?
-
1
:
b
.
type
===
'manager'
?
1
:
0
}
return
-
1
})
state
.
teamMembers
=
Object
.
assign
({},
state
.
teamMembers
)
},
removeTeamMembersByAccounts
(
state
,
obj
)
{
var
teamId
=
obj
.
teamId
var
invalidAccounts
=
obj
.
accounts
if
(
state
.
teamMembers
[
teamId
]
===
undefined
)
return
state
.
teamMembers
[
teamId
]
=
state
.
teamMembers
[
teamId
].
filter
((
member
,
index
)
=>
{
return
invalidAccounts
.
indexOf
(
member
.
account
)
===-
1
})
state
.
teamMembers
=
Object
.
assign
({},
state
.
teamMembers
)
},
updateTeamInfo
(
state
,
team
)
{
var
index
=
state
.
teamlist
.
findIndex
(
item
=>
{
return
item
.
teamId
===
team
.
teamId
})
if
(
index
===
-
1
)
return
for
(
const
key
in
team
)
{
if
(
key
!==
'teamId'
&&
team
.
hasOwnProperty
(
key
)
&&
team
[
key
])
{
state
.
teamlist
[
index
][
key
]
=
team
[
key
]
}
}
},
updateTeamSettingConfig
(
state
,
obj
)
{
state
.
teamSettingConfig
=
obj
},
updateSentReceipedMap
(
state
,
obj
)
{
if
(
!
obj
||
obj
.
length
<
1
)
{
return
}
var
teamId
=
obj
[
0
].
teamId
if
(
!
state
.
sentReceipedMap
[
teamId
])
{
state
.
sentReceipedMap
[
teamId
]
=
[]
}
state
.
sentReceipedMap
[
teamId
].
push
(...
obj
.
map
(
msg
=>
msg
.
idServer
))
},
updateReceiptQueryList
(
state
,
obj
)
{
if
(
state
.
currReceiptQueryTeamId
!==
obj
.
teamId
)
{
state
.
receiptQueryList
=
[]
state
.
teamMsgReads
=
[]
state
.
currReceiptQueryTeamId
=
obj
.
teamId
}
var
needQuery
=
obj
.
msgs
.
filter
(
msg
=>
msg
.
needMsgReceipt
&&
msg
.
from
===
state
.
myInfo
.
account
&&
!
state
.
receiptQueryList
.
find
(
item
=>
item
.
idServer
===
msg
.
idServer
)
)
.
map
(
msg
=>
{
return
{
teamId
:
obj
.
teamId
,
idServer
:
msg
.
idServer
}
})
if
(
needQuery
.
length
>
0
)
{
state
.
receiptQueryList
.
push
(...
needQuery
)
}
if
(
needQuery
.
length
>
0
)
{
store
.
dispatch
(
'getTeamMsgReads'
,
needQuery
)
}
},
updateTeamMsgReads
(
state
,
obj
)
{
state
.
teamMsgReads
.
push
(...
obj
.
teamMsgReceipts
)
},
updateSingleTeamMsgReads
(
state
,
obj
)
{
state
.
teamMsgReads
.
forEach
(
item
=>
{
if
(
item
.
idServer
===
obj
.
idServer
)
{
item
.
unread
=
obj
.
unread
item
.
read
=
obj
.
read
}
})
// 更新已读未读账号列表
var
unreadAccounts
=
state
.
teamMsgReadsDetail
.
unreadAccounts
var
findIndex
=
unreadAccounts
.
findIndex
(
account
=>
account
===
obj
.
account
)
if
(
findIndex
>=
0
)
{
unreadAccounts
.
splice
(
findIndex
,
1
)
state
.
teamMsgReadsDetail
.
readAccounts
.
push
(
obj
.
account
)
}
},
initMsgReceiptDetail
(
state
,
obj
)
{
state
.
teamMsgReadsDetail
.
readAccounts
=
obj
.
readAccounts
state
.
teamMsgReadsDetail
.
unreadAccounts
=
obj
.
unreadAccounts
},
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment