Example #1
0
        public object AddMessage(Message message, User user, object textObject)
        {
            var entry = new MessageEntry(message, user);

            var afterEntry = textObject as MessageEntry;
            if (afterEntry != null)
            {
                var index = _messages.IndexOf(afterEntry);
                _messages.Insert(index, entry);
            }
            else
            {
                _messages.Add(entry);
            }
            return entry;
        }
Example #2
0
        public object AddMessage(Message message, User user, object textObject)
        {
            Action<Message, User, Paragraph> handler;
            if (!_handlers.TryGetValue(message.Type, out handler))
            {
                return null;
            }
            var paragraph = new Paragraph {Margin = new Thickness(0)};
            handler(message, user, paragraph);

            var after = textObject as Paragraph;
            if (after != null)
            {
                Blocks.InsertAfter(after, paragraph);
            }
            else
            {
                Blocks.Add(paragraph);
            }

            return paragraph;
        }
Example #3
0
        private void FormatUserMessage(Message message, User user, Paragraph paragraph)
        {
            if (message.Body.StartsWith("/me", StringComparison.InvariantCultureIgnoreCase))
            {
                paragraph.Inlines.Add(RenderUserMessage(user.Name + message.Body.Substring("/me".Length)));

                paragraph.FontStyle = FontStyles.Italic;
            }
            else
            {
                RenderUserString(user, paragraph);
                var inline = RenderUserMessage(message.Body);
                paragraph.Inlines.Add(inline);
            }

            paragraph.BorderThickness = new Thickness(0, 0, 0, 0.2);
            paragraph.BorderBrush = Brushes.LightGray;
        }
Example #4
0
        private void FormatUploadMessage(Message msg, User user, Paragraph paragraph)
        {
            var vm = _factory.Create(msg);
            var view = _factory.Create(vm);

            RenderUserString(user, paragraph);
            paragraph.Inlines.Add(new LineBreak());

            paragraph.Inlines.Add(view.Element);
        }
Example #5
0
        private void FormatTweetMessage(Message msg, User user, Paragraph paragraph)
        {
            if (msg.Tweet != null)
            {
                var bodyInline = RenderUserMessage(msg.Tweet.Message);

                var tweetView = new InlineTweetView(bodyInline, msg.Tweet);

                paragraph.Inlines.Add(FormatUserName(user) + ":" + Environment.NewLine);
                paragraph.Inlines.Add(tweetView);
                return;
            }

            // fallback
            FormatUserMessage(msg, user, paragraph);
        }
Example #6
0
 private void FormatTopicChangeMessage(Message message, User user, Paragraph paragraph)
 {
     var name = FormatUserName(user);
     paragraph.Inlines.Add(CreateMetaRun(String.Format("{0} changed the topic to '{1}'", name, message.Body)));
 }
Example #7
0
 public void UpdateMessage(object textObject, Message message, User user)
 {
     throw new System.NotImplementedException();
 }
Example #8
0
 private void AddMessage(Message message)
 {
     _messages.Add(message);
     var streamer = _streamers.FirstOrDefault(s => s.Id == message.RoomId);
     if (streamer != null)
     {
         streamer.Action(message);
     }
 }
Example #9
0
 private void FormatLeaveMessage(Message message, User user, Paragraph paragraph)
 {
     var name = FormatUserName(user);
     paragraph.Inlines.Add(CreateMetaRun(String.Format("{0} left the room", name)));
 }
Example #10
0
 private void FormatKickMessage(Message message, User user, Paragraph paragraph)
 {
     var name = FormatUserName(user);
     paragraph.Inlines.Add(CreateMetaRun(String.Format("{0} was kicked from the room", name)));
 }
Example #11
0
 private void FormatAdvertisementMessage(Message message, User user, Paragraph paragraph)
 {
     user = new User {Name = "Advertisement"};
     FormatUserMessage(message, user, paragraph);
 }
Example #12
0
        public void UpdateMessage(object textObject, Message message, User user)
        {
            var paragraph = textObject as Paragraph;
            if (paragraph == null)
            {
                throw new InvalidOperationException("Invalid object passed in");
            }

            Action<Message, User, Paragraph> handler;
            if (!_handlers.TryGetValue(message.Type, out handler))
            {
                return;
            }
            paragraph.Inlines.Clear();
            handler(message, user, paragraph);
        }
Example #13
0
 public NotificationMessage(IRoom room, User user, Message message)
 {
     Room = room;
     User = user;
     Message = message;
 }
Example #14
0
 public MessageEntry(Message message, User user)
 {
     Message = message;
     User = user;
 }
Example #15
0
        public void NewRoomMessage(string messageText, string roomName, int userId = 0)
        {
            int id = IdForRoom(roomName);
            var message = new Message
                {
                    Body = messageText,
                    CreatedAt = DateTime.Now,
                    Id = _currentMessageId++,
                    MessageTypeString = MessageType.TextMessage.ToString(),
                    RoomId = id,
                    UserIdString = userId.ToString()
                };

            AddMessage(message);
        }
Example #16
0
 public void SendRoomMessages(string roomName, Message[] messages)
 {
     var id = IdForRoom(roomName);
     foreach (var message in messages)
     {
         message.RoomId = id;
         AddMessage(message);
     }
 }
Example #17
0
        private void FormatPasteMessage(Message message, User user, Paragraph paragraph)
        {
            var name = FormatUserName(user);
            paragraph.Inlines.Add(name + ": " + Environment.NewLine);

            var run = RenderUserMessage(message.Body);
            run.FontFamily = new FontFamily("Consolas");
            paragraph.Inlines.Add(run);

            paragraph.BorderThickness = new Thickness(0, 0.5, 0, 0.5);
            paragraph.BorderBrush = Brushes.Black;
            paragraph.Margin = new Thickness(0, 1, 0, 6);
            paragraph.Padding = new Thickness(0, 1, 0, 6);
            paragraph.Background = Brushes.LightGoldenrodYellow;
        }
Example #18
0
 public MessagesReceivedMessage(int roomId, Message[] messages, int? sinceMessageId)
 {
     RoomId = roomId;
     Messages = messages;
     SinceMessageId = sinceMessageId;
 }
Example #19
0
 private void FormatTimestampMessage(Message message, User user, Paragraph paragraph)
 {
     var run = CreateMetaRun(message.CreatedAt.ToLocalTime().ToString());
     paragraph.Inlines.Add(run);
 }