private void InitSendBird(Bundle extras)
        {
            if (extras != null)
            {
                String appId    = extras.GetString("appId");
                String uuid     = extras.GetString("uuid");
                String userName = extras.GetString("userName");

                mSyncContext = SynchronizationContext.Current;                 // required for ui update

                SendBirdEventHandler seh = new SendBirdEventHandler();
                seh.OnConnect                 += (sender, e) => {
                };
                seh.OnError                   += (sender, e) => {
                };
                seh.OnMessagingEnded          += (sender, e) => {
                };
                seh.OnMessagingChannelUpdated += (sender, e) => {
                    mSendBirdMessagingChannelAdapter.Replace(e.MessagingChannel);
                };
                seh.OnMentionUpdated += (sender, e) => {
                };

                SendBirdSDK.Init(appId);
                SendBirdSDK.Login(uuid, userName);
                SendBirdSDK.SetEventHandler(seh);
            }
        }
Example #2
0
    public void InitOpenChat()
    {
        currentUserName = inputUserName.text;
        SendBirdSDK.Login(userId, currentUserName);

        SendBirdEventHandler seh = new SendBirdEventHandler();

        seh.OnConnect += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                txtOpenChatTitle.text = "#" + e.Channel.GetUrlWithoutAppPrefix();
                selectedChannelUrl    = e.Channel.url;
            }));
        };
        seh.OnError += (sender, e) => {
            if (e.Exception != null)
            {
                Debug.Log(e.Exception.StackTrace);
            }
        };
        seh.OnChannelLeft     += (sender, e) => {
        };
        seh.OnMessageReceived += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                Message message         = e.Message as Message;
                txtOpenChatContent.text = txtOpenChatContent.text + (MessageRichText(message) + "\n");
                ScrollToBottom();
            }));
        };
        seh.OnBroadcastMessageReceived += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                BroadcastMessage bm     = e.Message as BroadcastMessage;
                txtOpenChatContent.text = txtOpenChatContent.text + (SystemMessageRichText(bm.message) + "\n");
            }));
        };
        seh.OnSystemMessageReceived += (sender, e) => {
            mEventProcessor.QueueEvent(new Action(() => {
                SystemMessage sm        = e.Message as SystemMessage;
                txtOpenChatContent.text = txtOpenChatContent.text + (SystemMessageRichText(sm.message) + "\n");
            }));
        };
        seh.OnAllDataReceived += (sender, e) => {
        };
        seh.OnMessageDelivery += (sender, e) => {
        };

        SendBirdSDK.SetEventHandler(seh);
    }
        private void InitSendBird(Bundle extras)
        {
            if (extras != null)
            {
                String appId    = extras.GetString("appId");
                String uuid     = extras.GetString("uuid");
                String userName = extras.GetString("userName");

                mSyncContext = SynchronizationContext.Current;                 // required for ui update

                SendBirdNotificationHandler jnh = new SendBirdNotificationHandler();
                jnh.OnMessagingChannelUpdated += (sender, e) => {
                    mSendBirdMessagingChannelAdapter.Replace(e.MessagingChannel);
                };
                jnh.OnMentionUpdated += (sender, e) => {
                };

                SendBirdEventHandler ieh = new SendBirdEventHandler();
                ieh.OnConnect += (sender, e) => {
                };
                ieh.OnError   += (sender, e) => {
                    if (SendBird.CommonVar.IS_DEBUG)
                    {
                        Console.WriteLine("ieh Messaging OnError");
                        Console.WriteLine(e.ErrorCode);
                    }
                };
                ieh.OnMessagingEnded += (sender, e) => {
                };

                SendBirdSDK.Init(appId);
                SendBirdSDK.Login(uuid, userName);
                SendBirdSDK.RegisterNotificationHandler(jnh);
                SendBirdSDK.SetEventHandler(ieh);
            }
        }
Example #4
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);
        }
Example #5
0
        private void InitSendBird(Bundle extras)
        {
            string appId    = extras.GetString("appId");
            string uuid     = extras.GetString("uuid");
            string userName = extras.GetString("userName");

            mChannelUrl = extras.GetString("channelUrl");

            mSyncContext = SynchronizationContext.Current;             // required for ui update
            #region SendBirdEventHandler

            SendBirdEventHandler seh = new SendBirdEventHandler();
            seh.OnConnect += (sender, e) => {
                Channel channel = e.Channel;
                mSyncContext.Post(delegate {
                    mTxtChannelUrl.Text = "#" + mChannelUrl;
                    mSendBirdChatAdapter.NotifyDataSetChanged();
                }, null);
            };
            seh.OnError           += (sender, e) => {
            };
            seh.OnChannelLeft     += (sender, e) => {
            };
            seh.OnMessageReceived += (sender, e) => {
                mSendBirdChatAdapter.AddMessageModel(e.Message);
                mSyncContext.Post(delegate {
                    mSendBirdChatAdapter.NotifyDataSetChanged();
                }, null);
            };
            seh.OnBroadcastMessageReceived += (sender, e) => {
                mSendBirdChatAdapter.AddMessageModel(e.Message);
                mSyncContext.Post(delegate {
                    mSendBirdChatAdapter.NotifyDataSetChanged();
                }, null);
            };
            seh.OnSystemMessageReceived += (sender, e) => {
                mSendBirdChatAdapter.AddMessageModel(e.Message);
                mSyncContext.Post(delegate {
                    mSendBirdChatAdapter.NotifyDataSetChanged();
                }, null);
            };
            seh.OnFileReceived += (sender, e) => {
                mSendBirdChatAdapter.AddMessageModel(e.FileLink);
                mSyncContext.Post(delegate {
                    mSendBirdChatAdapter.NotifyDataSetChanged();
                }, null);
            };
            seh.OnAllDataReceived += (sender, e) => {
                mSyncContext.Post(delegate {
                    mSendBirdChatAdapter.NotifyDataSetChanged();
                    mSendBirdChatFragment.mListView.SetSelection(mSendBirdChatAdapter.Count);
                }, null);
            };
            seh.OnMessageDelivery += (sender, e) => {
                if (!e.Sent)
                {
                    mSyncContext.Post(delegate {
                        mSendBirdChatFragment.mEtxtMessage.Text = e.Message;
                    }, null);
                }
            };
            seh.OnMessagingEnded      += (sender, e) => {
            };
            seh.OnSystemEventReceived += (sender, e) => {
            };


            #endregion

            SendBirdSDK.Init(appId);
            SendBirdSDK.Login(uuid, userName);
            SendBirdSDK.SetEventHandler(seh);
        }
Example #6
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);
    }