Beispiel #1
0
        public void AddInMessage(ReferenceData.Entity.Message message)
        {
            currentOutMessage = null;
            UserControl bubble = null;

            if (message.messageType.ToUpper().Equals("TEXT"))
            {
                bubble = new TextBubble(message.content, TextBubble.msgType.In);
            }
            else
            {
                bubble = new FileBubble(message.content, message.file, FileBubble.msgType.In);
            }
            if (this.currentInMessage == null)
            {
                currentInMessage = new IncomingMessage(message.avatar, message.senderId, message.lastName, DateTime.Now);
            }
            else
            {
                if (currentInMessage.UserId != message.senderId)
                {
                    currentInMessage = new IncomingMessage(message.avatar, message.senderId, message.lastName, DateTime.Now);
                }
                else
                {
                    if (compareTime(currentInMessage.Time, DateTime.Now))
                    {
                        FPMessage1.Controls.Remove(currentInMessage);
                    }
                    else
                    {
                        currentInMessage = new IncomingMessage(message.avatar, message.senderId, message.lastName, DateTime.Now);
                    }
                }
            }
            currentInMessage.AddBubble(bubble);
            FPMessage1.Controls.Add(currentInMessage);
            this.messageBox.UpdateUi();
            if (this.messageBox.panelBg.Size.Height < this.messageBox.flowLayoutPanel.PreferredSize.Height)
            {
                this.messageBox.vScrollBar.Value = this.messageBox.vScrollBar.Maximum;
            }
            foreach (var c in Form.ConversationList)
            {
                if (c.Cvst.id.Equals(message.conversationId))
                {
                    Form.InitLatestMessage(c, message);
                    break;
                }
            }
        }
Beispiel #2
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();
        }