public override void Show(ChatLog chatLog)
        {
            base.Show(chatLog);

            // Set GroupItem  //
            GroupItem groupItem = GlobalGroup.GetInstance().GetGroup(chatLog.chatID);
            if (groupItem != null)
            {
                if (_labelUserName)
                {
                    _labelUserName.text = groupItem.groupName;
                }
            }

            if (_imageHead != null)
            {
                int headCount = groupItem.memberUserId.Count > 9 ? 9 : groupItem.memberUserId.Count;
                UIManager.GetInstance().RefreshChildren(_imageHead.gameObject, EUIType.GroupMemberHeadIcon, headCount);

                for (int i = 0; i < headCount; i++)
                {
                    string userID = groupItem.memberUserId[i];
                    UserItem userItem = GlobalGroup.GetInstance().GetGroupMember(userID);
                    if (userItem == null)
                    {
                        userItem = new UserItem();
                    }

                    GameObject go = _imageHead.transform.GetChild(i).gameObject;
                    go.GetComponent<GroupMemberFrame>().Show(userItem);
                }
            }
        }
 private void ResetChtFrame(int index, ChatLog chatLog)
 {
     if (chatLog.targetType != _chatFrameList[index].GetTargetType())
     {
         int siblingIndex = _chatFrameList[index].transform.GetSiblingIndex();
         GameObject.Destroy(_chatFrameList[index].gameObject);
         GameObject newGo = AddChatFrame(chatLog);
         _chatFrameList[index] = newGo.GetComponent<ChatFrame>();
         newGo.transform.SetSiblingIndex(siblingIndex);
     }
 }
        private GameObject AddChatFrame(ChatLog chatLog)
        {
            if (chatLog.targetType == ChatDataItem.TargetType.INDIVIDUAL)
            {
                return UIManager.GetInstance().AddChild(_chatGrid.gameObject, EUIType.ChatFrame);

            }
            else
            {
                return UIManager.GetInstance().AddChild(_chatGrid.gameObject, EUIType.GroupChatFrame);
            }
        }
예제 #4
0
        public virtual void Show(ChatLog chatLog)
        {
            _chatLog = chatLog;

            // Set UserItem //

            UserItem userItem = GlobalContacts.GetInstance().GetUserItemById(chatLog.chatID);
            if (userItem != null && chatLog.targetType == ChatDataItem.TargetType.INDIVIDUAL)
            {
                if (_imageHead)
                {
                    UIManager.GetInstance().SetImage(_imageHead, EAtlasName.Head, "00" + userItem.headIndex);                    
                }

                if (_labelUserName)
                {
                    _labelUserName.text = userItem.userName;                    
                }
            }


            // Set ChatItem //
            if (_labelLastChat)
            {
                _labelLastChat.text = "";
                ChatDataItem lastChat = GlobalChat.GetInstance().GetLastChat(chatLog.chatID);
                if (lastChat != null)
                {
                    if (lastChat.chatType == ChatDataItem.ChatType.TEXT)
                    {
                        _labelLastChat.text = lastChat.chatBody;
                    }
                    else if (lastChat.chatType == ChatDataItem.ChatType.IMAGE)
                    {
                        _labelLastChat.text = "[表情]";
                    }
                }                
            }

            if (_labelDate)
            {
                _labelDate.text = DateFormatTool.GetChatFrameTimeStr(_chatLog.date);          
            }

            if (_imageUnRead)
            {
                int num = GlobalChat.GetInstance().GetUnReadNum(_chatLog.chatID);
                num = (num > 99) ? 99 : num;
                _imageUnRead.gameObject.SetActive(num != 0);
                _labelUnReadNum.text = num.ToString();
            }
        }
예제 #5
0
        /// <summary>
        /// 通过chatID来获取ChatLog
        /// </summary>
        /// <param name="chatID">当chatLog为群聊的时候,chatID为群ID,否则为userID</param>
        /// <returns></returns>
        public ChatLog GetChatLog(string chatID)
        {
            if (!_chatLogDict.ContainsKey(chatID))
            {
                ChatLog chatLog = new ChatLog
                {
                    chatID = chatID,
                };

                _chatLogDict.Add(chatID, chatLog);
            }

            return(_chatLogDict[chatID]);
        }
예제 #6
0
        public void MarkForRead(string chatID)
        {
            ChatLog chatLog = GetChatLog(chatID);

            for (int i = chatLog.itemList.Count - 1; i >= 0; i--)
            {
                if (chatLog.itemList[i].isRead)
                {
                    break;
                }

                chatLog.itemList[i].isRead = true;
            }
        }
예제 #7
0
 private void LoadLogDict()
 {
     ClearLogDict();
     if (IOTool.IsDirExist(GetChatDirPath()))
     {
         foreach (var file in IOTool.GetFiles(GetChatDirPath()))
         {
             ChatLog chatLog = IOTool.DeserializeFromFile <ChatLog>(file.FullName);
             if (chatLog != null)
             {
                 _chatLogDict[chatLog.chatID] = chatLog;
             }
         }
     }
 }
예제 #8
0
        public override void OnShow(object param = null)
        {
            base.OnShow(param);

            if (param != null)
            {
                _chatLog = param as ChatLog;
            }

            RefreshChatLog();

            MessageDispatcher.GetInstance().RegisterMessageHandler((uint)EUIMessage.UPDATE_RECEIVE_CHAT, OnUpdateReceiveChat);
            MessageDispatcher.GetInstance().RegisterMessageHandler((uint)EUIMessage.UPDATE_SEND_CHAT, OnUpdateSendChat);
            MessageDispatcher.GetInstance().RegisterMessageHandler((uint)EUIMessage.DELETE_CHAT_ITEM, OnDeleteChatItem);
        }
예제 #9
0
        public override void OnShow(object param = null)
        {
            base.OnShow(param);

            if (param != null)
            {
                _chatLog = param as ChatLog;
            }

            RefreshChatLog();

            MessageDispatcher.GetInstance().RegisterMessageHandler((uint)EUIMessage.UPDATE_RECEIVE_CHAT, OnUpdateReceiveChat);
            MessageDispatcher.GetInstance().RegisterMessageHandler((uint)EUIMessage.UPDATE_SEND_CHAT, OnUpdateSendChat);
            MessageDispatcher.GetInstance().RegisterMessageHandler((uint)EUIMessage.DELETE_CHAT_ITEM, OnDeleteChatItem);
        }
예제 #10
0
        public int GetUnReadNum(string chatID)
        {
            int     num     = 0;
            ChatLog chatLog = GetChatLog(chatID);

            for (int i = chatLog.itemList.Count - 1; i >= 0; i--)
            {
                if (chatLog.itemList[i].isRead)
                {
                    break;
                }

                num++;
            }
            return(num);
        }
예제 #11
0
        private void AddChatDataItem(ChatDataItem chatDataItem)
        {
            string chatID = null;

            if (chatDataItem.targetType == ChatDataItem.TargetType.INDIVIDUAL)
            {
                if (chatDataItem.sendUserId == GlobalUser.GetInstance().UserId)
                {
                    chatID = chatDataItem.receiveUserId;
                }
                else
                {
                    chatID = chatDataItem.sendUserId;
                }
            }
            else
            {
                chatID = chatDataItem.receiveUserId;
            }


            if (!_chatLogDict.ContainsKey(chatID))
            {
                ChatLog chatLog = new ChatLog
                {
                    chatID = chatID,
                };

                _chatLogDict.Add(chatID, chatLog);
            }

            if (chatDataItem.sendUserId == GlobalUser.GetInstance().UserId)
            {
                chatDataItem.isRead = true;
            }

            _chatLogDict[chatID].itemList.Remove(chatDataItem);

            _chatLogDict[chatID].date       = chatDataItem.date;
            _chatLogDict[chatID].targetType = chatDataItem.targetType;
            _chatLogDict[chatID].itemList.Add(chatDataItem);
        }
예제 #12
0
 private static int SortChatLogByDate(ChatLog c1, ChatLog c2)
 {
     return(-(new DateTime(c1.date)).CompareTo(new DateTime(c2.date)));
 }