Ejemplo n.º 1
0
        public MeshNetworkPanel(MeshNetwork network, ChatListItem chatItem)
        {
            InitializeComponent();

            _network = network;

            _network.PeerAdded += network_PeerAdded;

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

            //load all peers
            foreach (MeshNetwork.Peer peer in _network.GetPeers())
            {
                lstUsers.AddItem(new UserListItem(peer));

                peer.StateChanged += peer_StateChanged;
            }

            //add view to panel
            meshPanelSplitContainer.Panel1.Controls.Add(_view);
        }
Ejemplo n.º 2
0
        private List <CustomListViewItem> ConvertToListViewItems(MessageItem[] items, bool updateLastMessageInChatItem)
        {
            MeshNetwork.Peer[] peerList = _network.GetPeers();

            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:
                {
                    MeshNetwork.Peer sender = null;

                    foreach (MeshNetwork.Peer peer in peerList)
                    {
                        if (peer.PeerUserId.Equals(item.SenderUserId))
                        {
                            sender = peer;
                            break;
                        }
                    }

                    if (sender == null)
                    {
                        continue;
                    }

                    ChatMessageTextItem textItem = new ChatMessageTextItem(sender, item);
                    textItem.ForwardTo += MessageItem_ForwardTo;

                    listItems.Add(textItem);

                    if (sender == null)
                    {
                        lastMessage = item.SenderUserId + ": " + item.MessageText;
                    }
                    else if (sender.IsSelfPeer)
                    {
                        lastMessage = item.MessageText;
                    }
                    else
                    {
                        lastMessage = sender.ProfileDisplayName + ": " + item.MessageText;
                    }

                    lastMessageDate = item.MessageDate;
                }
                break;

                case MessageType.InlineImage:
                case MessageType.FileAttachment:
                {
                    MeshNetwork.Peer sender = null;

                    foreach (MeshNetwork.Peer peer in peerList)
                    {
                        if (peer.PeerUserId.Equals(item.SenderUserId))
                        {
                            sender = peer;
                            break;
                        }
                    }

                    if (sender == null)
                    {
                        continue;
                    }

                    ChatMessageFileItem fileItem = new ChatMessageFileItem(sender, item);
                    fileItem.ForwardTo += MessageItem_ForwardTo;

                    listItems.Add(fileItem);

                    string messageText = item.MessageText;
                    if (string.IsNullOrEmpty(messageText))
                    {
                        messageText = "file attachment";
                    }

                    if (sender == null)
                    {
                        lastMessage = item.SenderUserId + ": " + messageText;
                    }
                    else if (sender.IsSelfPeer)
                    {
                        lastMessage = messageText;
                    }
                    else
                    {
                        lastMessage = sender.ProfileDisplayName + ": " + messageText;
                    }

                    lastMessageDate = item.MessageDate;
                }
                break;
                }
            }

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

            return(listItems);
        }