Ejemplo n.º 1
0
        public void Refresh()
        {
            DataChat chat = ChatManager.GetChat(mCurrentContact.ID);

            if (chat == null)
            {
                Clear();
                return;
            }

            bool addedNewMessage = false;

            // Add new messages
            for (int i = 0; i < chat.Messages.Length; i++)
            {
                DataChatMessage message = chat.Messages[i];

                if (mListedEntries.Contains(message.ID))
                {
                    continue;                     // Message is already in the log
                }
                mListedEntries.Add(message.ID);

                bool shouldAppend = false;

                // Check if this message should be appended to the latest entry or create new entry
                if (mChatLog.Count > 0)
                {
                    ChatUIEntry lastEntry = mChatLog[mChatLog.Count - 1];

                    if (lastEntry.FromUser.ID == message.User.ID &&
                        (message.CreatedAt.Value - lastEntry.LastMessageTime) < TimeSpan.FromMinutes(4))
                    {
                        shouldAppend = true;
                    }
                }

                if (shouldAppend)
                {
                    mChatLog[mChatLog.Count - 1].AddMessage(message);
                }
                else
                {
                    ChatUIEntry newEntry = Instantiate(message.User.IsMe ? mEntryMe : mEntryOther, mChatLogRoot);
                    mChatLog.Add(newEntry);
                    newEntry.Initialize(message);
                }

                addedNewMessage = true;
            }

            if (addedNewMessage)
            {
                Vector2 position = mChatLogRoot.anchoredPosition;
                position.y = 0;
                mChatLogRoot.anchoredPosition = position;
            }
        }
Ejemplo n.º 2
0
        public static DataChatMessage[] ListFromData(List <object> data)
        {
            DataChatMessage[] result = new DataChatMessage[data.Count];

            for (int i = 0; i < data.Count; i++)
            {
                result[i] = new DataChatMessage();
                result[i].SetData(data[i] as Dictionary <string, object>);
            }

            return(result);
        }
Ejemplo n.º 3
0
        public void Initialize(DataChatMessage message)
        {
            FromUser        = message.User;
            LastMessageTime = message.CreatedAt.Value;

            mProfileImage.SetDetails(message.User.UserDetails);

            mNameText.text = message.User.UserDetails.FullName;

            Color nameColor;

            ColorUtility.TryParseHtmlString(message.User.IsMe ? NAME_COLOR_ME : NAME_COLOR_OTHER, out nameColor);
            mNameText.color = nameColor;

            mTimeText.text = message.CreatedAt.Value.ToString(TIME_FORMAT);
            mChatText.text = message.Body;

            gameObject.SetActive(true);
        }
Ejemplo n.º 4
0
        public override void SetData(Dictionary <string, object> data)
        {
            base.SetData(data);

            List <object> userData = GetList(data, KEY_USERS);

            Users = new DataUser[userData.Count];

            for (int i = 0; i < Users.Length; i++)
            {
                Users[i] = DataUser.GetUser(userData[i] as Dictionary <string, object>);
            }

            Messages = DataChatMessage.ListFromData(GetList(data, KEY_MESSAGES));

            for (int i = 0; i < Users.Length; i++)
            {
                if (!Users[i].IsMe)
                {
                    Contact = Users[i];
                    break;
                }
            }
        }
Ejemplo n.º 5
0
 public void AddMessage(DataChatMessage message)
 {
     LastMessageTime = message.CreatedAt.Value;
     mChatText.text += "\n" + message.Body;
 }