Esempio n. 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.SendBirdActivityChat);
            this.Window.SetSoftInputMode(SoftInput.StateAlwaysHidden);

            InitFragment(savedInstanceState);
            InitUIComponents();
            InitSendBird(this.Intent.Extras);

            mMessageListQuery           = SendBirdSDK.QueryMessageList(mChannelUrl);
            mMessageListQuery.OnResult += (sender, e) => {
                // mSyncContext.Post for RunOnUIThread
                mSyncContext.Post(delegate {
                    foreach (var messageModel in e.Messages)
                    {
                        mSendBirdChatAdapter.AddMessageModel(messageModel);
                    }

                    mSendBirdChatFragment.mAdapter.NotifyDataSetChanged();
                    mSendBirdChatFragment.mListView.SetSelection(mSendBirdChatAdapter.Count);

                    SendBirdSDK.Join(mChannelUrl);
                    SendBirdSDK.Connect(mSendBirdChatAdapter.GetMaxMessageTimestamp());
                }, null);
            };
            mMessageListQuery.Prev(long.MaxValue, 50);              // Excute Query
        }
Esempio n. 2
0
        protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == REQUEST_CHANNEL_LIST)
            {
                if (resultCode == Android.App.Result.Ok && data != null)
                {
                    mChannelUrl = data.GetStringExtra("channelUrl");

                    mSendBirdChatAdapter.Clear();
                    mSendBirdChatAdapter.NotifyDataSetChanged();

                    mMessageListQuery           = SendBirdSDK.QueryMessageList(mChannelUrl);
                    mMessageListQuery.OnResult += (sender, e) => {
                        // mSyncContext.Post for RunOnUIThread
                        mSyncContext.Post(delegate {
                            foreach (var messageModel in e.Messages)
                            {
                                mSendBirdChatAdapter.AddMessageModel(messageModel);
                            }

                            mSendBirdChatAdapter.NotifyDataSetChanged();
                            mSendBirdChatFragment.mListView.SetSelection(mSendBirdChatAdapter.Count);

                            SendBirdSDK.Join(mChannelUrl);
                            SendBirdSDK.Connect(mSendBirdChatAdapter.GetMaxMessageTimestamp());
                        }, null);
                    };
                    mMessageListQuery.Prev(long.MaxValue, 50);                      // Excute Query
                }
            }
        }
Esempio n. 3
0
    public void OnQueryChannelList(List <Channel> channels)
    {
        mEventProcessor.QueueEvent(new Action(() => {
            foreach (UnityEngine.Object btnChannel in btnChannels)
            {
                GameObject.Destroy(btnChannel);
            }
            btnChannels.Clear();

            foreach (Channel channel in channels)
            {
                GameObject btnChannel = Instantiate(channelListItemPrefab) as GameObject;
                btnChannel.GetComponent <Image>().sprite = uiTheme.channelButtonOff;

                if (channel.url == selectedChannelUrl)
                {
                    btnChannel.GetComponent <Image>().overrideSprite = uiTheme.channelButtonOn;
                    btnChannel.GetComponentInChildren <Text>().color = uiTheme.channelButtonOnColor;
                }
                else
                {
                    btnChannel.GetComponent <Image>().overrideSprite = null;
                    btnChannel.GetComponentInChildren <Text>().color = uiTheme.channelButtonOffColor;
                }
                Text text = btnChannel.GetComponentInChildren <Text> ();
                text.text = "#" + channel.GetUrlWithoutAppPrefix();
                btnChannel.transform.SetParent(channelGridPannel.transform);
                btnChannel.transform.localScale = Vector3.one;
                btnChannels.Add(btnChannel);

                Channel channelFinal = channel;
                btnChannel.GetComponent <Button>().onClick.AddListener(() => {
                    ResetOpenChatContent();

                    SendBirdSDK.Join(channelFinal.url);
                    SendBirdSDK.Connect(GetMaxMessageTimestamp());

                    mEventProcessor.QueueEvent(new Action(() => {
                        channelPanel.SetActive(false);
                        SelectTab(TAB_MODE.CHANNEL);
                    }));
                });
            }
        }));
    }
        protected override void OnResume()
        {
            base.OnResume();
            var mMessageChannelListQuery = SendBirdSDK.QueryMessagingList();

            mMessageChannelListQuery.OnResult += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingChannelAdapter.Clear();
                    mSendBirdMessagingChannelAdapter.AddAll(e.MessagingChannels);
                    if (e.MessagingChannels.Count <= 0)
                    {
                        Toast.MakeText(this, "No messaging channels were found.", ToastLength.Short).Show();
                    }

                    mSendBirdMessagingChannelAdapter.NotifyDataSetChanged();

                    SendBirdSDK.Join("");
                    SendBirdSDK.Connect();
                }, null);
            };
            mMessageChannelListQuery.Excute();              // Excute Query
        }
Esempio n. 5
0
        private void InitSendBird(Bundle extras)
        {
            mSendBirdInfo = extras;

            String appId    = extras.GetString("appId");
            String uuid     = extras.GetString("uuid");
            String userName = extras.GetString("userName");

            mSyncContext = SynchronizationContext.Current;             // required for api queries

            #region SendBirdEventHandler

            SendBirdEventHandler seh = new SendBirdEventHandler();
            seh.OnConnect         += (sender, e) => {
            };
            seh.OnError           += (sender, e) => {
            };
            seh.OnChannelLeft     += (sender, e) => {
            };
            seh.OnMessageReceived += (sender, e) => {
                SendBirdSDK.MarkAsRead();
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.AddMessageModel(e.Message);
                }, null);
            };
            seh.OnBroadcastMessageReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.AddMessageModel(e.Message);
                }, null);
            };
            seh.OnSystemMessageReceived += (sender, e) => {
                var systemMessage = (SystemMessage)e.Message;
                mSyncContext.Post(delegate {
                    switch (systemMessage.category)
                    {
                    case SystemMessage.CATEGORY_TOO_MANY_MESSAGES:
                        systemMessage.SetMessage("Too many messages. Please try later.");
                        break;

                    case SystemMessage.CATEGORY_MESSAGING_USER_BLOCKED:
                        systemMessage.SetMessage("Blocked.");
                        break;

                    case SystemMessage.CATEGORY_MESSAGING_USER_DEACTIVATED:
                        systemMessage.SetMessage("Deactivated.");
                        break;
                    }

                    mSendBirdMessagingAdapter.AddMessageModel(systemMessage);
                }, null);
            };
            seh.OnFileReceived += (sender, e) => {
            };
            seh.OnReadReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.SetReadStatus(e.ReadStatus.GetUserId(), e.ReadStatus.timestamp);
                }, null);
            };
            seh.OnTypeStartReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.SetTypeStatus(e.TypeStatus.GetUserId(), SendBirdUtils.GetCurrentTimeMills());
                }, null);
            };
            seh.OnTypeEndReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.SetTypeStatus(e.TypeStatus.GetUserId(), 0);
                }, null);
            };
            seh.OnAllDataReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdMessagingAdapter.NotifyDataSetChanged();
                    mSendBirdMessagingFragment.mListView.SetSelection(mSendBirdMessagingAdapter.Count - 1);
                }, null);
            };
            seh.OnMessageDelivery += (sender, e) => {
                if (!e.Sent)
                {
                    mSyncContext.Post(delegate {
                        mSendBirdMessagingFragment.mEtxtMessage.Text = e.Message;
                    }, null);
                }
            };
            seh.OnMessagingStarted += (sender, e) => {
                mSendBirdMessagingAdapter.Clear();
                mSyncContext.Post(delegate {
                    UpdateMessagingChannel(e.MessagingChannel);

                    var channelUrl = e.MessagingChannel.GetUrl();

                    MessageListQuery messageListQuery = SendBirdSDK.QueryMessageList(channelUrl);
                    messageListQuery.OnResult        += (sender_child, e_child) => {
                        // mSyncContext.Post for RunOnUIThread
                        mSyncContext.Post(delegate {
                            foreach (var messageModel in e_child.Messages)
                            {
                                mSendBirdMessagingAdapter.AddMessageModel(messageModel);
                            }

                            mSendBirdMessagingAdapter.NotifyDataSetChanged();
                            mSendBirdMessagingFragment.mListView.SetSelection(30);

                            SendBirdSDK.MarkAsRead(channelUrl);
                            SendBirdSDK.Join(channelUrl);
                            SendBirdSDK.Connect(mSendBirdMessagingAdapter.GetMaxMessageTimestamp());
                        }, null);
                    };
                    messageListQuery.Prev(long.MaxValue, 50);                      // Excute Query
                }, null);
            };
            seh.OnMessagingUpdated += (sender, e) => {
                mSyncContext.Post(delegate {
                    UpdateMessagingChannel(e.MessagingChannel);
                }, null);
            };
            seh.OnMessagingChannelUpdated += (sender, e) => {
                if (mMessagingChannel != null && mMessagingChannel.GetId() == e.MessagingChannel.GetId())
                {
                    mSyncContext.Post(delegate {
                        UpdateMessagingChannel(e.MessagingChannel);
                    }, null);
                }
            };
            seh.OnMentionUpdated += (sender, e) => {
            };

            #endregion

            SendBirdSDK.Init(appId);
            SendBirdSDK.Login(uuid, userName);
            SendBirdSDK.SetEventHandler(seh);
        }
Esempio n. 6
0
    void InitComponents()
    {
        uiPanel = GameObject.Find("SendBirdUnity/UIPanel");
        (Instantiate(uiThemePrefab) as GameObject).transform.parent = uiPanel.transform;

        uiTheme = GameObject.FindObjectOfType(typeof(SendBirdTheme)) as SendBirdTheme;

        #region MenuPanel

        menuPanel = GameObject.Find("SendBirdUnity/UIPanel/MenuPanel");
        menuPanel.GetComponent <Image> ().sprite = uiTheme.channelListFrameBG;

        var txtMenuTitle = GameObject.Find("SendBirdUnity/UIPanel/MenuPanel/TxtTitle").GetComponent <Text> ();
        txtMenuTitle.color = uiTheme.titleColor;

        btnOpenChannel = GameObject.Find("SendBirdUnity/UIPanel/MenuPanel/BtnOpenChannel").GetComponent <Button> ();
        btnOpenChannel.GetComponent <Image> ().sprite = uiTheme.sendButton;
        btnOpenChannel.GetComponent <Image> ().type   = Image.Type.Sliced;
        btnOpenChannel.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                menuPanel.SetActive(false);
                openChatPanel.SetActive(true);

                ResetOpenChatContent();
                InitOpenChat();

                SendBirdSDK.Join("jia_test.lobby");
                SendBirdSDK.Connect(GetMaxMessageTimestamp());

                SelectTab(TAB_MODE.CHANNEL);
            }));
        });

        btnStartMessaging = GameObject.Find("SendBirdUnity/UIPanel/MenuPanel/BtnStartMessaging").GetComponent <Button> ();
        btnStartMessaging.GetComponent <Image> ().sprite = uiTheme.sendButton;
        btnStartMessaging.GetComponent <Image> ().type   = Image.Type.Sliced;
        btnStartMessaging.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                menuPanel.SetActive(false);
                userListPanel.SetActive(true);
                OpenUserList();
            }));
        });

        btnJoinMessaging = GameObject.Find("SendBirdUnity/UIPanel/MenuPanel/BtnJoinMessaging").GetComponent <Button> ();
        btnJoinMessaging.GetComponent <Image> ().sprite = uiTheme.sendButton;
        btnJoinMessaging.GetComponent <Image> ().type   = Image.Type.Sliced;
        btnJoinMessaging.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                menuPanel.SetActive(false);
                messagingChannelListPanel.SetActive(true);
                OpenMessagingList();
            }));
        });

        inputUserName = GameObject.Find("SendBirdUnity/UIPanel/MenuPanel/InputUserName").GetComponent <InputField> ();
        inputUserName.GetComponent <Image> ().sprite = uiTheme.inputTextBG;

        #endregion

        #region OpenChannel

        openChatPanel = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel");
        openChatPanel.GetComponent <Image> ().sprite = uiTheme.chatFrameBG;

        txtOpenChatContent       = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/ScrollArea/TxtContent").GetComponent <Text>();  // (Text);
        txtOpenChatContent.color = uiTheme.messageColor;

        txtOpenChatTitle       = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/TxtTitle").GetComponent <Text> ();
        txtOpenChatTitle.color = uiTheme.titleColor;

        openChatScrollbar = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/Scrollbar").GetComponent <Scrollbar>();

        ColorBlock cb = openChatScrollbar.colors;
        cb.normalColor           = uiTheme.scrollBarColor;
        cb.pressedColor          = uiTheme.scrollBarColor;
        cb.highlightedColor      = uiTheme.scrollBarColor;
        openChatScrollbar.colors = cb;
        openChatScrollbar.onValueChanged.AddListener((float value) => {
            if (value <= 0)
            {
                autoScroll        = true;
                lastTextPositionY = txtOpenChatContent.transform.position.y;
                return;
            }

            if (lastTextPositionY - txtOpenChatContent.transform.position.y >= 100)
            {
                autoScroll = false;
            }

            lastTextPositionY = txtOpenChatContent.transform.position.y;
        });

        inputOpenChat = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/InputOpenChat").GetComponent <InputField> ();
        inputOpenChat.GetComponent <Image> ().sprite = uiTheme.inputTextBG;
        inputOpenChat.onEndEdit.AddListener((string msg) => {
            SubmitOpenChat();
        });

        GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/InputOpenChat/Placeholder").GetComponent <Text> ().color = uiTheme.inputTextPlaceholderColor;
        GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/InputOpenChat/Text").GetComponent <Text> ().color        = uiTheme.inputTextColor;

        btnOpenChatSend = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/BtnOpenChatSend").GetComponent <Button> ();
        btnOpenChatSend.GetComponent <Image> ().sprite         = uiTheme.sendButton;
        btnOpenChatSend.GetComponentInChildren <Text> ().color = uiTheme.sendButtonColor;
        btnOpenChatSend.onClick.AddListener(() => {
            SubmitOpenChat();
        });

        btnClan = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/BtnClan").GetComponent <Button> ();
        btnClan.GetComponent <Image> ().sprite = uiTheme.chatChannelButtonOff;
        btnClan.onClick.AddListener(() => {
            ResetOpenChatContent();

            SendBirdSDK.Join("jia_test.clan");
            SendBirdSDK.Connect(GetMaxMessageTimestamp());

            SelectTab(TAB_MODE.CLAN);
        });

        btnOpenChatClose = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/BtnOpenChatClose").GetComponent <Button> ();
        btnOpenChatClose.GetComponent <Image> ().sprite = uiTheme.closeButton;
        btnOpenChatClose.onClick.AddListener(() => {
            Disconnect();
            mEventProcessor.QueueEvent(new Action(() => {
                openChatPanel.SetActive(false);
                menuPanel.SetActive(true);
            }));
        });

        btnChannel = GameObject.Find("SendBirdUnity/UIPanel/OpenChatPanel/BtnChannel").GetComponent <Button> ();
        btnChannel.GetComponent <Image> ().sprite = uiTheme.chatChannelButtonOff;
        btnChannel.onClick.AddListener(() => {
            OpenChannelList();
        });

        #endregion

        #region ChannelList

        channelPanel = GameObject.Find("SendBirdUnity/UIPanel/ChannelPanel");
        channelPanel.GetComponent <Image> ().sprite = uiTheme.channelListFrameBG;

        channelGridPannel = GameObject.Find("SendBirdUnity/UIPanel/ChannelPanel/ScrollArea/GridPanel");

        GameObject.Find("SendBirdUnity/UIPanel/ChannelPanel/TxtTitle").GetComponent <Text> ().color = uiTheme.titleColor;

        var channelScrollbar = GameObject.Find("SendBirdUnity/UIPanel/ChannelPanel/Scrollbar").GetComponent <Scrollbar>();
        cb                      = channelScrollbar.colors;
        cb.normalColor          = uiTheme.scrollBarColor;
        cb.pressedColor         = uiTheme.scrollBarColor;
        cb.highlightedColor     = uiTheme.scrollBarColor;
        channelScrollbar.colors = cb;

        btnChannelClose = GameObject.Find("SendBirdUnity/UIPanel/ChannelPanel/BtnChannelClose").GetComponent <Button> ();
        btnChannelClose.GetComponent <Image> ().sprite = uiTheme.closeButton;
        btnChannelClose.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                channelPanel.SetActive(false);
            }));
        });

        #endregion

        #region Messaging

        messagingPanel = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel");
        messagingPanel.GetComponent <Image> ().sprite = uiTheme.chatFrameBG;

        txtMessagingTitle       = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/TxtTitle").GetComponent <Text> ();
        txtMessagingTitle.color = uiTheme.titleColor;

        btnMessagingClose = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/BtnMessagingClose").GetComponent <Button> ();
        btnMessagingClose.GetComponent <Image> ().sprite = uiTheme.closeButton;
        btnMessagingClose.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                messagingPanel.SetActive(false);
                menuPanel.SetActive(true);
            }));
        });

        txtMessagingContent       = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/ScrollArea/TxtContent").GetComponent <Text>();  // (Text);
        txtMessagingContent.color = uiTheme.messageColor;

        txtMessagingTitle       = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/TxtTitle").GetComponent <Text> ();
        txtMessagingTitle.color = uiTheme.titleColor;

        messagingScrollbar = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/Scrollbar").GetComponent <Scrollbar>();
        ColorBlock cb_messaging = messagingScrollbar.colors;
        cb_messaging.normalColor      = uiTheme.scrollBarColor;
        cb_messaging.pressedColor     = uiTheme.scrollBarColor;
        cb_messaging.highlightedColor = uiTheme.scrollBarColor;
        messagingScrollbar.colors     = cb_messaging;
        messagingScrollbar.onValueChanged.AddListener((float value) => {
            if (value <= 0)
            {
                autoScroll        = true;
                lastTextPositionY = txtMessagingContent.transform.position.y;
                return;
            }

            if (lastTextPositionY - txtMessagingContent.transform.position.y >= 100)
            {
                autoScroll = false;
            }

            lastTextPositionY = txtMessagingContent.transform.position.y;
        });

        inputMessaging = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/InputMessaging").GetComponent <InputField> ();
        inputMessaging.GetComponent <Image> ().sprite = uiTheme.inputTextBG;
        inputMessaging.onEndEdit.AddListener((string msg) => {
            SubmitMessaging();
        });

        GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/InputMessaging/Placeholder").GetComponent <Text> ().color = uiTheme.inputTextPlaceholderColor;
        GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/InputMessaging/Text").GetComponent <Text> ().color        = uiTheme.inputTextColor;

        btnMessagingSend = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/BtnMessagingSend").GetComponent <Button> ();
        btnMessagingSend.GetComponent <Image> ().sprite         = uiTheme.sendButton;
        btnMessagingSend.GetComponentInChildren <Text> ().color = uiTheme.sendButtonColor;
        btnMessagingSend.onClick.AddListener(() => {
            SubmitMessaging();
        });

        btnMessagingList = GameObject.Find("SendBirdUnity/UIPanel/MessagingPanel/BtnMessagingList").GetComponent <Button> ();
        btnMessagingList.GetComponent <Image> ().sprite        = uiTheme.chatChannelButtonOff;
        btnMessagingList.GetComponent <Image> ().type          = Image.Type.Sliced;
        btnMessagingList.GetComponentInChildren <Text>().color = uiTheme.chatChannelButtonOffColor;
        btnMessagingList.onClick.AddListener(() => {
            OpenMessagingList();
        });

        #endregion

        #region UserList

        userListPanel = GameObject.Find("SendBirdUnity/UIPanel/UserListPanel");
        userListPanel.GetComponent <Image> ().sprite = uiTheme.channelListFrameBG;

        userListGridPanel = GameObject.Find("SendBirdUnity/UIPanel/UserListPanel/ScrollArea/GridPanel");

        GameObject.Find("SendBirdUnity/UIPanel/UserListPanel/TxtTitle").GetComponent <Text> ().color = uiTheme.titleColor;

        var userListScrollBar = GameObject.Find("SendBirdUnity/UIPanel/UserListPanel/Scrollbar").GetComponent <Scrollbar>();
        cb                       = userListScrollBar.colors;
        cb.normalColor           = uiTheme.scrollBarColor;
        cb.pressedColor          = uiTheme.scrollBarColor;
        cb.highlightedColor      = uiTheme.scrollBarColor;
        userListScrollBar.colors = cb;
        userListScrollBar.onValueChanged.AddListener((float value) => {
            if (value <= 0)
            {
                LoadMoreUsers();
            }
        });

        btnUserListClose = GameObject.Find("SendBirdUnity/UIPanel/UserListPanel/BtnUserListClose").GetComponent <Button> ();
        btnUserListClose.GetComponent <Image> ().sprite = uiTheme.closeButton;
        btnUserListClose.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                userListPanel.SetActive(false);
                menuPanel.SetActive(true);
            }));
        });

        btnInvite = GameObject.Find("SendBirdUnity/UIPanel/UserListPanel/BtnInvite").GetComponent <Button> ();
        btnInvite.GetComponent <Image> ().sprite = uiTheme.sendButton;
        btnInvite.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                userListPanel.SetActive(false);
                messagingPanel.SetActive(true);
            }));
            InviteMessaging(mUserList);
        });

        #endregion

        #region MessagingList

        messagingChannelListPanel = GameObject.Find("SendBirdUnity/UIPanel/MessagingChannelListPanel");
        messagingChannelListPanel.GetComponent <Image> ().sprite = uiTheme.channelListFrameBG;

        messagingChannelListGridPanel = GameObject.Find("SendBirdUnity/UIPanel/MessagingChannelListPanel/ScrollArea/GridPanel");

        GameObject.Find("SendBirdUnity/UIPanel/MessagingChannelListPanel/TxtTitle").GetComponent <Text> ().color = uiTheme.titleColor;

        var messagingChannelListScrollbar = GameObject.Find("SendBirdUnity/UIPanel/MessagingChannelListPanel/Scrollbar").GetComponent <Scrollbar>();
        cb                  = messagingChannelListScrollbar.colors;
        cb.normalColor      = uiTheme.scrollBarColor;
        cb.pressedColor     = uiTheme.scrollBarColor;
        cb.highlightedColor = uiTheme.scrollBarColor;
        messagingChannelListScrollbar.colors = cb;
        messagingChannelListScrollbar.onValueChanged.AddListener((float value) => {
            if (value <= 0)
            {
            }
        });

        btnMessagingClose = GameObject.Find("SendBirdUnity/UIPanel/MessagingChannelListPanel/BtnMessagingChannelListClose").GetComponent <Button> ();
        btnMessagingClose.GetComponent <Image> ().sprite = uiTheme.closeButton;
        btnMessagingClose.onClick.AddListener(() => {
            mEventProcessor.QueueEvent(new Action(() => {
                messagingChannelListPanel.SetActive(false);
                if (!messagingPanel.activeSelf)
                {
                    menuPanel.SetActive(true);
                }
            }));
        });

        #endregion

        uiPanel.SetActive(true);
        menuPanel.SetActive(true);
        openChatPanel.SetActive(false);
        channelPanel.SetActive(false);
        messagingPanel.SetActive(false);
        userListPanel.SetActive(false);
        messagingChannelListPanel.SetActive(false);
    }
Esempio n. 7
0
    public void InitMessaging()
    {
        currentUserName = inputUserName.text;
        SendBirdSDK.Login(userId, currentUserName);

        SendBirdEventHandler seh = new SendBirdEventHandler();

        seh.OnConnect += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                selectedChannelUrl = e.Channel.url;
            }));
        };
        seh.OnError           += (sender, e) => {
        };
        seh.OnChannelLeft     += (sender, e) => {
        };
        seh.OnMessageReceived += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                Message message          = e.Message as Message;
                txtMessagingContent.text = txtMessagingContent.text + (MessageRichText(message) + "\n");
                ScrollToBottom();
            }));
            // markasread
        };
        seh.OnBroadcastMessageReceived += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                BroadcastMessage bm      = e.Message as BroadcastMessage;
                txtMessagingContent.text = txtMessagingContent.text + (SystemMessageRichText(bm.message) + "\n");
            }));
        };
        seh.OnSystemMessageReceived += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                SystemMessage sm         = e.Message as SystemMessage;
                txtMessagingContent.text = txtMessagingContent.text + (SystemMessageRichText(sm.message) + "\n");
            }));
        };
        seh.OnAllDataReceived   += (sender, e) => {
        };
        seh.OnMessageDelivery   += (sender, e) => {
        };
        seh.OnReadReceived      += (sender, e) => {
        };
        seh.OnTypeStartReceived += (sender, e) => {
        };
        seh.OnTypeEndReceived   += (sender, e) => {
        };
        seh.OnMessagingStarted  += (sender, e) => {
            UpdateMessagingChannel(e.MessagingChannel);

            var messagingChannelUrl = e.MessagingChannel.GetUrl();
            // message query
            MessageListQuery messageListQuery = SendBirdSDK.QueryMessageList(messagingChannelUrl);
            messageListQuery.OnResult += (sender_child, e_child) => {
                mEventProcessor.QueueEvent(new Action(() => {
                    foreach (var messageModel in e_child.Messages)
                    {
                        if (messageModel is Message)
                        {
                            var message = messageModel as Message;
                            if (message.IsPast())
                            {
                                txtMessagingContent.text = (MessageRichText(message) + "\n") + txtMessagingContent.text;
                            }
                            else
                            {
                                txtMessagingContent.text = txtMessagingContent.text + (MessageRichText(message) + "\n");
                            }
                            UpdateMessageTimestamp(message);
                        }
                        else if (messageModel is SystemMessage)
                        {
                            var message = messageModel as SystemMessage;
                            if (message.IsPast())
                            {
                                txtMessagingContent.text = (SystemMessageRichText(message.message) + "\n") + txtMessagingContent.text;
                            }
                            else
                            {
                                txtMessagingContent.text = txtMessagingContent.text + (SystemMessageRichText(message.message) + "\n");
                            }
                            UpdateMessageTimestamp(message);
                        }
                        else if (messageModel is BroadcastMessage)
                        {
                            var message = messageModel as BroadcastMessage;
                            if (message.IsPast())
                            {
                                txtMessagingContent.text = (SystemMessageRichText(message.message) + "\n") + txtMessagingContent.text;
                            }
                            else
                            {
                                txtMessagingContent.text = txtMessagingContent.text + (SystemMessageRichText(message.message) + "\n");
                            }
                            UpdateMessageTimestamp(message);
                        }
                    }

                    SendBirdSDK.MarkAsRead(messagingChannelUrl);
                    SendBirdSDK.Join(messagingChannelUrl);
                    SendBirdSDK.Connect(GetMaxMessageTimestamp());
                }));
            };
            messageListQuery.Prev(long.MaxValue, 50);
        };
        seh.OnMessagingUpdated += (sender, e) => {
            UpdateMessagingChannel(e.MessagingChannel);
        };
        seh.OnMessagingChannelUpdated += (sender, e) => {
            if (mMessagingChannel != null && mMessagingChannel.GetId() == e.MessagingChannel.GetId())
            {
                mEventProcessor.QueueEvent(new Action(() => {
                    UpdateMessagingChannel(e.MessagingChannel);
                }));
            }
        };

        SendBirdSDK.SetEventHandler(seh);
    }