예제 #1
0
        public BitChatPanel(BitChat chat, ChatListItem chatItem)
        {
            InitializeComponent();

            _chat = chat;

            _chat.FileAdded       += _chat_FileAdded;
            _chat.PeerAdded       += _chat_PeerAdded;
            _chat.MessageReceived += _chat_MessageReceived;

            //create view
            _view                   = new ChatMessageView(_chat, chatItem);
            _view.Dock              = DockStyle.Fill;
            _view.AllowDrop         = true;
            _view.SettingsModified += _view_SettingsModified;
            _view.DragEnter        += lstFiles_DragEnter;
            _view.DragDrop         += lstFiles_DragDrop;

            //load all peers
            foreach (BitChat.Peer peer in _chat.GetPeerList())
            {
                lstUsers.AddItem(new UserListItem(peer));
                peer.StateChanged += _view.peer_StateChanged;
                peer.StateChanged += peer_StateChanged;
            }

            //load all files
            foreach (SharedFile sharedFile in _chat.GetSharedFileList())
            {
                _chat_FileAdded(chat, sharedFile);
            }

            //add view to panel
            bitChatPanelSplitContainer.Panel1.Controls.Add(_view);
        }
예제 #2
0
        public ChatListItem(BitChat chat)
        {
            InitializeComponent();

            _chat = chat;

            SetTitle(_chat.NetworkDisplayName);
            labLastMessage.Text = "";
            SetLastMessageDate();
            ResetUnreadMessageCount();

            _chat.FileAdded       += chat_FileAdded;
            _chat.MessageReceived += chat_MessageReceived;
            _chat.PeerAdded       += chat_PeerAdded;
            _chat.PeerTyping      += chat_PeerTyping;

            if (_chat.NetworkType == BitChatCore.Network.BitChatNetworkType.PrivateChat)
            {
                foreach (BitChat.Peer peer in _chat.GetPeerList())
                {
                    if (!peer.IsSelf)
                    {
                        _peer = peer;
                        peer.ProfileImageChanged += peer_ProfileImageChanged;
                        peer.StateChanged        += peer_StateChanged;
                    }
                }
            }
            else
            {
                SetImageIcon(_chat.GroupImage);

                _chat.GroupImageChanged += chat_GroupImageChanged;
            }

            this.GoOffline = (_chat.NetworkStatus == BitChatCore.Network.BitChatNetworkStatus.Offline);

            _chatPanel      = new BitChatPanel(_chat, this);
            _chatPanel.Dock = DockStyle.Fill;
        }
        private List <CustomListViewItem> ConvertToListViewItems(MessageItem[] items, bool updateLastMessageInChatItem)
        {
            BitChat.Peer[] peerList = _chat.GetPeerList();
            SharedFile[]   fileList = _chat.GetSharedFileList();

            List <CustomListViewItem> listItems = new List <CustomListViewItem>(items.Length);
            DateTime lastItemDate    = new DateTime();
            string   lastMessage     = null;
            DateTime lastMessageDate = new DateTime();

            foreach (MessageItem item in items)
            {
                if (lastItemDate.Date < item.MessageDate.Date)
                {
                    lastItemDate = item.MessageDate;
                    listItems.Add(new ChatMessageInfoItem(new MessageItem(lastItemDate)));
                }

                switch (item.Type)
                {
                case MessageType.Info:
                    listItems.Add(new ChatMessageInfoItem(item));
                    break;

                case MessageType.TextMessage:
                case MessageType.InvitationMessage:
                {
                    BitChat.Peer sender = null;

                    foreach (BitChat.Peer peer in peerList)
                    {
                        if (peer.PeerCertificate.IssuedTo.EmailAddress.Address.Equals(item.Sender))
                        {
                            sender = peer;
                            break;
                        }
                    }

                    listItems.Add(new ChatMessageTextItem(sender, item));

                    if (sender == null)
                    {
                        lastMessage = item.Sender + ": " + item.Message;
                    }
                    else if (sender.IsSelf)
                    {
                        lastMessage = item.Message;
                    }
                    else
                    {
                        lastMessage = sender.PeerCertificate.IssuedTo.Name + ": " + item.Message;
                    }

                    lastMessageDate = item.MessageDate;
                }
                break;

                case MessageType.SharedFileMetaData:
                {
                    BitChat.Peer sender = null;
                    SharedFile   file   = null;

                    foreach (BitChat.Peer peer in peerList)
                    {
                        if (peer.PeerCertificate.IssuedTo.EmailAddress.Address.Equals(item.Sender))
                        {
                            sender = peer;
                            break;
                        }
                    }

                    foreach (SharedFile sharedFile in fileList)
                    {
                        if (sharedFile.MetaData.FileID.Equals(item.SharedFileMetaData.FileID))
                        {
                            file = sharedFile;
                            break;
                        }
                    }

                    ChatMessageFileItem fileItem = new ChatMessageFileItem(sender, item, file);
                    listItems.Add(fileItem);

                    fileItem.ShareFile += FileItem_ShareFile;

                    if (sender == null)
                    {
                        lastMessage = item.Sender + " shared a file";
                    }
                    else if (sender.IsSelf)
                    {
                        lastMessage = "file was shared";
                    }
                    else
                    {
                        lastMessage = sender.PeerCertificate.IssuedTo.Name + " shared a file";
                    }

                    lastMessageDate = item.MessageDate;
                }
                break;
                }
            }

            if (updateLastMessageInChatItem && (lastMessage != null))
            {
                _chatItem.SetLastMessage(lastMessage, lastMessageDate, false);
            }

            return(listItems);
        }