public void DownloadMessageHistory(BinaryReader reader) { int smsCount = reader.ReadInt32(); for (int j = 0; j < smsCount; j++) { string contact = reader.ReadString(); int smsQueueCount = reader.ReadInt32(); textMessages.Add(contact, new Queue <DialogueNode>()); TextMessages.Add(contact, new Queue <TextMes>()); for (int i = 0; i < smsQueueCount; i++) { int nodeId = reader.ReadInt32(); string DialogId = reader.ReadString(); List <DialogueNode> nodes = CoreController.DialogueManager.GetNodesForDialogue(DialogId, BlockType.body, EGetDialogueNodeType.next, nodeId); DialogueNode tempNode = nodes.Find(n => n.Id == nodeId); TextMes tempMes = new TextMes() { node = tempNode, dialogId = DialogId }; textMessages[contact].Enqueue(tempNode); TextMessages[contact].Enqueue(tempMes); } } int emailCount = reader.ReadInt32(); for (int j = 0; j < smsCount; j++) { int emailQueueCount = reader.ReadInt32(); for (int i = 0; i < emailQueueCount; i++) { int nodeId = reader.ReadInt32(); int date = reader.ReadInt32(); List <DialogueNode> nodes = CoreController.DialogueManager.GetNodesForDialogue(Id, BlockType.body, EGetDialogueNodeType.next, nodeId); MessNode mes = new MessNode() { node = nodes.Find(n => n.Id == nodeId), date = CoreController.TimeModule.GetDate() }; emailMessages.Enqueue(mes); } } }
public void AddMessage(string charId, DialogueNode dialogueNode, MessageType mode, string dialogId) { DialogueNode tempNode; TextMes tempSms; switch (mode) { case MessageType.Sms: TextMes tempMess = new TextMes(); tempMess.node = dialogueNode; tempMess.dialogId = dialogId; if (!textMessages.ContainsKey(charId)) { textMessages.Add(charId, new Queue <DialogueNode>()); textMessages[charId].Enqueue(dialogueNode); TextMessages.Add(charId, new Queue <TextMes>()); TextMessages[charId].Enqueue(tempMess); } else { Queue <DialogueNode> temp = new Queue <DialogueNode>(textMessages[charId].Reverse()); Queue <TextMes> tempText = new Queue <TextMes>(TextMessages[charId].Reverse()); if (temp.Count > 0) { tempNode = temp.Peek(); tempSms = tempText.Peek(); if (tempNode.Id != dialogueNode.Id) { textMessages[charId].Enqueue(dialogueNode); TextMessages[charId].Enqueue(tempMess); } } else { textMessages[charId].Enqueue(dialogueNode); TextMessages[charId].Enqueue(tempMess); } } break; case MessageType.Email: Queue <MessNode> tempQ = new Queue <MessNode>(emailMessages.Reverse()); if (tempQ.Count > 0) { tempNode = tempQ.Peek().node; if (tempNode.Id != dialogueNode.Id) { MessNode mes = new MessNode() { node = dialogueNode, date = CoreController.TimeModule.GetDate() }; emailMessages.Enqueue(mes); } } else { MessNode mes = new MessNode() { node = dialogueNode, date = CoreController.TimeModule.GetDate() }; emailMessages.Enqueue(mes); } break; default: break; } }