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

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

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