예제 #1
0
        private void ProcessMessage(ChatMessage message)
        {
            if (message.Type == ChatMessageType.Control)
            {
                switch (message.Control.Type)
                {
                case ControlMessageType.Joined:

                    if (message.UserCredential.UserName == this.credential.UserName &&
                        !channelsMap.ContainsKey(message.Topic))
                    {
                        var item = new ChannelItem(message.Topic);

                        item.ButtonToggled += ChannelItem_ButtonToggled;

                        channelsMap.Add(message.Topic, item);
                        channelsList.Add(item);

                        channelsBox.PackEnd(item.Button);
                        channelsNotebook.AppendPage(item.Page, null);

                        this.GoToChannel(message.Topic);
                    }

                    break;

                case ControlMessageType.Quitted:

                    if (message.UserCredential.UserName == this.credential.UserName &&
                        channelsMap.ContainsKey(message.Topic))
                    {
                        var item = channelsMap[message.Topic];

                        channelsMap.Remove(item.Topic);
                        channelsList.Remove(item);

                        channelsBox.Remove(item.Button);
                        channelsNotebook.RemovePage(channelsNotebook.CurrentPage);

                        if (item == this.currentChannel)
                        {
                            this.currentChannel = null;

                            this.GoToChannel(this.currentChannelIndex - 1);
                        }
                        else
                        {
                            this.currentChannelIndex = channelsList.IndexOf(this.currentChannel);
                        }

                        return;
                    }

                    break;
                }
            }

            if (message.Topic == "")
            {
                this.currentChannel.AppendMessage(message);
            }
            else if (this.channelsMap.ContainsKey(message.Topic))
            {
                var channel = this.channelsMap[message.Topic];

                channel.AppendMessage(message);

                if (channel != this.currentChannel)
                {
                    channel.SetUnread(true);
                }
            }
        }