766 lines
21 KiB
JavaScript
766 lines
21 KiB
JavaScript
|
|
// --------------------------------------------------------------------
|
||
|
|
// @author: shiraho@syg.com(必填, 创建模块的人员)
|
||
|
|
// @description:
|
||
|
|
// 好友主界面
|
||
|
|
// <br/>Create: new Date().toISOString()
|
||
|
|
// --------------------------------------------------------------------
|
||
|
|
var ChatConst = require("chat_const");
|
||
|
|
var ChatEvent = require("chat_event");
|
||
|
|
var RoleEvent = require("role_event");
|
||
|
|
var ChatItemController = require("chat_item_controller");
|
||
|
|
var ChatController = require("chat_controller");
|
||
|
|
var RoleController = require("role_controller")
|
||
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
||
|
|
const FxTogs = require( "nx.fx.togs" );
|
||
|
|
var BridgeWindow = require("bridge.window")
|
||
|
|
|
||
|
|
cc.Class({
|
||
|
|
extends: BridgeWindow,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
chat_taps: {//暂时不改颜色
|
||
|
|
default: [],
|
||
|
|
type:[cc.Node]
|
||
|
|
},
|
||
|
|
chat_list:{
|
||
|
|
default:null,
|
||
|
|
type:FxSVC
|
||
|
|
},
|
||
|
|
notice_list:{
|
||
|
|
default:null,
|
||
|
|
type:FxSVC
|
||
|
|
},
|
||
|
|
msg_rt:{
|
||
|
|
default:null,
|
||
|
|
type:cc.RichText
|
||
|
|
},
|
||
|
|
empty_tips_nd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
// 私聊区域
|
||
|
|
private_add_nd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
private_nd:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
private_view:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
private_contend:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
private_list:{
|
||
|
|
default:null,
|
||
|
|
type:FxSVC
|
||
|
|
},
|
||
|
|
slide_tar:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
slide_btn:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
//按钮红点
|
||
|
|
channel_red:{
|
||
|
|
default:[],
|
||
|
|
type:[cc.Node]
|
||
|
|
},
|
||
|
|
togs:{
|
||
|
|
default:null,
|
||
|
|
type:FxTogs
|
||
|
|
},
|
||
|
|
//notice
|
||
|
|
notice_node:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
at_notice_node:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
chat_input_panel:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Node
|
||
|
|
},
|
||
|
|
|
||
|
|
chat_pre:{
|
||
|
|
default:null,
|
||
|
|
type:cc.Prefab
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// LIFE-CYCLE CALLBACKS:
|
||
|
|
|
||
|
|
onLoad () {
|
||
|
|
this.ctrl = ChatController.getInstance();
|
||
|
|
this.model = this.ctrl.getModel();
|
||
|
|
this.channel = ChatConst.Channel.World;
|
||
|
|
this.role_vo = RoleController.getInstance().getRoleVo();
|
||
|
|
this.cut_tap= null; // 当前选中的标签
|
||
|
|
this.chat_items= {};
|
||
|
|
this.chat_items_cache= [];
|
||
|
|
this.is_update= false; // 消息列表更新中
|
||
|
|
this.update_index= 0; // 消息更新序号
|
||
|
|
this.chat_msgs = {};
|
||
|
|
this.content_info = {};
|
||
|
|
this.channel_tg = {};
|
||
|
|
this.private_targets = null;
|
||
|
|
this.chat_friends = {};
|
||
|
|
this.cur_friend= null; // 当前私聊对象
|
||
|
|
this.cur_friend_tap= null; // 当前私聊对象标签页面
|
||
|
|
this.chat_items_index= ""; // 当前聊天索引
|
||
|
|
this.scroll_dis= 0;
|
||
|
|
if (!this.timer){
|
||
|
|
this.timer = gcore.Timer.set((function(){
|
||
|
|
this.mainLoop();
|
||
|
|
}).bind(this), 100, -1);
|
||
|
|
}
|
||
|
|
this.chat_item_ctrl = ChatItemController.getInstance();
|
||
|
|
|
||
|
|
|
||
|
|
//事件绑定
|
||
|
|
this.role_update_event = this.role_vo.bind(RoleEvent.ROLE_EVENT_ATTR_UPDATE, (key, val)=>{
|
||
|
|
if (key == "lev" || key == "gid")
|
||
|
|
this.updateWidget()
|
||
|
|
});
|
||
|
|
//为频道增加一条新消息
|
||
|
|
this.bindGEvent(ChatEvent.MassageUpdate,this.addMsgs.bind(this));
|
||
|
|
//为频道删除一条消息
|
||
|
|
this.bindGEvent(ChatEvent.MassageDelete,this.deleteMsgs.bind(this));
|
||
|
|
//为频道增加一条私聊最新消息
|
||
|
|
this.bindGEvent(ChatEvent.PrivateMassageUpdate,this.addMsgs.bind(this));
|
||
|
|
//删除一条私聊消息
|
||
|
|
this.bindGEvent(ChatEvent.PrivateMassageDelete,this.deleteMsgs.bind(this));
|
||
|
|
//更新红点
|
||
|
|
this.bindGEvent(EventId.CHAT_NEWMSG_FLAG,this.setAllRedStatus.bind(this));
|
||
|
|
|
||
|
|
this.togs.posTog = this.onTogMenu.bind( this );
|
||
|
|
// this.scrollview_mgs_sc.node.on("scrolling", this.contentScrolling.bind(this))
|
||
|
|
//键盘输入监听
|
||
|
|
this.chat_input_cmp = this.chat_input_panel.getComponent("cmp.chat.wnd.input");
|
||
|
|
this.chat_input_cmp.setSendCallback(this.didiClickSendMsg.bind(this));
|
||
|
|
|
||
|
|
this.chatPool = new cc.NodePool();
|
||
|
|
},
|
||
|
|
|
||
|
|
//当前根节点销毁前进行的预处理操作
|
||
|
|
onPreClosed(){
|
||
|
|
this.is_update = false;
|
||
|
|
this.private_targets = null;
|
||
|
|
|
||
|
|
this.chat_list.rebuild([]);
|
||
|
|
this.notice_list.rebuild([]);
|
||
|
|
this.private_list.rebuild([]);
|
||
|
|
|
||
|
|
this.rebuildMsgItem(null);
|
||
|
|
},
|
||
|
|
|
||
|
|
start () {
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
createChatList(data_list,key){
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onOpenConfigs(params){
|
||
|
|
let channel = ChatConst.Channel.Cross;//从世界聊天默认到跨服聊天
|
||
|
|
if (params && params.channel)
|
||
|
|
channel = params.channel;
|
||
|
|
let channel_tag = this.getChannelTag(channel);
|
||
|
|
|
||
|
|
if (channel == ChatConst.Channel.Friend) {
|
||
|
|
this.cur_friend = params.friend_data;
|
||
|
|
|
||
|
|
this.togs.togTo(2);
|
||
|
|
if(!this.private_view.active){
|
||
|
|
this.onClickSlide();
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
this.togs.togTo(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
this.changeChannel(channel_tag);
|
||
|
|
|
||
|
|
this.updateWidget();
|
||
|
|
this.setAllRedStatus();
|
||
|
|
},
|
||
|
|
|
||
|
|
onFocusFriendList(_item){
|
||
|
|
// 空
|
||
|
|
if( nx.dt.objEmpty( _item ) ||
|
||
|
|
nx.dt.objEmpty( _item.mdata ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 聚焦
|
||
|
|
this.private_list.cleanFocus();
|
||
|
|
this.private_list.addFocus( _item.index );
|
||
|
|
|
||
|
|
let real_index = _item.friend_vo.srv_id + _item.friend_vo.rid;
|
||
|
|
this.selectPrivate(real_index,_item.friend_vo);
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
onEnable(){
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
onDisable(){
|
||
|
|
if( nx.bridge.prompt ) {
|
||
|
|
nx.bridge.prompt.delPrompt(8);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
//------------------------1
|
||
|
|
changeChannel: function(channel_tag) {
|
||
|
|
if(channel_tag == 1){
|
||
|
|
nx.mTip.openTip("chat.world",false);
|
||
|
|
}else if(channel_tag == 2){
|
||
|
|
nx.mTip.openTip("chat.union",false);
|
||
|
|
}else if(channel_tag == 3){
|
||
|
|
nx.mTip.openTip("chat.players",false);
|
||
|
|
}else if(channel_tag == 4){
|
||
|
|
nx.mTip.openTip("chat.system",false);
|
||
|
|
}
|
||
|
|
this.chat_list.rebuild([]);
|
||
|
|
this.notice_list.rebuild([]);
|
||
|
|
nx.gui.setActive(this.chat_list.node,"",channel_tag != 4);
|
||
|
|
nx.gui.setActive(this.notice_list.node,"",channel_tag == 4);
|
||
|
|
|
||
|
|
this.setRedStatus(channel_tag);
|
||
|
|
|
||
|
|
var channel_index = ChatConst.ChannelTag[channel_tag];
|
||
|
|
this.last_chat_index = this.chat_items_index;
|
||
|
|
this.channel = ChatConst.Channel[channel_index];
|
||
|
|
|
||
|
|
this.chat_input_panel.active = true;
|
||
|
|
this.slide_btn.active = false;
|
||
|
|
if(this.private_view.active && this.channel != ChatConst.Channel.Friend){
|
||
|
|
this.private_view.active = false;
|
||
|
|
this.slide_tar.scaleX = -this.slide_tar.scaleX;
|
||
|
|
}
|
||
|
|
|
||
|
|
if( ( this.channel == ChatConst.Channel.Gang && this.role_vo.gid == 0 ) || this.channel == ChatConst.Channel.System){
|
||
|
|
this.chat_input_panel.active = false;
|
||
|
|
this.notice_node.active = true;
|
||
|
|
}else if(this.channel == ChatConst.Channel.Province){
|
||
|
|
var province_config = game.configs.misc_data.data_const["province_level"];
|
||
|
|
if(!province_config || this.role_vo.lev < province_config.val){
|
||
|
|
this.chat_input_panel.active = false;
|
||
|
|
this.notice_node.active = false;
|
||
|
|
}else{
|
||
|
|
this.chat_input_panel.active = true;
|
||
|
|
this.notice_node.active = false;
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
this.notice_node.active = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (channel_tag === 0) {
|
||
|
|
if (this.role_vo && this.role_vo.lev < 35) {
|
||
|
|
this.empty_tips_nd.active = true;
|
||
|
|
this.chat_input_panel.active = false;
|
||
|
|
} else {
|
||
|
|
this.empty_tips_nd.active = false;
|
||
|
|
this.chat_input_panel.active = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.cut_tap = channel_tag;
|
||
|
|
|
||
|
|
// 更新记录切换时的高度和位置
|
||
|
|
// this.updageChannelSizeInfo();
|
||
|
|
|
||
|
|
this.private_list.rebuild([]);
|
||
|
|
this.chat_items_index = this.channel;
|
||
|
|
if (this.channel == ChatConst.Channel.Friend) {
|
||
|
|
this.slide_btn.active = true;
|
||
|
|
this.private_targets = null;
|
||
|
|
if (!this.private_targets) {
|
||
|
|
this.private_targets = [];
|
||
|
|
var h_private_targets = this.model.getPrivateTargets();
|
||
|
|
if (h_private_targets.length > 0) {
|
||
|
|
if (!this.cur_friend){
|
||
|
|
this.cur_friend = h_private_targets[0];
|
||
|
|
}
|
||
|
|
|
||
|
|
let list = [];
|
||
|
|
let index = 0;
|
||
|
|
for (var friend_i = 0; friend_i < h_private_targets.length; friend_i++){
|
||
|
|
let select = this.addPrivateTap(h_private_targets[friend_i]);
|
||
|
|
let obj = {};
|
||
|
|
obj.vo = h_private_targets[friend_i];
|
||
|
|
// obj.select_cb = this.selectPrivate.bind(this);
|
||
|
|
obj.delete_cb = this.deletePrivate.bind(this);
|
||
|
|
obj.is_select = select;
|
||
|
|
if(select){
|
||
|
|
index = friend_i;
|
||
|
|
this.cur_friend = h_private_targets[friend_i];
|
||
|
|
}
|
||
|
|
list.push(obj);
|
||
|
|
}
|
||
|
|
this.private_list.rebuild(list);
|
||
|
|
this.private_list.addFocus(index);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (this.cur_friend) {
|
||
|
|
this.chat_items_index = this.cur_friend.srv_id + this.cur_friend.rid;
|
||
|
|
this.private_add_nd.active = false;
|
||
|
|
} else {
|
||
|
|
this.private_add_nd.active = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
} else {
|
||
|
|
if (this.private_add_nd.active)
|
||
|
|
this.private_add_nd.active = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// 清楚频道未读消息
|
||
|
|
this.model.cleanUnredNum(this.channel);
|
||
|
|
// 更新显示区域
|
||
|
|
this.updateMsgsContent();
|
||
|
|
|
||
|
|
var tempStr = "";
|
||
|
|
// 同省、跨服、世界、公会可以@人
|
||
|
|
if (channel_tag == 1 || channel_tag == 2 || channel_tag == 3 || channel_tag == 4) {
|
||
|
|
var data = this.model.getAtData();
|
||
|
|
if (!nx.dt.objEmpty(data)) {
|
||
|
|
// this.showAtNotice(true, data);
|
||
|
|
}
|
||
|
|
tempStr = "";
|
||
|
|
}
|
||
|
|
|
||
|
|
this.chat_input_cmp.setPlacholderLabel(tempStr);
|
||
|
|
this.chat_input_cmp.setChannel(this.channel);
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
//标签页红点处理
|
||
|
|
setRedStatus: function (channel) {
|
||
|
|
if (channel == null) return
|
||
|
|
|
||
|
|
this.model.updateRedStatus(channel);
|
||
|
|
|
||
|
|
// if ((channel == 2 && this.role_vo && this.role_vo.lev < 50) || (channel == 4 && this.role_vo && !this.role_vo.gid)) {
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
|
||
|
|
// let btn = this.channel_red[channel-1];
|
||
|
|
// let num = this.model.getUnreadNum(ChatConst.Channel[ChatConst.ChannelTag[channel]]);
|
||
|
|
// if (num > 0) {
|
||
|
|
// btn.active = true;
|
||
|
|
// } else {
|
||
|
|
// btn.active = false;
|
||
|
|
// }
|
||
|
|
},
|
||
|
|
|
||
|
|
// 更新消息容器的高度和位置
|
||
|
|
updageChannelSizeInfo: function(is_clean) {
|
||
|
|
// if (!this.chat_items_index) return;
|
||
|
|
// if (!this.content_info[this.chat_items_index]) this.content_info[this.chat_items_index] = {};
|
||
|
|
// var c_pos = this.msgs_content.y;
|
||
|
|
// var c_height = this.msgs_content.height;
|
||
|
|
// if (is_clean) {
|
||
|
|
// c_pos = 0;
|
||
|
|
// c_height = 0;
|
||
|
|
// }
|
||
|
|
// this.content_info[this.chat_items_index].c_pos = c_pos;
|
||
|
|
// this.content_info[this.chat_items_index].c_height = c_height;
|
||
|
|
},
|
||
|
|
|
||
|
|
addPrivateTap: function(friend_vo) {
|
||
|
|
for (var friend_i = 0; friend_i < this.private_targets.length; friend_i++) {
|
||
|
|
if (this.private_targets[friend_i].srv_id === friend_vo.srv_id && this.private_targets[friend_i].rid === friend_vo.rid){
|
||
|
|
return
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// var ChatFriend = require("chat_friend");
|
||
|
|
var is_select = false;
|
||
|
|
if (this.cur_friend && this.cur_friend.srv_id === friend_vo.srv_id && this.cur_friend.rid == friend_vo.rid)
|
||
|
|
is_select = true;
|
||
|
|
|
||
|
|
this.private_targets.push(friend_vo);
|
||
|
|
return is_select;
|
||
|
|
},
|
||
|
|
|
||
|
|
selectPrivate: function(private_index, friend_vo) {
|
||
|
|
if (private_index && friend_vo && private_index !== this.chat_items_index) {
|
||
|
|
// 更新记录切换时的高度和位置
|
||
|
|
this.updageChannelSizeInfo();
|
||
|
|
this.cur_friend_tap = this.chat_friends[friend_vo.srv_id + friend_vo.rid];
|
||
|
|
this.cur_friend = friend_vo;
|
||
|
|
this.last_chat_index = this.chat_items_index;
|
||
|
|
this.chat_items_index = private_index;
|
||
|
|
this.updateMsgsContent();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
deletePrivate: function(private_index, friend_vo) {
|
||
|
|
if (private_index && friend_vo) {
|
||
|
|
for (var friend_i in this.private_targets) {
|
||
|
|
if (this.private_targets[friend_i].rid === friend_vo.rid) {
|
||
|
|
this.private_targets.splice(friend_i, 1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (this.private_targets.length > 0) {
|
||
|
|
var new_friend_vo = this.private_targets[0];
|
||
|
|
var private_index = new_friend_vo.srv_id + new_friend_vo.rid
|
||
|
|
this.selectPrivate(private_index, new_friend_vo);
|
||
|
|
this.private_add_nd.active = false;
|
||
|
|
} else {
|
||
|
|
this.last_chat_index = friend_vo.srv_id + friend_vo.rid;
|
||
|
|
this.chat_msgs[this.chat_items_index] = [];
|
||
|
|
this.updateMsgsContent();
|
||
|
|
this.chat_items_index = null;
|
||
|
|
this.cur_friend = null;
|
||
|
|
this.last_chat_index = null;
|
||
|
|
this.private_add_nd.active = true;
|
||
|
|
}
|
||
|
|
// delete this.chat_friends[friend_vo.srv_id + friend_vo.rid];
|
||
|
|
|
||
|
|
this.model.deltePrivateTarget(friend_vo);
|
||
|
|
|
||
|
|
let list = [];
|
||
|
|
for(let i=0;i<this.private_targets.length;i++){
|
||
|
|
let obj = {};
|
||
|
|
obj.vo = this.private_targets[i];
|
||
|
|
obj.select_cb = this.selectPrivate.bind(this);
|
||
|
|
obj.delete_cb = this.deletePrivate.bind(this);
|
||
|
|
if(i == 0){
|
||
|
|
obj.is_select = true;
|
||
|
|
}else{
|
||
|
|
obj.is_select = false;
|
||
|
|
}
|
||
|
|
list.push(obj);
|
||
|
|
}
|
||
|
|
this.private_list.rebuild(list);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
rebuildMsgItem(e){
|
||
|
|
// 清空
|
||
|
|
// if( e == null ) {
|
||
|
|
// nx.pools.putChildren( this.msgs_content );
|
||
|
|
// return;
|
||
|
|
// }
|
||
|
|
|
||
|
|
// 重建
|
||
|
|
// let pool = nx.pools.getPool( this.chat_pre.name, this.chat_pre );
|
||
|
|
// let node = cc.instantiate(this.chat_pre);
|
||
|
|
// if(node){
|
||
|
|
// return node.getComponent("cmp.item.chat.player");
|
||
|
|
// }
|
||
|
|
// return null;
|
||
|
|
},
|
||
|
|
|
||
|
|
addMsgItem: function(msg_data, channel2) {
|
||
|
|
let channel = channel2 ? channel2 : msg_data.channel;
|
||
|
|
var items_index = channel;
|
||
|
|
|
||
|
|
if (channel === ChatConst.Channel.Friend) {
|
||
|
|
items_index = msg_data.srv_id + msg_data.rid;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 解析聊天字符串,增加表情和图片高度
|
||
|
|
// analyzeMessage
|
||
|
|
var test_msg = this.chat_item_ctrl.analyzeMessage(msg_data.msg);
|
||
|
|
this.msg_rt.string = test_msg;
|
||
|
|
this.chat_msgs[items_index].push(msg_data);
|
||
|
|
|
||
|
|
return items_index;// msg_item
|
||
|
|
},
|
||
|
|
|
||
|
|
// 删除、初始化消息来创建chat_item, 更新区域
|
||
|
|
updateMsgsContent: function() {
|
||
|
|
|
||
|
|
// 初始化当前频道信息
|
||
|
|
if (this.chat_items_index && !this.chat_msgs[this.chat_items_index]) {
|
||
|
|
// this.updageChannelSizeInfo(true);
|
||
|
|
this.initItems(this.channel, this.chat_items_index);
|
||
|
|
}else{
|
||
|
|
let msg_list = this.chat_msgs[this.chat_items_index] || [];
|
||
|
|
if(this.channel == ChatConst.Channel.System){
|
||
|
|
this.notice_list.svcKey = this.channel;
|
||
|
|
this.notice_list.rebuild(msg_list);
|
||
|
|
}else{
|
||
|
|
this.chat_list.svcKey = this.channel;
|
||
|
|
this.chat_list.rebuild(msg_list);
|
||
|
|
}
|
||
|
|
|
||
|
|
// this.createChatList(this.chat_msgs[this.chat_items_index],this.chat_items_index);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 初始化某个channel的消息条目
|
||
|
|
initItems: function(channel, item_index) {
|
||
|
|
if (!channel) return;
|
||
|
|
|
||
|
|
var items_index = item_index ? item_index : channel;
|
||
|
|
var msgs = [];
|
||
|
|
this.chat_msgs[items_index] = [];
|
||
|
|
this.chat_items[items_index] = [];
|
||
|
|
|
||
|
|
if (channel == ChatConst.Channel.Friend && item_index) {
|
||
|
|
if (this.cur_friend) {
|
||
|
|
msgs = this.model.getPrivateMsgs(this.cur_friend.srv_id, this.cur_friend.rid);
|
||
|
|
this.ctrl.sender12723(this.cur_friend.srv_id, this.cur_friend.rid);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
msgs = this.model.getChannelMsgs(channel);
|
||
|
|
}
|
||
|
|
|
||
|
|
let chat_item_index = channel;
|
||
|
|
if(msgs.length > 0){
|
||
|
|
for (var msg_i = 0; msg_i < msgs.length; msg_i++) {
|
||
|
|
chat_item_index = this.addMsgItem(msgs[msg_i], channel);
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
if (channel == ChatConst.Channel.Friend) {
|
||
|
|
chat_item_index = item_index;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let msg_list = this.chat_msgs[chat_item_index] || [];
|
||
|
|
if(channel == ChatConst.Channel.System){
|
||
|
|
this.notice_list.svcKey = channel;
|
||
|
|
this.notice_list.rebuild(msg_list);
|
||
|
|
}else{
|
||
|
|
this.chat_list.svcKey = channel;
|
||
|
|
this.chat_list.rebuild(msg_list);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
cleanConten: function() {
|
||
|
|
// if (!this.last_chat_index) return
|
||
|
|
// this.update_index = 0;
|
||
|
|
// for (var chat_i in this.chat_items[this.last_chat_index]) {
|
||
|
|
// this.chat_items[this.last_chat_index][chat_i].updateContent(true);
|
||
|
|
// }
|
||
|
|
},
|
||
|
|
|
||
|
|
// 更新条目状态
|
||
|
|
updageItems: function() {
|
||
|
|
// if (this.chat_items_index) {
|
||
|
|
// if (this.chat_items[this.chat_items_index]) {
|
||
|
|
// for (var item_index in this.chat_items[this.chat_items_index]) {
|
||
|
|
// this.chat_items[this.chat_items_index][item_index].updateContent();
|
||
|
|
// }
|
||
|
|
// // 更新到最新位置
|
||
|
|
// if (this.chat_items[this.chat_items_index].length > 0) {
|
||
|
|
// this.empty_tips_nd.active = false;
|
||
|
|
// } else {
|
||
|
|
// if (this.cut_tap !== 1 || (this.role_vo && this.role_vo.lev > 35)) {
|
||
|
|
// this.empty_tips_nd.active = true;
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
// }
|
||
|
|
},
|
||
|
|
//------------------------1------------------end
|
||
|
|
|
||
|
|
//------------------------2
|
||
|
|
updateWidget: function() {
|
||
|
|
// 设置个频道状态
|
||
|
|
for (var channel_i in ChatConst.ChannelTag) {
|
||
|
|
var channel_status = this.checkBtnIsOpen(channel_i);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
checkBtnIsOpen: function(channel) {
|
||
|
|
if (channel == 2) {
|
||
|
|
if(this.role_vo.lev < 50)
|
||
|
|
return false;
|
||
|
|
} else if (channel == 4) {
|
||
|
|
if (!this.role_vo.gid)
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
return true
|
||
|
|
},
|
||
|
|
|
||
|
|
//所有标签页红点处理
|
||
|
|
setAllRedStatus: function () {
|
||
|
|
for (let i = 1; i <= 6; i++) {
|
||
|
|
this.setRedStatus(i);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
//------------------------2------------------end
|
||
|
|
|
||
|
|
onTogMenu(_type){
|
||
|
|
this.checkToggle(_type+1);
|
||
|
|
this.didClickTap(_type+1);
|
||
|
|
},
|
||
|
|
|
||
|
|
checkToggle: function(event) {
|
||
|
|
var toggle_tag_1 = event;
|
||
|
|
if (toggle_tag_1 == this.cur_select) return;
|
||
|
|
|
||
|
|
this.changeChannel(toggle_tag_1);
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击标签
|
||
|
|
didClickTap: function(event) {
|
||
|
|
if (event == 2 && !this.role_vo.gid) {
|
||
|
|
nx.tbox( "ChatNoParty" );
|
||
|
|
}
|
||
|
|
|
||
|
|
this.setRedStatus(event);
|
||
|
|
},
|
||
|
|
|
||
|
|
mainLoop: function() {
|
||
|
|
// if (!this.is_update) return
|
||
|
|
// if (this.chat_items[this.chat_items_index] && this.update_index < this.chat_items[this.chat_items_index].length) {
|
||
|
|
// this.chat_items[this.chat_items_index][this.update_index].updateContent();
|
||
|
|
// this.update_index ++;
|
||
|
|
// } else {
|
||
|
|
// this.update_index = 0;
|
||
|
|
// this.is_update = false;
|
||
|
|
// }
|
||
|
|
},
|
||
|
|
|
||
|
|
addMsgs(msgData){
|
||
|
|
if (!msgData) return;
|
||
|
|
let channel = msgData.channel;
|
||
|
|
let data = msgData;
|
||
|
|
var chat_items_index = channel;
|
||
|
|
if (channel === ChatConst.Channel.Friend) {
|
||
|
|
chat_items_index = msgData.msg_data.srv_id + msgData.msg_data.rid;
|
||
|
|
data = msgData.msg_data;
|
||
|
|
}
|
||
|
|
|
||
|
|
if(!this.chat_msgs[chat_items_index]){
|
||
|
|
if (chat_items_index == this.chat_items_index) {
|
||
|
|
this.initItems(channel, chat_items_index);
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
chat_items_index = this.addMsgItem(data, channel);
|
||
|
|
if (chat_items_index == this.chat_items_index) {
|
||
|
|
|
||
|
|
let msg_list = this.chat_msgs[chat_items_index] || [];
|
||
|
|
if(channel == ChatConst.Channel.System){
|
||
|
|
this.notice_list.svcKey = channel;
|
||
|
|
this.notice_list.rebuild(msg_list);
|
||
|
|
}else{
|
||
|
|
this.chat_list.svcKey = channel;
|
||
|
|
this.chat_list.rebuild(msg_list);
|
||
|
|
}
|
||
|
|
// this.createChatList(this.chat_msgs[chat_items_index],chat_items_index);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let tag = null;
|
||
|
|
for(let i in ChatConst.Channel){
|
||
|
|
if(ChatConst.Channel[i] == channel){
|
||
|
|
for(let j in ChatConst.ChannelTag){
|
||
|
|
if(ChatConst.ChannelTag[j] == i){
|
||
|
|
tag = j;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
this.setRedStatus(tag);
|
||
|
|
if (channel === this.channel )
|
||
|
|
this.model.cleanUnredNum(channel);
|
||
|
|
},
|
||
|
|
|
||
|
|
deleteMsgs(msgData){
|
||
|
|
if (!msgData) return;
|
||
|
|
let channel = msgData.channel;
|
||
|
|
|
||
|
|
var chat_items_index = msgData.channel;
|
||
|
|
if (channel === ChatConst.Channel.Friend)
|
||
|
|
chat_items_index = msgData.srv_id + msgData.rid;
|
||
|
|
|
||
|
|
if(this.chat_msgs && this.chat_msgs[chat_items_index]){
|
||
|
|
this.chat_msgs[chat_items_index].shift();
|
||
|
|
this.chat_list.svcKey = "";
|
||
|
|
this.chat_list.rebuild([]);
|
||
|
|
this.notice_list.svcKey = "";
|
||
|
|
this.notice_list.rebuild([]);
|
||
|
|
}
|
||
|
|
|
||
|
|
this.setRedStatus(channel);
|
||
|
|
},
|
||
|
|
|
||
|
|
getChannelTag: function(channel) {
|
||
|
|
var channel_tag = null, channel_index = null;
|
||
|
|
for (var channel_i in ChatConst.Channel) {
|
||
|
|
if (ChatConst.Channel[channel_i] === channel)
|
||
|
|
channel_index = channel_i;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (channel_index) {
|
||
|
|
for (var tag_i in ChatConst.ChannelTag) {
|
||
|
|
if (ChatConst.ChannelTag[tag_i] == channel_index)
|
||
|
|
channel_tag = tag_i;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return channel_tag;
|
||
|
|
},
|
||
|
|
|
||
|
|
didiClickSendMsg: function(msg) {
|
||
|
|
if (msg.length > 0) {
|
||
|
|
if (this.channel === ChatConst.Channel.Friend) {
|
||
|
|
if (this.cur_friend)
|
||
|
|
this.ctrl.sendMessage(this.channel, msg, 2, this.cur_friend.srv_id, this.cur_friend.rid,this.cur_friend.name);
|
||
|
|
} else {
|
||
|
|
this.ctrl.sendMessage(this.channel, msg, 2);
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
nx.tbox("chat_str6");
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
getChatItemNd: function() {
|
||
|
|
if (this.chat_items_cache.length > 0) {
|
||
|
|
return this.chat_items_cache.shift();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
cacheChatItemNd: function(item_nd) {
|
||
|
|
this.chat_items_cache.push(item_nd);
|
||
|
|
},
|
||
|
|
|
||
|
|
// getContentPos: function() {
|
||
|
|
// return this.msgs_content.y
|
||
|
|
// },
|
||
|
|
|
||
|
|
onClickAddPriBtn(){
|
||
|
|
this.ctrl.closeChatPanel();
|
||
|
|
nx.bridge.createPanel( "WndFriend",{type:1} );
|
||
|
|
},
|
||
|
|
|
||
|
|
onClickSlide(){
|
||
|
|
this.private_view.active = !this.private_view.active;
|
||
|
|
this.slide_tar.scaleX = -this.slide_tar.scaleX;
|
||
|
|
},
|
||
|
|
|
||
|
|
atSelfNotice(item){
|
||
|
|
if (item) {
|
||
|
|
// var precent = (this.msgs_content.height - item.pos_y-item.height) / this.msgs_content.height;
|
||
|
|
// if(precent>1){
|
||
|
|
// precent = 1;
|
||
|
|
// }
|
||
|
|
// this.scrollview_mgs_sc.scrollToPercentVertical(precent, 0.1,true);
|
||
|
|
this.atSelfClose();
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
atSelfClose(atData){
|
||
|
|
this.at_notice_node.active = false;
|
||
|
|
this.model.setAtData({});
|
||
|
|
if (!nx.dt.objEmpty(atData)) {
|
||
|
|
this.ctrl.sender12768(atData.rid, atData.srv_id, atData.channel, atData.msg);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|