Exemplo n.º 1
0
        public void GenarateMessage(List <ReferenceData.Entity.Message> list, FlowLayoutPanel fl)
        {
            FlowLayoutPanel flow = new FlowLayoutPanel();

            flow.AutoScroll   = false;
            flow.WrapContents = false;
            flow.AutoSize     = true;
            if (fl.Equals(FPMessage1))
            {
                list.Reverse();
                flow.FlowDirection = FlowDirection.TopDown;
            }
            else
            {
                flow.FlowDirection = FlowDirection.BottomUp;
            }

            DateTime        time = (DateTime)list[0].createdAt;
            UserControl     currentMessage;
            UserControl     bubble;
            IncomingMessage cInMessage  = new IncomingMessage();
            OutgoingMessage cOutMessage = new OutgoingMessage();

            if (list[0].senderId != Form.User.id)
            {
                cInMessage = new IncomingMessage(list[0].avatar, list[0].senderId, list[0].lastName, time);
                if (list[0].messageType.Equals("FILE"))
                {
                    bubble = new FileBubble(list[0].content, list[0].file, FileBubble.msgType.In);
                }
                else
                {
                    bubble = new TextBubble(list[0].content, TextBubble.msgType.In);
                }
                cInMessage.AddBubble(bubble);
                currentMessage = cInMessage;
            }
            else
            {
                cOutMessage = new OutgoingMessage(list[0].senderId, time);
                if (list[0].messageType.Equals("FILE"))
                {
                    bubble = new FileBubble(list[0].content, list[0].file, FileBubble.msgType.Out);
                }
                else
                {
                    bubble = new TextBubble(list[0].content, TextBubble.msgType.Out);
                }
                cOutMessage.AddBubble(bubble);
                currentMessage = cOutMessage;
            }
            foreach (var mes in list)
            {
                if (!mes.Equals(list[0]))
                {
                    if (mes.senderId != Form.User.id)
                    {
                        if (currentMessage.GetType() != typeof(IncomingMessage))
                        {
                            flow.Controls.Add(currentMessage);
                            time       = (DateTime)mes.createdAt;
                            cInMessage = new IncomingMessage(mes.avatar, mes.senderId, mes.lastName, time);
                            if (mes.messageType.Equals("FILE"))
                            {
                                bubble = new FileBubble(mes.content, mes.file, FileBubble.msgType.In);
                            }
                            else
                            {
                                bubble = new TextBubble(mes.content, TextBubble.msgType.In);
                            }
                            cInMessage.AddBubble(bubble);
                            currentMessage = cInMessage;
                        }
                        else
                        {
                            if (compareTime(time, (DateTime)mes.createdAt) && cInMessage.UserId == mes.senderId)
                            {
                                if (mes.messageType.Equals("FILE"))
                                {
                                    bubble = new FileBubble(mes.content, mes.file, FileBubble.msgType.In);
                                }
                                else
                                {
                                    bubble = new TextBubble(mes.content, TextBubble.msgType.In);
                                }
                                cInMessage.AddBubble(bubble);
                            }
                            else
                            {
                                flow.Controls.Add(currentMessage);
                                time       = (DateTime)mes.createdAt;
                                cInMessage = new IncomingMessage(mes.avatar, mes.senderId, mes.lastName, time);
                                if (mes.messageType.Equals("FILE"))
                                {
                                    bubble = new FileBubble(mes.content, mes.file, FileBubble.msgType.In);
                                }
                                else
                                {
                                    bubble = new TextBubble(mes.content, TextBubble.msgType.In);
                                }
                                cInMessage.AddBubble(bubble);
                                currentMessage = cInMessage;
                            }
                        }
                    }
                    else
                    {
                        if (currentMessage.GetType() != typeof(OutgoingMessage))
                        {
                            flow.Controls.Add(currentMessage);
                            time        = (DateTime)mes.createdAt;
                            cOutMessage = new OutgoingMessage(mes.senderId, time);
                            if (mes.messageType.Equals("FILE"))
                            {
                                bubble = new FileBubble(mes.content, mes.file, FileBubble.msgType.Out);
                            }
                            else
                            {
                                bubble = new TextBubble(mes.content, TextBubble.msgType.Out);
                            }
                            cOutMessage.AddBubble(bubble);
                            currentMessage = cOutMessage;
                        }
                        else
                        {
                            if (compareTime(time, (DateTime)mes.createdAt) && cOutMessage.UserId == mes.senderId)
                            {
                                if (mes.messageType.Equals("FILE"))
                                {
                                    bubble = new FileBubble(mes.content, mes.file, FileBubble.msgType.Out);
                                }
                                else
                                {
                                    bubble = new TextBubble(mes.content, TextBubble.msgType.Out);
                                }
                                cOutMessage.AddBubble(bubble);
                            }
                            else
                            {
                                flow.Controls.Add(currentMessage);
                                time        = (DateTime)mes.createdAt;
                                cOutMessage = new OutgoingMessage(mes.senderId, time);
                                if (mes.messageType.Equals("FILE"))
                                {
                                    bubble = new FileBubble(mes.content, mes.file, FileBubble.msgType.Out);
                                }
                                else
                                {
                                    bubble = new TextBubble(mes.content, TextBubble.msgType.Out);
                                }
                                cOutMessage.AddBubble(bubble);
                                currentMessage = cOutMessage;
                            }
                        }
                    }
                }
            }
            flow.Controls.Add(currentMessage);
            fl.Controls.Add(flow);
            this.messageBox.UpdateUi();
        }