sysMsgs.js
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import store from '../'
import {onUpdateFriend, onDeleteFriend} from './friends'
import {onRevocateMsg} from './msgs'
export function onSysMsgs (sysMsgs) {
store.commit('updateSysMsgs', sysMsgs)
}
export function onSysMsg (sysMsg) {
switch (sysMsg.type) {
// 在其他端添加或删除好友
case 'addFriend':
onUpdateFriend(null, {
account: sysMsg.from
})
store.commit('updateSysMsgs', [sysMsg])
break
case 'deleteFriend':
onDeleteFriend(null, {
account: sysMsg.from
})
break
// 对方消息撤回
case 'deleteMsg':
if(sysMsg.scene === 'p2p') {
sysMsg.sessionId = `p2p-${sysMsg.from}`
} else {
sysMsg.sessionId = `team-${sysMsg.to}`
}
onRevocateMsg(null, sysMsg)
break
case 'teamInvite': //被邀请入群
case 'applyTeam': // 申请入群
case 'rejectTeamApply': // 申请入群被拒绝
case 'rejectTeamInvite': // 拒绝入群邀请
store.commit('updateSysMsgs', [sysMsg])
break
}
store.commit('updateSysMsgState', sysMsg)
}
export function onSysMsgUnread (obj) {
store.commit('updateSysMsgUnread', obj)
}
export function onCustomSysMsgs (customSysMsgs) {
console.log(customSysMsgs)
if (!Array.isArray(customSysMsgs)) {
customSysMsgs = [customSysMsgs]
}
customSysMsgs = customSysMsgs.filter(msg => {
if (msg.type === 'custom') {
if (msg.content) {
try {
let content = JSON.parse(msg.content)
// 消息正在输入中
if ((content.id + '') === '1') {
return false
}
} catch (e) {}
}
}
return true
})
if (customSysMsgs.length > 0) {
store.commit('updateCustomSysMsgs', customSysMsgs)
}
}
// 不传obj则全部重置
export function markSysMsgRead ({state, commit}, obj) {
const nim = state.nim
let sysMsgs = []
if (obj && obj.sysMsgs) {
sysMsgs = obj.sysMsgs
} else {
sysMsgs = state.sysMsgs
}
if (Array.isArray(sysMsgs) && sysMsgs.length > 0) {
nim.markSysMsgRead({
sysMsgs,
done: function (error, obj) {
}
})
}
}
export function markCustomSysMsgRead ({state, commit}) {
commit('updateCustomSysMsgUnread', {
type: 'reset'
})
}
export function resetSysMsgs ({state, commit}, obj) {
commit('resetSysMsgs', obj)
}
export function deleteSysMsgs({commit}, obj) {
commit('deleteSysMsgs', obj)
}