workIMAction.js
4.9 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import * as types from '../constants/ActionTypes';
import { getRongCloudToken,getUserInfo} from '../../utils/workIMUtil';
import {message} from 'antd';
import store from 'store2';
export function changeIMShow(flag){
return {
type : types.CHANGE_IM_CHAT_STATE,
showChat : flag
}
}
export function getIMToken(data){ //获取开票类型
return dispatch => {
return getRongCloudToken(data)
.then(data => {
const {token='',app_key=''}=data;
dispatch({
type : types.LOAD_IM_TOKEN,
token : token,
appid : app_key
});
})
.catch(err => { throw err; });
};
}
export function addNewMessage(message,userMap,selecedUser,my){
const sdId=message.senderUserId;
const {senderUserId,content:{content=''},sentTime}=message;
return dispatch => {
return getUserInfo(senderUserId)
.then(data => {
let count=0;
if(userMap[senderUserId]){
count=userMap[senderUserId].messages.length;
if(senderUserId==selecedUser){
count=0;
}else{
count=userMap[senderUserId].count?userMap[senderUserId].count+1:1;
}
userMap[senderUserId].messages.push({
content,
sentTime,
senderUserId,
name:data.name,
type:'user'
})
}else{
if(senderUserId==selecedUser){
count=0;
}else{
count=count+1;
}
userMap[senderUserId]=message;
userMap[senderUserId].messages=[{
content,
sentTime,
senderUserId,
name:data.name,
type:'user'
}]
}
userMap[senderUserId].name=data.name;
userMap[senderUserId].mobile=data.mobile;
userMap[senderUserId].count=count;
dispatch({
type : types.LOAD_USER_MAP,
userMap : Object.assign({},userMap)
});
if(senderUserId==selecedUser){
dispatch({
type : types.CHANGE_MESSAGES,
messages : userMap[senderUserId].messages.concat([])
});
}
dispatch(changeIMShow(true));
store(my.id, Object.assign({},userMap));
})
.catch(err => { throw err; });
};
}
export function choiceMessage(message,userMap,dispatch,messages){
}
export function addMyMessage(message,senderUserId,userMap,user){
return dispatch => {
return new Promise((resolve, reject)=>{
setTimeout(() => {
if(userMap[senderUserId]&&userMap[senderUserId].messages){
userMap[senderUserId].messages.push({
content:message.content.content,
sentTime:message.sentTime,
senderUserId:message.senderUserId,
name:user.name,
type:'my'
});
dispatch({
type : types.CHANGE_MESSAGES,
selecedUser : senderUserId,
messages : userMap[senderUserId].messages.concat([])
});
}else if(userMap[selecedUser]){
userMap[senderUserId].messages=[{
content:message.content.content,
sentTime:message.sentTime,
senderUserId:message.senderUserId,
name:user.name,
type:'my'
}];
dispatch({
type : types.CHANGE_MESSAGES,
selecedUser : senderUserId,
messages : userMap[senderUserId].messages.concat([])
});
}
dispatch({
type : types.LOAD_USER_MAP,
userMap
});
resolve();
store(user.id, Object.assign({},userMap));
}, 200);
});
};
}
export function loadStoreMessage(id){
const tempDate=store(id)||{};
return {
type : types.LOAD_USER_MAP,
userMap : tempDate
}
}