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,28 +4,28 @@ 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)
function connectNim({ state, commit, dispatch }, obj) {
let { force } = Object.assign({}, obj)
// 操作为内容页刷新页面,此时无nim实例
//
if (!state.nim || force) {
let loginuser= require('electron').remote.getGlobal("LOGINUSER");
let loginuser = require('electron').remote.getGlobal("LOGINUSER");
let loginInfo = {
uid: loginuser.ImAccount,
sdktoken:loginuser.ImToken,
sdktoken: loginuser.ImToken,
}
if (!loginInfo.uid) {
// 无cookie,直接跳转登录页
......@@ -37,14 +37,14 @@ function connectNim ({state, commit, dispatch}, obj) {
}
}
function connectChatroom ({state, commit, dispatch}, obj) {
let {chatroomId} = Object.assign({}, 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) {
done: function getChatroomAddressDone(error, obj) {
if (error) {
//alert(error.message)
//location.href = '#/room'
......@@ -57,7 +57,7 @@ function connectChatroom ({state, commit, dispatch}, obj) {
}
export default {
updateRefreshState ({commit}) {
updateRefreshState({ commit }) {
commit('updateRefreshState')
},
......@@ -69,8 +69,8 @@ export default {
continueRobotMsg,
// 连接sdk请求,false表示强制重连
connect (store, obj) {
let {type} = Object.assign({}, obj)
connect(store, obj) {
let { type } = Object.assign({}, obj)
// type 可为 nim chatroom
type = type || 'nim'
switch (type) {
......@@ -84,7 +84,7 @@ export default {
},
// 用户触发的登出逻辑
logout ({ state, commit }) {
logout({ state, commit }) {
cookie.delCookie('uid')
cookie.delCookie('sdktoken')
if (state.nim) {
......@@ -113,6 +113,7 @@ export default {
resetCurrSession,
// 发送消息
sendMsg,
forwardMsg,
sendTip,
sendFileMsg,
sendDataUrlMsg,
......
......@@ -2,7 +2,7 @@ import store from '../'
import config from '../../configs'
import util from '../../utils'
export function formatMsg (msg) {
export function formatMsg(msg) {
const nim = store.state.nim
if (msg.type === 'robot') {
if (msg.content && msg.content.flag === 'bot') {
......@@ -25,25 +25,25 @@ export function formatMsg (msg) {
return msg
}
export function onRoamingMsgs (obj) {
export function onRoamingMsgs(obj) {
let msgs = obj.msgs.map(msg => {
return formatMsg(msg)
})
store.commit('updateMsgs', msgs)
}
export function onOfflineMsgs (obj) {
export function onOfflineMsgs(obj) {
let msgs = obj.msgs.map(msg => {
return formatMsg(msg)
})
store.commit('updateMsgs', msgs)
}
export function onMutelist (mutelist){
export function onMutelist(mutelist) {
store.commit('updateMutelist', mutelist)
}
export function onMarkInMutelist (obj){
export function onMarkInMutelist(obj) {
console.log(obj.account + '被你' + (obj.isAdd ? '加入' : '移除') + '静音列表');
if (obj.isAdd) {
addToMutelist(obj);
......@@ -59,9 +59,9 @@ export function removeFromMutelist(obj) {
store.commit('removeFromMutelist', obj)
}
export function markInMutelist({state,commit}, obj){
export function markInMutelist({ state, commit }, obj) {
const nim = store.state.nim
let {account,isAdd,scene,to,name} = obj
let { account, isAdd, scene, to, name } = obj
nim.markInMutelist({
account,
isAdd,
......@@ -72,22 +72,34 @@ export function markInMutelist({state,commit}, obj){
});
}
export function sendTip ({state, commit}, obj) {
export function sendTip({ state, commit }, obj) {
const nim = store.state.nim
let isLocal='isLocal' in obj ? obj.isLocal : false
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) {
done: function sendTipMsgDone(error, msg) {
console.log(msg)
onMsg(msg)
}
})
}
export function onMsg (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)
}
})
}
export function onMsg(msg) {
msg = formatMsg(msg)
store.commit('putMsg', msg)
if (msg.sessionId === store.state.currSessionId) {
......@@ -98,29 +110,29 @@ export function onMsg (msg) {
// 发送已读回执
store.dispatch('sendMsgReceipt')
}
if (msg.scene === 'team' && msg.type ==='notification') {
if (msg.scene === 'team' && msg.type === 'notification') {
store.dispatch('onTeamNotificationMsg', msg)
}
}
function onSendMsgDone (error, 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)
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
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) {
done: function sendTipMsgDone(error, msg) {
onSendMsgDone(null, msg)
}
})
......@@ -129,7 +141,7 @@ function onSendMsgDone (error, msg) {
}
// 消息撤回
export function onRevocateMsg (error, msg) {
export function onRevocateMsg(error, msg) {
console.log('onRevocateMsg')
const nim = store.state.nim
if (error) {
......@@ -157,7 +169,7 @@ export function onRevocateMsg (error, msg) {
to: msg.to,
tip,
time: msg.time,
done: function sendTipMsgDone (error, tipMsg) {
done: function sendTipMsgDone(error, tipMsg) {
let idClient = msg.deletedIdClient || msg.idClient
store.commit('replaceMsg', {
sessionId: msg.sessionId,
......@@ -176,18 +188,18 @@ export function onRevocateMsg (error, msg) {
}
export function revocateMsg ({state, commit}, msg) {
export function revocateMsg({ state, commit }, msg) {
const nim = state.nim
let {idClient} = msg
let { idClient } = msg
msg = Object.assign(msg, state.msgsMap[idClient])
nim.deleteMsg({
msg,
done: function deleteMsgDone (error) {
done: function deleteMsgDone(error) {
onRevocateMsg(error, msg)
}
})
}
export function updateLocalMsg ({state, commit}, msg) {
export function updateLocalMsg({ state, commit }, msg) {
store.commit('updateCurrSessionMsgs', {
type: 'replace',
idClient: msg.idClient,
......@@ -205,7 +217,7 @@ export function updateLocalMsg ({state, commit}, msg) {
}
// 发送普通消息
export function sendMsg ({state, commit}, obj) {
export function sendMsg({ state, commit }, obj) {
const nim = state.nim
obj = obj || {}
let type = obj.type || ''
......@@ -225,8 +237,8 @@ export function sendMsg ({state, commit}, obj) {
scene: obj.scene,
to: obj.to,
text: obj.text,
done: function(err,msg){
obj.callbackTeam(obj.content,msg.idServer)
done: function(err, msg) {
obj.callbackTeam(obj.content, msg.idServer)
onMsg(msg)
},
needMsgReceipt: obj.needMsgReceipt || false,
......@@ -245,9 +257,9 @@ export function sendMsg ({state, commit}, obj) {
}
// 发送文件消息
export function sendFileMsg ({state, commit}, obj) {
export function sendFileMsg({ state, commit }, obj) {
const nim = state.nim
let { type,fileInput } = obj
let { type, fileInput } = obj
if (!type) {
type = 'file'
if (/\.(png|jpg|bmp|jpeg|gif)$/i.test(fileInput.value)) {
......@@ -262,10 +274,10 @@ export function sendFileMsg ({state, commit}, obj) {
store.dispatch('showLoading')
const data = Object.assign({
type,
uploadprogress: function (data) {
uploadprogress: function(data) {
// console.log(data.percentageText)
},
uploaderror: function () {
uploaderror: function() {
fileInput.value = ''
console && console.log('上传失败')
},
......@@ -274,20 +286,20 @@ export function sendFileMsg ({state, commit}, obj) {
// console.log(error);
// console.log(file);
},
beforesend: function (msg) {
beforesend: function(msg) {
// console && console.log('正在发送消息, id=', msg);
onMsg(msg);
},
done: function (error, msg) {
onSendMsgDone (error, 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
let {scene, to, dataURL, name,size,md5} = obj
let { scene, to, dataURL, name, size, md5 } = obj
let type = 'file'
if (/(png|jpg|bmp|jpeg|gif)$/i.test(name)) {
type = 'image'
......@@ -297,19 +309,19 @@ export function sendDataUrlMsg ({state, commit}, obj) {
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
"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"
"recentContent": name,
"Width": "210"
}
}
nim.sendFile({
......@@ -317,43 +329,43 @@ export function sendDataUrlMsg ({state, commit}, obj) {
to,
type,
dataURL,
fastPass:{md5},
fastPass: { md5 },
custom: JSON.stringify(customMsg),
uploadprogress: function (data) {
uploadprogress: function(data) {
console.log('正在发送消息, id=', data);
},
uploaderror: function () {
uploaderror: function() {
console && console.log('上传失败')
},
uploaddone: function (error, file) {
uploaddone: function(error, file) {
// console.log(error);
// console.log(file);
},
beforesend: function (msg) {},
done: function (error, msg) {
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
let {scene, to, dataURL, name,size,md5,type} = obj
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
"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"
"recentContent": name,
"Width": "210"
}
}
nim.sendFile({
......@@ -363,21 +375,21 @@ export function sendDataUrlMsgCall ({state, commit}, obj) {
dataURL,
custom: JSON.stringify(customMsg),
uploadprogress: obj.onUploadprogress,
uploaderror: function () {
uploaderror: function() {
console && console.log('上传失败')
},
uploaddone: obj.onUploaddone,
beforesend: function (msg) {},
done: function (error, msg) {
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
let {type, scene, to, robotAccid, content, params, target, body} = obj
let { type, scene, to, robotAccid, content, params, target, body } = obj
scene = scene || 'p2p'
if (type === 'text') {
nim.sendRobotMsg({
......@@ -419,7 +431,7 @@ export function sendRobotMsg ({state, commit}, obj) {
}
// 发送消息已读回执
export function sendMsgReceipt ({state, commit}) {
export function sendMsgReceipt({ state, commit }) {
// 如果有当前会话
let currSessionId = store.state.currSessionId
if (currSessionId) {
......@@ -430,7 +442,7 @@ export function sendMsgReceipt ({state, commit}) {
if (state.sessionMap[currSessionId]) {
nim.sendMsgReceipt({
msg: state.sessionMap[currSessionId].lastMsg,
done: function sendMsgReceiptDone (error, obj) {
done: function sendMsgReceiptDone(error, obj) {
// do something
}
})
......@@ -440,20 +452,20 @@ export function sendMsgReceipt ({state, commit}) {
}
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
if (nim) {
let {scene, to} = obj
let { scene, to } = obj
let options = {
scene,
to,
reverse: false,
asc: true,
limit: config.localMsglimit || 20,
done: function getHistoryMsgsDone (error, obj) {
done: function getHistoryMsgsDone(error, obj) {
if (obj.msgs) {
if (obj.msgs.length === 0) {
commit('setNoMoreHistoryMsgs')
......@@ -482,11 +494,11 @@ export function getHistoryMsgs ({state, commit}, obj) {
}
}
export function resetNoMoreHistoryMsgs ({commit}) {
export function resetNoMoreHistoryMsgs({ commit }) {
commit('resetNoMoreHistoryMsgs')
}
// 继续与机器人会话交互
export function continueRobotMsg ({commit}, 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