277 lines
6.4 KiB
JavaScript
277 lines
6.4 KiB
JavaScript
var SDKManage = require('SDKManage');
|
|
var NetManage = require('NetManage');
|
|
var playerData = require('playerData');
|
|
var gameConfig = require('gameConfig');
|
|
var Main = require('Main');
|
|
|
|
cc.Class({
|
|
extends: cc.Component,
|
|
|
|
properties: {
|
|
// foo: {
|
|
// // ATTRIBUTES:
|
|
// default: null, // The default value will be used only when the component attaching
|
|
// // to a node for the first time
|
|
// type: cc.SpriteFrame, // optional, default is typeof default
|
|
// serializable: true, // optional, default is true
|
|
// },
|
|
// bar: {
|
|
// get () {
|
|
// return this._bar;
|
|
// },
|
|
// set (value) {
|
|
// this._bar = value;
|
|
// }
|
|
// },
|
|
},
|
|
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
onLoad() {
|
|
this.worldmax = 50;
|
|
this.guildmax = 50;
|
|
this.friendmax = 50;
|
|
this.teammax = 50;
|
|
|
|
this.woldmsg = [];
|
|
this.guildmsg = [];
|
|
this.friendmsg = {};
|
|
this.teammsg = [];
|
|
this.dalabamsg = [];
|
|
cc.talkmgr = this;
|
|
cc.Notifier.on(
|
|
'SMChatMsgNotify',
|
|
this,
|
|
this.SMChatMsgNotify.bind(this)
|
|
);
|
|
cc.Notifier.on(
|
|
'SMUpdateChatRedPointNotify',
|
|
this,
|
|
this.SMUpdateChatRedPointNotify.bind(this)
|
|
);
|
|
},
|
|
|
|
onDestroy() {
|
|
cc.Notifier.off('SMChatMsgNotify', this);
|
|
cc.Notifier.off('SMUpdateChatRedPointNotify', this);
|
|
},
|
|
|
|
compareint64(a, b) {
|
|
if (a.high < b.high) {
|
|
return true;
|
|
}
|
|
if (a.high == b.high) {
|
|
if (a.low <= b.low) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
|
|
SMUpdateChatRedPointNotify(msg) {
|
|
playerData.chatred = false;
|
|
playerData.chatworldred = false;
|
|
playerData.chatguildred = false;
|
|
playerData.chatfriendred = false;
|
|
if (msg.has_unread_msg_channels.length != 0) {
|
|
for (var i = 0; i < msg.has_unread_msg_channels.length; i++) {
|
|
if (msg.has_unread_msg_channels[i] == 1) {
|
|
// playerData.chatworldred = true
|
|
} else if (msg.has_unread_msg_channels[i] == 2) {
|
|
playerData.chatfriendred = true;
|
|
playerData.chatred = true;
|
|
} else if (msg.has_unread_msg_channels[i] == 3) {
|
|
playerData.chatguildred = true;
|
|
playerData.chatred = true;
|
|
}
|
|
}
|
|
}
|
|
SDKManage.m_chatUNReadArr = msg.has_unread_msg_channels;
|
|
|
|
cc.Notifier.emit('refreshchatred');
|
|
},
|
|
|
|
SMChatMsgNotify(msg) {
|
|
console.log('TalkMaanger=========', msg);
|
|
var arr = msg.msg_list;
|
|
var biaoshi = [false, false, false, false];
|
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
var channel = arr[i].chat_channel;
|
|
if (channel == 1) {
|
|
if (
|
|
this.woldmsg.length > 0 &&
|
|
this.compareint64(
|
|
arr[i].msg_uuid,
|
|
this.woldmsg[this.woldmsg.length - 1].msg_uuid
|
|
)
|
|
) {
|
|
continue;
|
|
}
|
|
this.woldmsg.push(arr[i]);
|
|
if (this.woldmsg.length > this.worldmax) {
|
|
this.woldmsg.splice(0, 1);
|
|
}
|
|
biaoshi[0] = true;
|
|
} else if (channel == 2) {
|
|
var accountid = arr[i].sender.base_data.account_id;
|
|
if (accountid == SDKManage.account_id) {
|
|
accountid = arr[i].receiver.base_data.account_id;
|
|
}
|
|
if (!this.friendmsg[accountid]) {
|
|
this.friendmsg[accountid] = [];
|
|
try {
|
|
var str = cc.sys.localStorage.getItem(
|
|
SDKManage.account_id + accountid
|
|
);
|
|
if (str && str != '') {
|
|
this.friendmsg[accountid] = JSON.parse(str);
|
|
}
|
|
} catch (e) {
|
|
this.friendmsg[accountid] = [];
|
|
}
|
|
}
|
|
var temp = JSON.parse(JSON.stringify(arr[i]));
|
|
temp.accountid = arr[i].sender.base_data.account_id;
|
|
|
|
if (
|
|
this.friendmsg[accountid].length > 0 &&
|
|
this.compareint64(
|
|
arr[i].msg_uuid,
|
|
this.friendmsg[accountid][
|
|
this.friendmsg[accountid].length - 1
|
|
].msg_uuid
|
|
)
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
this.friendmsg[accountid].push(temp);
|
|
if (this.friendmsg[accountid].length > this.friendmax) {
|
|
this.friendmsg[accountid].splice(0, 1);
|
|
}
|
|
try {
|
|
cc.sys.localStorage.setItem(
|
|
SDKManage.account_id + accountid,
|
|
JSON.stringify(this.friendmsg[accountid])
|
|
);
|
|
} catch (e) {}
|
|
|
|
biaoshi[1] = true;
|
|
} else if (channel == 3) {
|
|
if (
|
|
this.guildmsg.length > 0 &&
|
|
this.compareint64(
|
|
arr[i].msg_uuid,
|
|
this.guildmsg[this.guildmsg.length - 1].msg_uuid
|
|
)
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
this.guildmsg.push(arr[i]);
|
|
if (this.guildmsg.length > this.guildmax) {
|
|
this.guildmsg.splice(0, 1);
|
|
}
|
|
biaoshi[2] = true;
|
|
} else if (channel == 4) {
|
|
if (
|
|
this.teammsg.length > 0 &&
|
|
this.compareint64(
|
|
arr[i].msg_uuid,
|
|
this.teammsg[this.teammsg.length - 1].msg_uuid
|
|
)
|
|
) {
|
|
continue;
|
|
}
|
|
this.teammsg.push(arr[i]);
|
|
if (this.teammsg.length > this.teammax) {
|
|
this.teammsg.splice(0, 1);
|
|
}
|
|
biaoshi[3] = true;
|
|
} else if (channel == 5) {
|
|
this.dalabamsg.push(arr[i]);
|
|
cc.Notifier.emit('refreshdalaba');
|
|
let msgBody01 = arr[i].msg_body;
|
|
cc.Notifier.emit('runMsg', '' + msgBody01);
|
|
}
|
|
}
|
|
|
|
cc.Notifier.emit('refreshchat', biaoshi);
|
|
},
|
|
|
|
getfriendmsg(accountid) {
|
|
if (!this.friendmsg[accountid]) {
|
|
this.friendmsg[accountid] = [];
|
|
try {
|
|
var str = cc.sys.localStorage.getItem(
|
|
SDKManage.account_id + accountid
|
|
);
|
|
if (str && str != '') {
|
|
this.friendmsg[accountid] = JSON.parse(str);
|
|
}
|
|
} catch (e) {
|
|
this.friendmsg[accountid] = [];
|
|
}
|
|
}
|
|
return this.friendmsg[accountid];
|
|
},
|
|
|
|
getLastidbyChannel(channel, accountid) {
|
|
var last_id = 0;
|
|
var arr;
|
|
if (channel == 1) {
|
|
arr = this.woldmsg;
|
|
} else if (channel == 2) {
|
|
if (!this.friendmsg[accountid]) {
|
|
this.friendmsg[accountid] = [];
|
|
}
|
|
try {
|
|
var str = cc.sys.localStorage.getItem(
|
|
SDKManage.account_id + accountid
|
|
);
|
|
if (str && str != '') {
|
|
this.friendmsg[accountid] = JSON.parse(str);
|
|
}
|
|
} catch (e) {
|
|
this.friendmsg[accountid] = [];
|
|
}
|
|
|
|
arr = this.friendmsg[accountid];
|
|
} else if (channel == 3) {
|
|
arr = this.guildmsg;
|
|
} else if (channel == 4) {
|
|
arr = this.teammsg;
|
|
}
|
|
|
|
if (arr && arr.length != 0) {
|
|
last_id = arr[arr.length - 1].msg_uuid;
|
|
}
|
|
return last_id;
|
|
},
|
|
|
|
getAllLastid() {
|
|
var temp = [
|
|
{
|
|
key: 1,
|
|
val: this.getLastidbyChannel(1),
|
|
},
|
|
{
|
|
key: 3,
|
|
val: this.getLastidbyChannel(3),
|
|
},
|
|
{
|
|
key: 4,
|
|
val: this.getLastidbyChannel(4),
|
|
},
|
|
];
|
|
return temp;
|
|
},
|
|
|
|
// update (dt) {
|
|
|
|
// },
|
|
});
|