import SDKPacket from "../SDKNetwork/SDKPacket"; import SDKPackets from "../SDKNetwork/SDKPackets"; export default class SDKHistoryInfo { private _userIds: Array; private _userMsgs: Object; private _packets: Array; private _isParse : boolean; /**临时存储的历史信息 */ private _historyMsgs: Object; constructor() { this.reset(); } public get isParse():boolean{ return this._isParse; } public set isParse(value:boolean){ this._isParse = value; } public set historyMsgs(value: Object) { this._historyMsgs = value; } public get historyMsgs(): Object { return this._historyMsgs; } public set userMsgs(value: Object) { this._userMsgs = value; } public get userMsgs(): Object { return this._userMsgs; } public addPacket(userId: number, value: SDKPacket): void { if (this._userIds.indexOf(userId) == -1) { this._userIds.push(userId); this._packets.push(new SDKPackets()); } let index = this._userIds.indexOf(userId); this._packets[index].addPacket(value); } public getPacketByIndex(userId: number, index: number): SDKPacket { if (this._userIds.indexOf(userId) == -1) { return null; } let userIndex = this._userIds.indexOf(userId); return this._packets[userIndex].getPacketByIndex(index); } public getLastPacket(userId): SDKPacket { if (this._userIds.indexOf(userId) == -1) { return null; } let userIndex = this._userIds.indexOf(userId); let packets = this._packets[userIndex]; if (packets.getPacketsCount() == 0) { return null; } return packets.getPacketByIndex(packets.getPacketsCount() - 1); } public getPacketsCount(userId: number): number { if (this._userIds.indexOf(userId) == -1) { return 0; } let userIndex = this._userIds.indexOf(userId); return this._packets[userIndex].getPacketsCount(); } public clear(): void { let index = 0, count = 0; count = this._packets.length; for (index = 0; index < count; index++) { this._packets[index].clear(); } this._packets = []; this._userIds = []; this._userMsgs = {}; this._historyMsgs = null; } public reset(): void { this._historyMsgs = null; this._packets = []; this._userIds = []; this._userMsgs = {}; this._isParse = false; } }