Esempio n. 1
0
        /// <summary>
        /// Adds and displays the given message.
        /// When a new message is detected, this method should be called.
        /// </summary>
        /// <param name="message">the new message to add</param>
        public void OnNewMessage(Entities.Message message)
        {
            if (InvokeRequired)
            {
                Invoke(new Action(() => { OnNewMessage(message); }));
                return;
            }
            MessageRow mr = new MessageRow(message, this.channel, this);

            if (this.messages.Any())
            {
                mr.Top = this.messages.Last().Top + this.messages.Last().Height;
            }
            else
            {
                mr.Top = 0;
            }
            this.messages.Add(mr);
            this.Controls.Add(mr);
        }
Esempio n. 2
0
        /// <summary>
        /// Removes all contained messages, fetches those of the specified channel and
        /// displays them.
        /// </summary>
        /// <param name="channel">The channel to fetch the messages from</param>
        public void FetchMessages(Entities.Channel channel)
        {
            Form1.Instance.ShowPreloader();
            this.messages.Clear();
            this.Controls.Clear();
            this.channel = channel;
            Entities.Message[] fetchedMessages = Form1.Instance.session.REST.GetMessages(channel).ToArray();
            int hoffset = 0;

            foreach (Entities.Message msg in fetchedMessages.OrderBy(m => m.SentDate))
            {
                MessageRow mr = new MessageRow(msg, this.channel, this);
                mr.Top = hoffset;
                this.messages.Add(mr);
                this.Controls.Add(mr);
                hoffset += mr.Height;
            }
            System.Threading.Thread t = new System.Threading.Thread(() => {
                System.Threading.Thread.Sleep(1000);
                Form1.Instance.HidePreloader();
            });
            t.Start();
        }