Ejemplo n.º 1
0
        public void OnUserMessageReceived()
        {
            ChatCardViewController card = CreateCard(m_UserCardPrefab);

            // Set whether avatar should be enabled based on last message
            if (m_WasLastMessageFromBot || m_MessageBeginIndex == -1)
            {
                card.SetAvatarEnabled(true);
                m_MessageBeginIndex = m_Messages.Count;
            }
            else
            {
                for (int i = m_MessageBeginIndex; i < m_Messages.Count; i++)
                {
                    m_Messages[i].Value.SetAvatarEnabled(false);
                }
            }

            //card.AddContent(m_ContentFactory.Create(activity));


            m_WasLastMessageFromBot = false;
            //m_Messages.Add(card);
            //m_Messages.Add(new KeyValuePair<Activity, ChatCardViewController>(activity, card));
            card.SetAvatarImage(m_UserManager.CurrentUser.userPicture);
        }
Ejemplo n.º 2
0
        private void OnBotMessageReceived(Activity activity)
        {
            if (activity.Type != "message")
            {
                return;
            }

            if (m_Messages.Any(x => x.Key.Id == activity.Id))
            {
                return;
            }

            if (m_LastActivity != null &&
                m_LastActivity.Value == activity.Value &&
                m_LastActivity.Text == activity.Text &&
                m_LastActivity.Name == activity.Name &&
                !(activity.Name == null && activity.Text == null))
            {
                m_BotMessenger?.ResendLastActivityAsync();
                return;
            }

            GameObject content = m_ContentFactory.Create(activity);

            if (content == null)
            {
                return;
            }


            ChatCardViewController card = CreateCard(m_BotCardPrefab);

            AddMessage(card.gameObject);

            // Set whether avatar should be enabled based on last message
            if (!m_WasLastMessageFromBot || m_MessageBeginIndex == -1)
            {
                card.SetAvatarEnabled(true);
                m_MessageBeginIndex = m_Messages.Count;
            }
            else
            {
                for (int i = m_MessageBeginIndex; i < m_Messages.Count; i++)
                {
                    m_Messages[i].Value.SetAvatarEnabled(false);
                }
            }

            m_LastActivity = activity;

            m_AciEventManager.Invoke(new BotMessageReceivedEvent());

            card.AddContent(content);

            m_WasLastMessageFromBot = true;
            //m_Messages.Add(card);
            m_Messages.Add(new KeyValuePair <Activity, ChatCardViewController>(activity, card));
            EnsureCorrectOrder();

            PlayNotificationSound();
        }