/// <summary> /// Retrieves the messages since last time they were fetched and adds them to /// the list. Unlike FetchMessages, this method is non-destructive /// </summary> /// <param name="channel"> the channel to fetch the messages from</param> public void FetchMessagesSinceLastTime(Entities.Channel channel) { Entities.Message[] fetchedMessages = Form1.Instance.session.REST.GetMessages(channel).ToArray(); foreach (Entities.Message msg in fetchedMessages.OrderBy(m => m.SentDate)) { OnNewMessage(msg); } }
public Channel ToDomain(Entities.Channel channel) { return(new Channel { Id = channel.Id, Name = channel.Name, IsDigital = channel.IsDigital }); }
/// <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(); }
public static Models.Channel ToModel(this Entities.Channel entity) { return(mapper.Map <Models.Channel>(entity)); }
/// <summary> /// Constructor for the MessageListPanel class. also loads messages /// from the given channel. /// </summary> /// <param name="channel">The channel to fetch the messages from</param> public MessageListPanel(Entities.Channel channel) : base() { this.channel = channel; this.messages = new List <MessageRow>(); FetchMessages(channel); }
public MessageRow(Entities.Message message, Entities.Channel channel, Panel parent) { this.message = message; this.parent = parent; this.ismine = (Form1.Instance.user != null && message.UserId == Form1.Instance.user?.UserId); Color message_bg_color = Constants.BLUE; Color message_text_color = Constants.DARK_GRAY; if (this.ismine) { message_bg_color = Constants.LIGHT_PURPLE; message_text_color = Constants.LIGHT_GRAY; } this.image = new PictureBox(); this.textPane = new Panel(); this.text = new Label(); this.timestampLabel = new Label(); this.Width = this.parent.Width; this.image.Size = Constants.MEDIUM_IMAGE_SIZE; this.image.Left = Constants.MARGIN_SMALL.Left; this.image.Top = Constants.MARGIN_SMALL.Top; this.image.BackColor = Color.Crimson; this.image.SizeMode = PictureBoxSizeMode.Zoom; Entities.User usr = channel.Memberships.Where(m => m.UserDetails.UserId == message.UserId).First().UserDetails; if (!string.IsNullOrEmpty(usr.ProfilePicture)) { this.image.LoadAsync(usr.ProfilePicture); } else { this.image.Image = Properties.Resources.default_user_image; } this.textPane.Left = this.image.Left + this.image.Width + Constants.MARGIN_SMALL.Right; this.textPane.Top = Constants.MARGIN_SMALL.Top; this.textPane.MaximumSize = new Size((int)(0.8f * this.Width), int.MaxValue); this.textPane.BackColor = message_bg_color; this.textPane.BackgroundImage = Constants.TRANSPARENT_GRADIENT_VERTICAL; this.textPane.BackgroundImageLayout = ImageLayout.Stretch; this.textPane.AutoSize = true; this.text.Left = Constants.MARGIN_SMALL.Left; this.text.Top = Constants.MARGIN_SMALL.Top; this.text.MaximumSize = new Size(Constants.MAX_MESSAGE_PANE_WIDTH - Constants.MARGIN_SMALL.Left - Constants.MARGIN_SMALL.Right, int.MaxValue); this.text.Text = this.message.Contents; this.text.AutoSize = true; this.text.ForeColor = message_text_color; this.textPane.Height = Constants.MARGIN_SMALL.Top + this.text.Height + Constants.MARGIN_SMALL.Bottom; this.textPane.Width = Constants.MARGIN_SMALL.Left + this.text.Width + Constants.MARGIN_SMALL.Right; this.textPane.Controls.Add(this.text); this.textPane.AutoSize = true; if (this.textPane.Height < this.image.Height) { this.Height = this.image.Height + Constants.MARGIN_SMALL.Top + Constants.MARGIN_SMALL.Bottom; this.textPane.Top = this.image.Top + this.image.Height - this.textPane.Height; } else { this.Height = this.textPane.Height + Constants.MARGIN_SMALL.Top + Constants.MARGIN_SMALL.Bottom; this.image.Top = this.textPane.Top + this.textPane.Height - this.image.Height; } this.timestampLabel.Text = this.message.SentDate.ToString() + " " + this.message.UserId; this.timestampLabel.Left = this.Width - this.timestampLabel.Width - Constants.MARGIN_SMALL.Right; this.timestampLabel.Top = this.Height - this.timestampLabel.Height; this.timestampLabel.ForeColor = Constants.DARK_GRAY; if (this.ismine) { this.image.Left = this.timestampLabel.Left - Constants.MARGIN_SMALL.Left - this.image.Width - Constants.MARGIN_SMALL.Right; this.textPane.Left = this.image.Left - (Constants.MARGIN_SMALL.Left + this.textPane.Controls[0].Width + this.textPane.Controls[0].Left + Constants.MARGIN_SMALL.Right); } this.Controls.Add(this.image); this.Controls.Add(this.textPane); this.Controls.Add(this.timestampLabel); }