"use strict";
cc._RF.push(module, 'bfba6w+qEdKqbSx0rq3BbHq', 'chat_controller');
// Scripts/mod/chat/chat_controller.js
"use strict";
var ChatConst = require("chat_const");
var ChatController = cc.Class({
"extends": BaseController,
ctor: function ctor() {
var ChatModel = require("chat_model");
this.model = new ChatModel(this);
this.model.initConfig();
this.chat_time = {};
},
registerEvents: function registerEvents() {
this.init_role_event = gcore.GlobalEvent.bind(EventId.EVT_ROLE_CREATE_SUCCESS, function () {
gcore.GlobalEvent.unbind(this.init_role_event);
this.model.initPrivatreTargets();
}.bind(this));
},
openChatPanel: function openChatPanel(channel, form, data) {
var open_parame = {};
if (!this.chat_window) {
var ChatWindow = require("chat_window");
this.chat_window = new ChatWindow();
}
open_parame.channel = form;
if (form == "friend") {
this.model.addPrivateTarget(data);
open_parame.channel = ChatConst.Channel.Friend;
open_parame.friend_data = data;
}
if (!this.chat_window.getVisible()) {
this.chat_window.setVisible(true, open_parame);
} else {
this.chat_window.open(open_parame);
}
},
closeChatPanel: function closeChatPanel() {
if (this.chat_window) {
var PromptController = require("prompt_controller");
var PromptTypeConst = require("prompt_type_const");
PromptController.getInstance().getModel().removePromptDataByTpye(PromptTypeConst.Private_chat);
PromptController.getInstance().getModel().removePromptDataByTpye(PromptTypeConst.At_notice); // this.chat_window.close();
// this.chat_window = null;
this.chat_window.setVisible(false);
var MainUIController = require("mainui_controller");
MainUIController.getInstance().showChatBtn(true);
}
},
initData: function initData() {},
getModel: function getModel() {
return this.model;
},
initConfig: function initConfig() {
var ChatModel = require("chat_model");
this.model = new ChatModel();
this.model.initConfig();
this.is_first = true;
this.pro_12766 = true;
this.stack_id = 0;
},
registerProtocals: function registerProtocals() {
this.RegisterProtocal(12720, this.handle12720); // 私聊
this.RegisterProtocal(12721, this.handle12721); // 推送私聊消息
this.RegisterProtocal(12722, this.handle12722); // 登陆推送私聊信息
this.RegisterProtocal(12725, this.handle12725); // 语音信息
this.RegisterProtocal(12726, this.handle12726); // 下载语音信息
this.RegisterProtocal(12741, this.handle12741); // 提示
this.RegisterProtocal(12743, this.handle12743); // 系统提示&聊天提示
this.RegisterProtocal(12799, this.handle12799); // 消息发送
this.RegisterProtocal(12761, this.handle12761); // 接受通用聊天
this.RegisterProtocal(12762, this.handle12762); // 发送通用聊天
this.RegisterProtocal(12763, this.handle12763); // 服务端分发翻译
this.RegisterProtocal(12766, this.handle12766); // 登录聊天记录
this.RegisterProtocal(12771, this.handle12771); // 聊天玩家队伍id
this.RegisterProtocal(12767, this.handle12767); // 聊天@
this.RegisterProtocal(12768, this.handle12768); // 已查看
},
isChatOpen: function isChatOpen() {
if (this.chat_window) {
return this.chat_window.getVisible();
}
return false;
},
/**
* 发送翻译后的文字消息
* @author zhanghuxing 2019-01-03
* @param {[type]} msg [description]
* @param {[type]} channel [description]
* @param {[type]} taken_obj [description]
* @return {[type]} [description]
*/
sendVoidMsg: function sendVoidMsg(msg, channel, taken_obj) {
if (channel == ChatConst.Channel.Friend) {
this.sender12720();
} else {
this.sender12762();
}
},
/**
* 发送文字信息
* @author zhanghuxing 2019-01-03
* @param {[type]} msg [description]
* @param {[type]} channel 频道
* @param {[type]} taken_obj [description]
* @param {[type]} len [description]
* @return {[type]} [description]
*/
sendMessage: function sendMessage(channel, msg, len, to_srv_id, to_rid, name) {
cc.log("chat__________", msg, channel, len, to_srv_id, to_rid);
if (channel == ChatConst.Channel.Friend) {
this.sender12720(to_srv_id, to_rid, msg, len, name);
} else {
this.sender12762(channel, msg, len);
}
},
sender12720: function sender12720(to_srv_id, to_rid, msg, len, name) {
// 发起私聊
var msg_data = {};
msg_data.to_srv_id = to_srv_id;
msg_data.to_rid = to_rid;
msg_data.msg = msg;
msg_data.len = len;
this.SendProtocal(12720, msg_data); // cc.log("sl---------------",to_rid.split("_"))
//爱微游渠道聊天监控
if (window.CHANNEL == "AIWEIYOU_PID") {
var rid = null;
to_rid = String(to_rid);
var arr = to_rid.split("_");
rid = arr[1];
sdk.chatMonitor({
to_srv_id: to_srv_id,
to_rid: rid,
type: 1,
//1表示私聊
name: name,
msg: msg
});
}
},
handle12720: function handle12720(data) {
// 私聊失败提示
cc.log("私聊失败");
cc.log(data);
if (data.code == 0) {
message(data.msg);
}
},
handle12721: function handle12721(data) {
// 收到私聊消息
cc.log("私聊消息");
cc.log(data);
if (data) this.model.addPrivateMsg(data);
},
handle12722: function handle12722(msg_datas) {
// 登陆推送离线私聊信息
cc.log("离线私聊消息");
cc.log(msg_datas);
if (msg_datas && msg_datas.offline_list.length > 0) {
var offline_Info = null;
for (var offline_i = 0; offline_i < msg_datas.offline_list.length; offline_i++) {
offline_Info = msg_datas.offline_list[offline_i];
if (offline_Info.msg_list && offline_Info.msg_list) {
for (var msg_i = 0; msg_i < offline_Info.msg_list.length; msg_i++) {
var msg_info = Utils.deepCopy(offline_Info);
delete msg_info.msg_list;
msg_info.msg = offline_Info.msg_list[msg_i].msg;
msg_info.len = offline_Info.msg_list[msg_i].len;
msg_info.tick = offline_Info.msg_list[msg_i].tick;
msg_info.offline = true;
msg_info.flag = 2;
this.model.addOutlinePrivateMsg(msg_info);
}
}
}
}
},
// 通知服务端已读消息
sender12723: function sender12723(srv_id, rid) {
if (srv_id === null || rid === null) return;
var protocal = {};
protocal.rid = rid;
protocal.srv_id = srv_id;
this.SendProtocal(12723, protocal);
},
handle12725: function handle12725(data) {// 语音信息
},
handle12726: function handle12726(data) {// 下载语音信息
},
handle12741: function handle12741(data) {
// 提示
// 消耗