/
forward.js
105 lines (91 loc) · 2.4 KB
/
forward.js
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
101
102
103
104
105
//collection.js
const state = {
rosterList: [],
groupList: [],
forwardMessage: null,
showForwardList: false
};
const getters = {
getRosterList(state) {
return state.rosterList;
},
getGroupList(state) {
return state.groupList;
},
getShowForwardList(state) {
return state.showForwardList;
}
};
const mutations = {
setRosterList(state, x) {
state.rosterList = x;
},
setGroupList(state, x) {
state.groupList = x;
},
setForwardMessage(state, x) {
state.forwardMessage = x;
},
setShowForwardList(state, x) {
state.showForwardList = x;
}
};
const actions = {
actionGetForwardList(context) {
const { rootState, state } = context;
if (!state.rosterList.length && !state.groupList.length) {
rootState.im.rosterManage.asyncGetRosterIdList().then((res) => {
rootState.im.rosterManage.asnycGetRosterListDetailByIds(res).then(() => {
const allMaps = rootState.im.rosterManage.getAllRosterDetail() || {};
const retObj = res.map((i) => {
const rosterInfo = allMaps[i] || { user_id: i };
return {
name: rosterInfo.username,
id: rosterInfo.user_id
};
});
context.commit('setRosterList', [].concat(retObj));
});
});
rootState.im.groupManage.asyncGetJoinedGroups(/**true**/).then((res) => {
res = res || [];
const retObj = res.map((i) => {
return {
name: i.name,
id: i.group_id
};
});
// this.forwardMembers.groupps = [].concat(retObj);
context.commit('setGroupList', [].concat(retObj));
});
}
},
actionRecordForwardMessage(context, x) {
// 记录要转发的message
context.commit('setForwardMessage', x);
context.commit('setShowForwardList', true);
},
actionForwardMessage(context, param) {
const { rootState, state } = context;
const { type, id: xid } = param; //type: group, roster; id: uid,gid
const fmsg = {};
if (type === 'roster') {
fmsg.uid = xid;
} else {
fmsg.gid = xid;
}
fmsg.mid = state.forwardMessage.id;
rootState.im.sysManage.forwardMessage(fmsg);
context.commit('setShowForwardList', false);
},
actionCancelForward(context) {
context.commit('setShowForwardList', false);
}
};
export default {
namespaced: true,
state,
getters,
mutations,
actions
};