UNPKG

unserver-unify

Version:

158 lines (151 loc) 4.45 kB
'use strict'; angular.module('bamboo.mystudy').controller('MessageThreadCtrl', function( $stateParams, CommonService, ApiService, $translate) { var self = this; var target = $stateParams.target; this.targetUser; this.tab = 'p2p'; this.messages = []; this.sysMessages = []; ApiService.get("/useravatar/" + target).then(function(result) { if (result.data.success) { self.targetUser = result.data.data; self.targetUser.avatarUrl = CommonService.getAvatarSrc(self.targetUser); console.log(self.targetUser) } }) getTargetThreadMsgs(); function getDisplayInfo(info) { switch (info.type) { case 'reply': case 'blogreply': case 'bbsreply': case 'feedbackreply': case 'feedbackreply': info.icon = "fa fa-commenting-o"; info.action = "Reply"; break; case 'accesscard': info.icon = "fa fa-sign-in"; info.action = "CardRecord"; break; case 'announcement': info.icon = "fa fa-bullhorn"; info.action = "Announced"; break; case 'courseapply': info.icon = "fa fa-tasks"; info.action = "Apply for Course Public Access"; break; case 'follow': info.icon = "fa fa-user"; info.action = "Follow"; break; case 'p2p': info.icon = "fa fa-envelope-o"; info.action = "MSG"; break; case 'Following': info.icon = "fa fa-envelope-o"; info.action = "Following User"; break; case 'course': info.icon = "fa fa-book"; info.action = "COURSE"; break; case 'feedback': info.icon = "fa fa-envelope-o"; info.action = "Feedback"; break; default: console.log("-- unknown type"); break; } return info; } function sortByTime(a, b) { var atime = new Date(a.time); var btime = new Date(b.time); return atime - btime; } function getTargetThreadMsgs() { var info = { action: 'getusertargemsgs', target: target, } console.log(info); ApiService.post("/messages", info).then(function(result) { // console.log(result); if (result.data.success) { console.log(result.data.data); var messages = result.data.data; self.messages = []; self.sysMessages = []; angular.forEach(messages, function(message) { getDisplayInfo(message); // console.log(message.type); if (message.type == 'p2p' || message.type == 'multiple') { self.messages.push(message); } else { self.sysMessages.push(message); } if(message.type=='p2p'&&message.data&&message.data.type=='interview'){ message.url= ApiService.APPURL + '/mymeetings/vroom/discuss/' + message.data.id; } }) self.messages.sort(sortByTime); self.sysMessages.sort(sortByTime); } }); } this.deleteMsg = function(msg, index) { console.log(msg); var info = { idx: msg.idx, action: 'delunread', } if (msg.group == 'old') { info.action = 'delread'; } else if (msg.group == 'send') { info.action = 'delread'; } console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { getTargetThreadMsgs(); } }); } this.readMsg = function(msg) { var info = { action: 'markread', idx: msg.idx, } console.log(info); ApiService.post("/messages", info).then(function(result) { if (result.data.success) { console.log(result); getTargetThreadMsgs(); } }); } this.addReply = function() { if (self.r_content.length < 2) { CommonService.showError('Message is too short!'); return; } var info = { action: "sendp2p", target: target, message: self.r_content, } ApiService.post('/messages', info).then(function(result) { // console.log(result); if (result.data.success) { CommonService.showNoBlockInfo($translate.instant('Send Successful!')); self.r_content = ""; getTargetThreadMsgs(); self.tab = 'p2p'; } }); } });