消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 lines
2.1 KiB

export class ChatManager {
private static _instance: ChatManager;
public static get instance(): ChatManager {
if (!this._instance) {
this._instance = new ChatManager();
}
return this._instance;
}
private _chatList: ChatGroupInfo[] = [];
private _chatMsgList: ChatMsg[] = [];
private _self: string;
init(selfName: string) {
this._self = selfName;
this._chatList = [];
this._chatMsgList = [];
}
sendMsg(msg: string, type: number, groupId: string, groupName: string, data: any, isNew: boolean = false) {
if (this.checkMsgAdded(data)) return;
let g: ChatGroupInfo = this._chatList.find(x => x.GroupID == groupId);
if (!g) {
g = new ChatGroupInfo();
g.GroupID = groupId;
g.GroupName = groupName;
g.GroupIcon = [];
this._chatList.push(g);
}
let m: ChatMsg = new ChatMsg();
m.Data = data;
m.GroupID = groupId;
m.Msg = msg;
m.MsgType = type;
m.UserID = groupName;
m.IsRead = groupName == this._self;
m.ImgUrl = "";
m.MsgID = "";
m.Time = Date.now();
this._chatMsgList.push(m);
g.LastMsg = m;
g.HaveNewMsg = isNew;
return m;
}
checkMsgAdded(data) {
return this._chatMsgList.find(x => x.Data == data) != null;
}
getChatList() {
return this._chatList;
}
getMsgList(GroupID: string) {
let group = this._chatList.find(x => x.GroupID == GroupID);
if (!group) return [];
group.HaveNewMsg = false;
let msgList = this._chatMsgList.filter(x => x.GroupID == GroupID);
return msgList;
}
}
export class ChatUserInfo {
UserID: string;
Head: string;
}
export class ChatGroupInfo {
GroupID: string;
GroupName: string;
GroupIcon: string[];
LastMsg: ChatMsg;
HaveNewMsg: boolean;
TaskID: number;
}
export class ChatMsg {
Data: any;
MsgID: string;
UserID: string;
GroupID: string;
Msg: string;
MsgType: number;
IsRead: boolean;
ImgUrl: string;
Time: number;
}