Commit 5de2722d authored by 华国豪's avatar 华国豪 🙄

Merge branch 'master' of http://gitlab.oytour.com/viitto/madara

parents e7754390 0d9bfe5b
...@@ -17,3 +17,4 @@ dist/ ...@@ -17,3 +17,4 @@ dist/
package/ package/
build/ build/
node_modules.rar node_modules.rar
node_modules.zip
...@@ -4,162 +4,163 @@ import cookie from '../../utils/cookie' ...@@ -4,162 +4,163 @@ import cookie from '../../utils/cookie'
import pageUtil from '../../utils/page' import pageUtil from '../../utils/page'
/* 导出actions方法 */ /* 导出actions方法 */
import {showLoading, hideLoading, showFullscreenImg, hideFullscreenImg} from './widgetUi' import { showLoading, hideLoading, showFullscreenImg, hideFullscreenImg } from './widgetUi'
import {initNimSDK} from './initNimSDK' import { initNimSDK } from './initNimSDK'
import {initChatroomSDK, resetChatroomSDK} from './initChatroomSDK' import { initChatroomSDK, resetChatroomSDK } from './initChatroomSDK'
import {updateBlack} from './blacks' import { updateBlack } from './blacks'
import {updateFriend, addFriend, deleteFriend} from './friends' import { updateFriend, addFriend, deleteFriend } from './friends'
import {resetSearchResult, searchUsers, searchTeam} from './search' import { resetSearchResult, searchUsers, searchTeam } from './search'
import {deleteSession, setCurrSession, resetCurrSession} from './session' import { deleteSession, setCurrSession, resetCurrSession } from './session'
import {sendMsg, sendTip,markInMutelist, sendFileMsg,sendDataUrlMsg,sendDataUrlMsgCall, sendMsgReceipt, sendRobotMsg, revocateMsg, updateLocalMsg, getHistoryMsgs, resetNoMoreHistoryMsgs, continueRobotMsg} from './msgs' import { sendMsg, sendTip, forwardMsg, markInMutelist, sendFileMsg, sendDataUrlMsg, sendDataUrlMsgCall, sendMsgReceipt, sendRobotMsg, revocateMsg, updateLocalMsg, getHistoryMsgs, resetNoMoreHistoryMsgs, continueRobotMsg } from './msgs'
import {markSysMsgRead, resetSysMsgs, deleteSysMsgs, markCustomSysMsgRead} from './sysMsgs' import { markSysMsgRead, resetSysMsgs, deleteSysMsgs, markCustomSysMsgRead } from './sysMsgs'
import {sendChatroomMsg, sendChatroomRobotMsg, sendChatroomFileMsg, getChatroomHistoryMsgs} from './chatroomMsgs' import { sendChatroomMsg, sendChatroomRobotMsg, sendChatroomFileMsg, getChatroomHistoryMsgs } from './chatroomMsgs'
import {initChatroomInfos, getChatroomInfo, getChatroomMembers, clearChatroomMembers} from './chatroomInfos' import { initChatroomInfos, getChatroomInfo, getChatroomMembers, clearChatroomMembers } from './chatroomInfos'
import { delegateTeamFunction, getNotifyForNewTeamMsg,onTeamNotificationMsg, enterSettingPage, getTeamMembers, checkTeamMsgReceipt, getTeamMsgReads} from './team' import { delegateTeamFunction, getNotifyForNewTeamMsg, onTeamNotificationMsg, enterSettingPage, getTeamMembers, checkTeamMsgReceipt, getTeamMsgReads } from './team'
function connectNim ({state, commit, dispatch}, obj) { function connectNim({ state, commit, dispatch }, obj) {
let {force} = Object.assign({}, obj) let { force } = Object.assign({}, obj)
// 操作为内容页刷新页面,此时无nim实例 // 操作为内容页刷新页面,此时无nim实例
// //
if (!state.nim || force) { if (!state.nim || force) {
let loginuser= require('electron').remote.getGlobal("LOGINUSER"); let loginuser = require('electron').remote.getGlobal("LOGINUSER");
let loginInfo = { let loginInfo = {
uid: loginuser.ImAccount, uid: loginuser.ImAccount,
sdktoken:loginuser.ImToken, sdktoken: loginuser.ImToken,
} }
if (!loginInfo.uid) { if (!loginInfo.uid) {
// 无cookie,直接跳转登录页 // 无cookie,直接跳转登录页
// pageUtil.turnPage('无历史登录记录,请重新登录', 'login') // pageUtil.turnPage('无历史登录记录,请重新登录', 'login')
} else { } else {
// 有cookie,重新登录 // 有cookie,重新登录
dispatch('initNimSDK', loginInfo) dispatch('initNimSDK', loginInfo)
}
} }
}
} }
function connectChatroom ({state, commit, dispatch}, obj) { function connectChatroom({ state, commit, dispatch }, obj) {
let {chatroomId} = Object.assign({}, obj) let { chatroomId } = Object.assign({}, obj)
const nim = state.nim const nim = state.nim
if (nim) { if (nim) {
dispatch('showLoading') dispatch('showLoading')
nim.getChatroomAddress({ nim.getChatroomAddress({
chatroomId, chatroomId,
done: function getChatroomAddressDone (error, obj) { done: function getChatroomAddressDone(error, obj) {
if (error) { if (error) {
//alert(error.message) //alert(error.message)
//location.href = '#/room' //location.href = '#/room'
return return
} }
dispatch('initChatroomSDK', obj) dispatch('initChatroomSDK', obj)
} }
}) })
} }
} }
export default { export default {
updateRefreshState ({commit}) { updateRefreshState({ commit }) {
commit('updateRefreshState') commit('updateRefreshState')
}, },
// UI 及页面状态变更 // UI 及页面状态变更
showLoading, showLoading,
hideLoading, hideLoading,
showFullscreenImg, showFullscreenImg,
hideFullscreenImg, hideFullscreenImg,
continueRobotMsg, continueRobotMsg,
// 连接sdk请求,false表示强制重连 // 连接sdk请求,false表示强制重连
connect (store, obj) { connect(store, obj) {
let {type} = Object.assign({}, obj) let { type } = Object.assign({}, obj)
// type 可为 nim chatroom // type 可为 nim chatroom
type = type || 'nim' type = type || 'nim'
switch (type) { switch (type) {
case 'nim': case 'nim':
connectNim(store, obj) connectNim(store, obj)
break break
case 'chatroom': case 'chatroom':
connectChatroom(store, obj) connectChatroom(store, obj)
break break
} }
}, },
// 用户触发的登出逻辑 // 用户触发的登出逻辑
logout ({ state, commit }) { logout({ state, commit }) {
cookie.delCookie('uid') cookie.delCookie('uid')
cookie.delCookie('sdktoken') cookie.delCookie('sdktoken')
if (state.nim) { if (state.nim) {
state.nim.disconnect() state.nim.disconnect()
} }
pageUtil.turnPage('', 'login') pageUtil.turnPage('', 'login')
}, },
// 初始化 重新连接SDK // 初始化 重新连接SDK
initNimSDK, initNimSDK,
// 清空所有搜索历史纪录 // 清空所有搜索历史纪录
resetSearchResult, resetSearchResult,
// 搜索用户信息 // 搜索用户信息
searchUsers, searchUsers,
// 更新黑名单 // 更新黑名单
updateBlack, updateBlack,
// 更新好友 // 更新好友
addFriend, addFriend,
deleteFriend, deleteFriend,
updateFriend, updateFriend,
// 删除会话 // 删除会话
deleteSession, deleteSession,
// 设置当前会话 // 设置当前会话
setCurrSession, setCurrSession,
// 重置当前会话 // 重置当前会话
resetCurrSession, resetCurrSession,
// 发送消息 // 发送消息
sendMsg, sendMsg,
sendTip, forwardMsg,
sendFileMsg, sendTip,
sendDataUrlMsg, sendFileMsg,
sendDataUrlMsgCall, sendDataUrlMsg,
markInMutelist, sendDataUrlMsgCall,
sendRobotMsg, markInMutelist,
// 发送消息已读回执 sendRobotMsg,
sendMsgReceipt, // 发送消息已读回执
// 消息撤回 sendMsgReceipt,
revocateMsg, // 消息撤回
// 更新本地消息 revocateMsg,
updateLocalMsg, // 更新本地消息
getHistoryMsgs, updateLocalMsg,
// 重置历史消息状态 getHistoryMsgs,
resetNoMoreHistoryMsgs, // 重置历史消息状态
// 标记系统消息已读 resetNoMoreHistoryMsgs,
markSysMsgRead, // 标记系统消息已读
markCustomSysMsgRead, markSysMsgRead,
resetSysMsgs, markCustomSysMsgRead,
deleteSysMsgs, resetSysMsgs,
deleteSysMsgs,
initChatroomSDK, initChatroomSDK,
initChatroomInfos, initChatroomInfos,
resetChatroomSDK, resetChatroomSDK,
sendChatroomMsg, sendChatroomMsg,
sendChatroomRobotMsg, sendChatroomRobotMsg,
sendChatroomFileMsg, sendChatroomFileMsg,
getChatroomHistoryMsgs, getChatroomHistoryMsgs,
getChatroomInfo, getChatroomInfo,
getChatroomMembers, getChatroomMembers,
clearChatroomMembers, clearChatroomMembers,
// 搜索群 // 搜索群
searchTeam, searchTeam,
// 代理sdk中的群方法 // 代理sdk中的群方法
delegateTeamFunction, delegateTeamFunction,
// 处理群消息回调 // 处理群消息回调
onTeamNotificationMsg, onTeamNotificationMsg,
getNotifyForNewTeamMsg, getNotifyForNewTeamMsg,
// 进入群信息设置页 // 进入群信息设置页
enterSettingPage, enterSettingPage,
// 获取群成员 // 获取群成员
getTeamMembers, getTeamMembers,
// 群消息回执检查 // 群消息回执检查
checkTeamMsgReceipt, checkTeamMsgReceipt,
// 查询群消息回执已读列表 // 查询群消息回执已读列表
getTeamMsgReads, getTeamMsgReads,
} }
\ No newline at end of file
...@@ -2,491 +2,503 @@ import store from '../' ...@@ -2,491 +2,503 @@ import store from '../'
import config from '../../configs' import config from '../../configs'
import util from '../../utils' import util from '../../utils'
export function formatMsg (msg) { export function formatMsg(msg) {
const nim = store.state.nim const nim = store.state.nim
if (msg.type === 'robot') { if (msg.type === 'robot') {
if (msg.content && msg.content.flag === 'bot') { if (msg.content && msg.content.flag === 'bot') {
if (msg.content.message) { if (msg.content.message) {
msg.content.message = msg.content.message.map(item => { msg.content.message = msg.content.message.map(item => {
switch (item.type) { switch (item.type) {
case 'template': case 'template':
item.content = nim.parseRobotTemplate(item.content) item.content = nim.parseRobotTemplate(item.content)
break break
case 'text': case 'text':
case 'image': case 'image':
case 'answer': case 'answer':
break break
} }
return item return item
}) })
} }
}
} }
} return msg
return msg
} }
export function onRoamingMsgs (obj) { export function onRoamingMsgs(obj) {
let msgs = obj.msgs.map(msg => { let msgs = obj.msgs.map(msg => {
return formatMsg(msg) return formatMsg(msg)
}) })
store.commit('updateMsgs', msgs) store.commit('updateMsgs', msgs)
} }
export function onOfflineMsgs (obj) { export function onOfflineMsgs(obj) {
let msgs = obj.msgs.map(msg => { let msgs = obj.msgs.map(msg => {
return formatMsg(msg) return formatMsg(msg)
}) })
store.commit('updateMsgs', msgs) store.commit('updateMsgs', msgs)
} }
export function onMutelist (mutelist){ export function onMutelist(mutelist) {
store.commit('updateMutelist', mutelist) store.commit('updateMutelist', mutelist)
} }
export function onMarkInMutelist (obj){ export function onMarkInMutelist(obj) {
console.log(obj.account + '被你' + (obj.isAdd ? '加入' : '移除') + '静音列表'); console.log(obj.account + '被你' + (obj.isAdd ? '加入' : '移除') + '静音列表');
if (obj.isAdd) { if (obj.isAdd) {
addToMutelist(obj); addToMutelist(obj);
} else { } else {
removeFromMutelist(obj); removeFromMutelist(obj);
} }
} }
export function addToMutelist(obj) { export function addToMutelist(obj) {
store.commit('addToMutelist', obj) store.commit('addToMutelist', obj)
} }
export function removeFromMutelist(obj) { export function removeFromMutelist(obj) {
store.commit('removeFromMutelist', obj) store.commit('removeFromMutelist', obj)
} }
export function markInMutelist({state,commit}, obj){ export function markInMutelist({ state, commit }, obj) {
const nim = store.state.nim const nim = store.state.nim
let {account,isAdd,scene,to,name} = obj let { account, isAdd, scene, to, name } = obj
nim.markInMutelist({ nim.markInMutelist({
account, account,
isAdd, isAdd,
done: function markInMutelistDone(error, obj) { done: function markInMutelistDone(error, obj) {
console.log(error) console.log(error)
onMarkInMutelist(obj) onMarkInMutelist(obj)
} }
}); });
} }
export function sendTip ({state, commit}, obj) { export function sendTip({ state, commit }, obj) {
const nim = store.state.nim const nim = store.state.nim
let isLocal='isLocal' in obj ? obj.isLocal : false let isLocal = 'isLocal' in obj ? obj.isLocal : false
nim.sendTipMsg({ nim.sendTipMsg({
scene: obj.scene, scene: obj.scene,
to: obj.to, to: obj.to,
tip: obj.tip, tip: obj.tip,
isLocal, isLocal,
done: function sendTipMsgDone (error, msg) { done: function sendTipMsgDone(error, msg) {
console.log(msg) console.log(msg)
onMsg(msg) onMsg(msg)
} }
}) })
} }
export function onMsg (msg) { export function forwardMsg({ state, commit }, obj) {
msg = formatMsg(msg) const nim = store.state.nim
store.commit('putMsg', msg) nim.forwardMsg({
if (msg.sessionId === store.state.currSessionId) { scene: obj.scene,
store.commit('updateCurrSessionMsgs', { to: obj.to,
type: 'put', msg: obj.tip,
msg done: function(err, msg) {
onMsg(msg)
}
}) })
// 发送已读回执
store.dispatch('sendMsgReceipt')
}
if (msg.scene === 'team' && msg.type ==='notification') {
store.dispatch('onTeamNotificationMsg', msg)
}
} }
function onSendMsgDone (error, msg) { export function onMsg(msg) {
store.dispatch('hideLoading') msg = formatMsg(msg)
if (error) { store.commit('putMsg', msg)
// 被拉黑 if (msg.sessionId === store.state.currSessionId) {
msg.error=error.message store.commit('updateCurrSessionMsgs', {
let errMsgArray=[] type: 'put',
if(window.localStorage.errorMsg){ msg
errMsgArray=JSON.parse(window.localStorage.errorMsg) })
// 发送已读回执
store.dispatch('sendMsgReceipt')
} }
errMsgArray.push(msg.idClient) if (msg.scene === 'team' && msg.type === 'notification') {
window.localStorage.errorMsg=JSON.stringify(errMsgArray) store.dispatch('onTeamNotificationMsg', msg)
let errorString=error.message }
errorString=errorString.indexOf(": ")!=-1?errorString.split(": ")[1]:errorString }
nim.sendTipMsg({
scene: msg.scene, function onSendMsgDone(error, msg) {
to: msg.to, store.dispatch('hideLoading')
tip: errorString, if (error) {
done: function sendTipMsgDone (error, msg) { // 被拉黑
onSendMsgDone(null, msg) msg.error = error.message
} let errMsgArray = []
}) if (window.localStorage.errorMsg) {
} errMsgArray = JSON.parse(window.localStorage.errorMsg)
onMsg(msg) }
errMsgArray.push(msg.idClient)
window.localStorage.errorMsg = JSON.stringify(errMsgArray)
let errorString = error.message
errorString = errorString.indexOf(": ") != -1 ? errorString.split(": ")[1] : errorString
nim.sendTipMsg({
scene: msg.scene,
to: msg.to,
tip: errorString,
done: function sendTipMsgDone(error, msg) {
onSendMsgDone(null, msg)
}
})
}
onMsg(msg)
} }
// 消息撤回 // 消息撤回
export function onRevocateMsg (error, msg) { export function onRevocateMsg(error, msg) {
console.log('onRevocateMsg') console.log('onRevocateMsg')
const nim = store.state.nim const nim = store.state.nim
if (error) { if (error) {
if (error.code === 508) { if (error.code === 508) {
util.showTips('发送时间超过2分钟的消息,不能被撤回') util.showTips('发送时间超过2分钟的消息,不能被撤回')
} else { } else {
util.showTips(error) util.showTips(error)
}
return
} }
return let tip = ''
} if (msg.from === store.state.userUID) {
let tip = '' tip = '你撤回了一条消息'
if (msg.from === store.state.userUID) {
tip = '你撤回了一条消息'
} else {
let userInfo = store.state.userInfos[msg.from]
if (userInfo) {
tip = `${util.getFriendAlias(userInfo)}撤回了一条消息`
} else { } else {
tip = '对方撤回了一条消息' let userInfo = store.state.userInfos[msg.from]
} if (userInfo) {
} tip = `${util.getFriendAlias(userInfo)}撤回了一条消息`
nim.sendTipMsg({ } else {
isLocal: true, tip = '对方撤回了一条消息'
scene: msg.scene, }
to: msg.to,
tip,
time: msg.time,
done: function sendTipMsgDone (error, tipMsg) {
let idClient = msg.deletedIdClient || msg.idClient
store.commit('replaceMsg', {
sessionId: msg.sessionId,
idClient,
msg: tipMsg
})
if (msg.sessionId === store.state.currSessionId) {
store.commit('updateCurrSessionMsgs', {
type: 'replace',
idClient,
msg: tipMsg
})
}
} }
}) nim.sendTipMsg({
isLocal: true,
scene: msg.scene,
to: msg.to,
tip,
time: msg.time,
done: function sendTipMsgDone(error, tipMsg) {
let idClient = msg.deletedIdClient || msg.idClient
store.commit('replaceMsg', {
sessionId: msg.sessionId,
idClient,
msg: tipMsg
})
if (msg.sessionId === store.state.currSessionId) {
store.commit('updateCurrSessionMsgs', {
type: 'replace',
idClient,
msg: tipMsg
})
}
}
})
} }
export function revocateMsg ({state, commit}, msg) { export function revocateMsg({ state, commit }, msg) {
const nim = state.nim const nim = state.nim
let {idClient} = msg let { idClient } = msg
msg = Object.assign(msg, state.msgsMap[idClient]) msg = Object.assign(msg, state.msgsMap[idClient])
nim.deleteMsg({ nim.deleteMsg({
msg, msg,
done: function deleteMsgDone (error) { done: function deleteMsgDone(error) {
onRevocateMsg(error, msg) onRevocateMsg(error, msg)
} }
}) })
} }
export function updateLocalMsg ({state, commit}, msg) { export function updateLocalMsg({ state, commit }, msg) {
store.commit('updateCurrSessionMsgs', { store.commit('updateCurrSessionMsgs', {
type: 'replace', type: 'replace',
idClient: msg.idClient, idClient: msg.idClient,
msg: msg msg: msg
}) })
state.nim.updateLocalMsg({ state.nim.updateLocalMsg({
idClient: msg.idClient, idClient: msg.idClient,
localCustom: msg.localCustom localCustom: msg.localCustom
}) })
store.commit('replaceMsg', { store.commit('replaceMsg', {
sessionId: msg.sessionId, sessionId: msg.sessionId,
idClient: msg.idClient, idClient: msg.idClient,
msg: msg msg: msg
}) })
} }
// 发送普通消息 // 发送普通消息
export function sendMsg ({state, commit}, obj) { export function sendMsg({ state, commit }, obj) {
const nim = state.nim const nim = state.nim
obj = obj || {} obj = obj || {}
let type = obj.type || '' let type = obj.type || ''
store.dispatch('showLoading') store.dispatch('showLoading')
switch (type) { switch (type) {
case 'text': case 'text':
nim.sendText({ nim.sendText({
scene: obj.scene, scene: obj.scene,
to: obj.to, to: obj.to,
text: obj.text, text: obj.text,
done: onSendMsgDone, done: onSendMsgDone,
needMsgReceipt: obj.needMsgReceipt || false needMsgReceipt: obj.needMsgReceipt || false
}) })
break break
case 'at': case 'at':
nim.sendText({ nim.sendText({
scene: obj.scene, scene: obj.scene,
to: obj.to, to: obj.to,
text: obj.text, text: obj.text,
done: function(err,msg){ done: function(err, msg) {
obj.callbackTeam(obj.content,msg.idServer) obj.callbackTeam(obj.content, msg.idServer)
onMsg(msg) onMsg(msg)
}, },
needMsgReceipt: obj.needMsgReceipt || false, needMsgReceipt: obj.needMsgReceipt || false,
custom: JSON.stringify(obj.content) custom: JSON.stringify(obj.content)
}) })
break break
case 'custom': case 'custom':
nim.sendCustomMsg({ nim.sendCustomMsg({
scene: obj.scene, scene: obj.scene,
to: obj.to, to: obj.to,
pushContent: obj.pushContent, pushContent: obj.pushContent,
content: JSON.stringify(obj.content), content: JSON.stringify(obj.content),
done: onSendMsgDone done: onSendMsgDone
}) })
} }
} }
// 发送文件消息 // 发送文件消息
export function sendFileMsg ({state, commit}, obj) { export function sendFileMsg({ state, commit }, obj) {
const nim = state.nim const nim = state.nim
let { type,fileInput } = obj let { type, fileInput } = obj
if (!type) { if (!type) {
type = 'file' type = 'file'
if (/\.(png|jpg|bmp|jpeg|gif)$/i.test(fileInput.value)) { if (/\.(png|jpg|bmp|jpeg|gif)$/i.test(fileInput.value)) {
type = 'image' type = 'image'
} else if (/\.(mov|mp4|ogg|webm)$/i.test(fileInput.value)) { } else if (/\.(mov|mp4|ogg|webm)$/i.test(fileInput.value)) {
type = 'video' type = 'video'
} else if (/\.(wav|mp3|wma)$/i.test(fileInput.value)) { } else if (/\.(wav|mp3|wma)$/i.test(fileInput.value)) {
type = 'file' type = 'file'
} }
}
store.dispatch('showLoading')
const data = Object.assign({
type,
uploadprogress: function (data) {
// console.log(data.percentageText)
},
uploaderror: function () {
fileInput.value = ''
console && console.log('上传失败')
},
uploaddone: function(error, file) {
fileInput.value = ''
// console.log(error);
// console.log(file);
},
beforesend: function (msg) {
// console && console.log('正在发送消息, id=', msg);
onMsg(msg);
},
done: function (error, msg) {
onSendMsgDone (error, msg)
} }
}, obj) store.dispatch('showLoading')
nim.sendFile(data) const data = Object.assign({
type,
uploadprogress: function(data) {
// console.log(data.percentageText)
},
uploaderror: function() {
fileInput.value = ''
console && console.log('上传失败')
},
uploaddone: function(error, file) {
fileInput.value = ''
// console.log(error);
// console.log(file);
},
beforesend: function(msg) {
// console && console.log('正在发送消息, id=', msg);
onMsg(msg);
},
done: function(error, msg) {
onSendMsgDone(error, msg)
}
}, obj)
nim.sendFile(data)
} }
export function sendDataUrlMsg ({state, commit}, obj) { export function sendDataUrlMsg({ state, commit }, obj) {
const nim = state.nim const nim = state.nim
let {scene, to, dataURL, name,size,md5} = obj let { scene, to, dataURL, name, size, md5 } = obj
let type = 'file' let type = 'file'
if (/(png|jpg|bmp|jpeg|gif)$/i.test(name)) { if (/(png|jpg|bmp|jpeg|gif)$/i.test(name)) {
type = 'image' type = 'image'
} else if (/(mov|mp4|ogg|webm)$/i.test(name)) { } else if (/(mov|mp4|ogg|webm)$/i.test(name)) {
type = 'video' type = 'video'
} else if (/\.(wav|mp3|wma)$/i.test(name)) { } else if (/\.(wav|mp3|wma)$/i.test(name)) {
type = 'file' type = 'file'
}
let customMsg = {
"msgtype":"custom_file",
"data":{
"pushContent":name,
"Height":"84",
"content":{
"fileType":name.substring(name.lastIndexOf('.')+1,name.length),
"fileUrl":"-1",
"fileName":name,
"fileSize":size,
'md5':md5
},
"recentContent":name,
"Width":"210"
} }
} let customMsg = {
nim.sendFile({ "msgtype": "custom_file",
scene, "data": {
to, "pushContent": name,
type, "Height": "84",
dataURL, "content": {
fastPass:{md5}, "fileType": name.substring(name.lastIndexOf('.') + 1, name.length),
custom: JSON.stringify(customMsg), "fileUrl": "-1",
uploadprogress: function (data) { "fileName": name,
console.log('正在发送消息, id=', data); "fileSize": size,
}, 'md5': md5
uploaderror: function () { },
console && console.log('上传失败') "recentContent": name,
}, "Width": "210"
uploaddone: function (error, file) { }
// console.log(error);
// console.log(file);
},
beforesend: function (msg) {},
done: function (error, msg) {
onSendMsgDone(error, msg)
} }
}) nim.sendFile({
scene,
to,
type,
dataURL,
fastPass: { md5 },
custom: JSON.stringify(customMsg),
uploadprogress: function(data) {
console.log('正在发送消息, id=', data);
},
uploaderror: function() {
console && console.log('上传失败')
},
uploaddone: function(error, file) {
// console.log(error);
// console.log(file);
},
beforesend: function(msg) {},
done: function(error, msg) {
onSendMsgDone(error, msg)
}
})
} }
export function sendDataUrlMsgCall ({state, commit}, obj) { export function sendDataUrlMsgCall({ state, commit }, obj) {
const nim = state.nim const nim = state.nim
let {scene, to, dataURL, name,size,md5,type} = obj let { scene, to, dataURL, name, size, md5, type } = obj
console.log(obj) console.log(obj)
let customMsg = { let customMsg = {
"msgtype":"custom_file", "msgtype": "custom_file",
"data":{ "data": {
"pushContent":name, "pushContent": name,
"Height":"84", "Height": "84",
"content":{ "content": {
"fileType":name.substring(name.lastIndexOf('.')+1,name.length), "fileType": name.substring(name.lastIndexOf('.') + 1, name.length),
"fileUrl":"-1", "fileUrl": "-1",
"fileName":name, "fileName": name,
"fileSize":size, "fileSize": size,
'md5':md5 'md5': md5
}, },
"recentContent":name, "recentContent": name,
"Width":"210" "Width": "210"
} }
}
nim.sendFile({
scene,
to,
type,
dataURL,
custom: JSON.stringify(customMsg),
uploadprogress: obj.onUploadprogress,
uploaderror: function () {
console && console.log('上传失败')
},
uploaddone: obj.onUploaddone,
beforesend: function (msg) {},
done: function (error, msg) {
onSendMsgDone(error, msg)
} }
}) nim.sendFile({
scene,
to,
type,
dataURL,
custom: JSON.stringify(customMsg),
uploadprogress: obj.onUploadprogress,
uploaderror: function() {
console && console.log('上传失败')
},
uploaddone: obj.onUploaddone,
beforesend: function(msg) {},
done: function(error, msg) {
onSendMsgDone(error, msg)
}
})
} }
// 发送机器人消息 // 发送机器人消息
export function sendRobotMsg ({state, commit}, obj) { export function sendRobotMsg({ state, commit }, obj) {
const nim = state.nim const nim = state.nim
let {type, scene, to, robotAccid, content, params, target, body} = obj let { type, scene, to, robotAccid, content, params, target, body } = obj
scene = scene || 'p2p' scene = scene || 'p2p'
if (type === 'text') { if (type === 'text') {
nim.sendRobotMsg({ nim.sendRobotMsg({
scene, scene,
to, to,
robotAccid: robotAccid || to, robotAccid: robotAccid || to,
content: { content: {
type: 'text', type: 'text',
content, content,
}, },
body, body,
done: onSendMsgDone done: onSendMsgDone
}) })
} else if (type === 'welcome') { } else if (type === 'welcome') {
nim.sendRobotMsg({ nim.sendRobotMsg({
scene, scene,
to, to,
robotAccid: robotAccid || to, robotAccid: robotAccid || to,
content: { content: {
type: 'welcome', type: 'welcome',
}, },
body, body,
done: onSendMsgDone done: onSendMsgDone
}) })
} else if (type === 'link') { } else if (type === 'link') {
nim.sendRobotMsg({ nim.sendRobotMsg({
scene, scene,
to, to,
robotAccid: robotAccid || to, robotAccid: robotAccid || to,
content: { content: {
type: 'link', type: 'link',
params, params,
target target
}, },
body, body,
done: onSendMsgDone done: onSendMsgDone
}) })
} }
} }
// 发送消息已读回执 // 发送消息已读回执
export function sendMsgReceipt ({state, commit}) { export function sendMsgReceipt({ state, commit }) {
// 如果有当前会话 // 如果有当前会话
let currSessionId = store.state.currSessionId let currSessionId = store.state.currSessionId
if (currSessionId) { if (currSessionId) {
// 只有点对点消息才发已读回执 // 只有点对点消息才发已读回执
if (util.parseSession(currSessionId).scene === 'p2p') { if (util.parseSession(currSessionId).scene === 'p2p') {
let msgs = store.state.currSessionMsgs let msgs = store.state.currSessionMsgs
const nim = state.nim const nim = state.nim
if (state.sessionMap[currSessionId]) { if (state.sessionMap[currSessionId]) {
nim.sendMsgReceipt({ nim.sendMsgReceipt({
msg: state.sessionMap[currSessionId].lastMsg, msg: state.sessionMap[currSessionId].lastMsg,
done: function sendMsgReceiptDone (error, obj) { done: function sendMsgReceiptDone(error, obj) {
// do something // do something
} }
}) })
} }
}
} }
}
} }
function sendMsgReceiptDone(error, obj) { function sendMsgReceiptDone(error, obj) {
console.log('发送消息已读回执' + (!error?'成功':'失败'), error, obj); console.log('发送消息已读回执' + (!error ? '成功' : '失败'), error, obj);
} }
export function getHistoryMsgs ({state, commit}, obj) { export function getHistoryMsgs({ state, commit }, obj) {
const nim = state.nim const nim = state.nim
if (nim) { if (nim) {
let {scene, to} = obj let { scene, to } = obj
let options = { let options = {
scene, scene,
to, to,
reverse: false, reverse: false,
asc: true, asc: true,
limit: config.localMsglimit || 20, limit: config.localMsglimit || 20,
done: function getHistoryMsgsDone (error, obj) { done: function getHistoryMsgsDone(error, obj) {
if (obj.msgs) { if (obj.msgs) {
if (obj.msgs.length === 0) { if (obj.msgs.length === 0) {
commit('setNoMoreHistoryMsgs') commit('setNoMoreHistoryMsgs')
} else { } else {
let msgs = obj.msgs.map(msg => { let msgs = obj.msgs.map(msg => {
return formatMsg(msg) return formatMsg(msg)
}) })
console.log(msgs) console.log(msgs)
commit('updateCurrSessionMsgs', { commit('updateCurrSessionMsgs', {
type: 'concat', type: 'concat',
msgs: msgs msgs: msgs
})
}
}
store.dispatch('hideLoading')
}
}
if (state.currSessionLastMsg) {
options = Object.assign(options, {
lastMsgId: state.currSessionLastMsg.idServer,
endTime: state.currSessionLastMsg.time,
}) })
}
} }
store.dispatch('hideLoading') store.dispatch('showLoading')
} nim.getHistoryMsgs(options)
}
if (state.currSessionLastMsg) {
options = Object.assign(options, {
lastMsgId: state.currSessionLastMsg.idServer,
endTime: state.currSessionLastMsg.time,
})
} }
store.dispatch('showLoading')
nim.getHistoryMsgs(options)
}
} }
export function resetNoMoreHistoryMsgs ({commit}) { export function resetNoMoreHistoryMsgs({ commit }) {
commit('resetNoMoreHistoryMsgs') commit('resetNoMoreHistoryMsgs')
} }
// 继续与机器人会话交互 // 继续与机器人会话交互
export function continueRobotMsg ({commit}, robotAccid) { export function continueRobotMsg({ commit }, robotAccid) {
commit('continueRobotMsg', robotAccid) commit('continueRobotMsg', robotAccid)
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment