1 |
- "use strict";app.controller("ChatCtrl",["$rootScope","$scope","api_text","SweetAlert",function(t,e,n,s){e.selfIdUser=null,e.otherIdUser=0,e.rid=void 0,e.chat=[],e.setOtherId=function(n,s){e.selfIdUser=t.me.id;var o=t.imUsrMap[n].unread.total>0?t.imUsrMap[n].unread.msgs:[],r=[];e.otherIdUser=n,angular.forEach(o,function(s){r.push({user:s.payload.sender.username,avatar:"assets/images/avatar-1.jpg",to:"我",date:s.date,content:s.text,idUser:e.selfIdUser||t.me.id,idOther:e.otherIdUser}),t.imUsrMap[n].unread.total-=1}),e.chat=e.chat.concat(r),e.rid=t.getDirectMsgRoomId(t.me.id,n),e.$$listenerCount[e.rid+"-msgs"]||e.$on(e.rid+"-msgs",function(t,n){t.preventDefault();var s=[];angular.forEach(n,function(t){s.push({user:t.u.username,avatar:"assets/images/avatar-1.jpg",to:"我",date:new Date(t.ts.$date),content:t.msg,idUser:e.selfIdUser,idOther:t.u._id})}),e.chat=e.chat.concat(s)}),e.$emit("openroom",{rid:e.rid,from:n},s.username)},e.closeRoom=function(){t.toggle("users","off"),e.$emit("closeroom")},e.$on("chatcloseroom",function(t,n){e.closeRoom()}),e.sendMessage=function(){t.sendMessage(e.rid,e.chatMessage,function(t){var n={user:"我",avatar:"assets/images/avatar-1.jpg",date:new Date,content:e.chatMessage,idUser:e.otherIdUser,idOther:e.selfIdUser};e.chat.push(n),e.chatMessage=""},function(t){})},e.login=!1,e.free=function(t,e){n.start(t).then(function(t){})},e.start=function(o,r){n.start(o).then(function(o){var a=o.token;t.takes=a,n.login(r,a).then(function(t){0==t.errno?(e.login=!0,s.swal({title:"登陆成功",text:"呼叫中心登陆成功!",type:"success"})):s.swal({title:"登陆失败",text:"请重新登陆!",type:"error"})})})},e.end=function(){n.logout(t.takes).then(function(o){0==o.errno&&n.exit(t.takes).then(function(t){0==t.errno?(e.login=!1,s.swal({title:"登出成功",text:"呼叫中心登出成功!",type:"success"})):s.swal({title:"登出失败",text:"呼叫中心登出失败!",type:"error"})})})},e.dialout=function(e,s){n.dialout(t.takes,e,s).then(function(t){0==t.errno})},e.busy=!1,e.setbusy=function(){n.setbusy(t.takes).then(function(t){0==t.errno&&(e.busy=!0)})},e.setidle=function(){n.setidle(t.takes).then(function(t){0==t.errno&&(e.busy=!1)})},e.inittrans=function(s){n.inittrans(s,t.takes).then(function(t){0==t.errno&&(e.busy=!1)})},e.comptrans=function(){n.comptrans(t.takes).then(function(t){0==t.errno&&(e.busy=!1)})},e.takeup=function(){n.offhook(t.takes).then(function(t){0==t.errno&&(e.busy=!1)})},e.takedown=function(){n.onhook(t.takes).then(function(t){0==t.errno&&(e.busy=!1)})}}]);
|