Exemplo n.º 1
0
        public void ParseTest()
        {
            ChatUser user = ChatUser.Parse("name#1");

            Assert.AreEqual(user.Id, 1);
            Assert.AreEqual(user.Name, "name");
        }
Exemplo n.º 2
0
        private void OnNewUser(ChatMessage message)
        {
            var user = ChatUser.Parse(message.Message.Text);
            var room = (user.Equals(mUser)) ? Room.CreateSelfRoom(user) :
                       Room.CreateRoomByUser(user, user, mUser);

            Application.Current.Dispatcher.Invoke(() => {
                mPublicRoom.Users.Add(user);
                RoomsManager.Rooms.Add(room);
            });

            if (user.Id != mUser.Id)
            {
                Task.Factory.StartNew(() => NotificationQueue.Enqueue($"A new user {user.Name} has joined", "OK", (username) => { }, user.Name));
            }
        }
Exemplo n.º 3
0
        private void OnServerUsers(ChatMessage message)
        {
            if (String.IsNullOrEmpty(message.Message.Text) || String.IsNullOrWhiteSpace(message.Message.Text))
            {
                return;
            }

            var users = message.Message.Text
                        .Split(' ')
                        .Select(user => ChatUser.Parse(user));
            var rooms = users.Select(u => Room.CreateRoomByUser(u, u, mUser));

            Application.Current.Dispatcher.Invoke(() => {
                mPublicRoom.Users.AddRange(users);
                RoomsManager.Rooms.AddRange(rooms);
            });
        }
Exemplo n.º 4
0
        public void EqualsTest()
        {
            ChatUser user  = ChatUser.Parse("name#1");
            ChatUser user2 = user;
            ChatUser user3 = ChatUser.Parse("name#1");

            Assert.IsTrue(user.Equals(user2));
            Assert.IsTrue(user.Equals(user3));

            Assert.IsTrue(user == user2);
            Assert.IsTrue(user != user3);

            ChatUser[] users = new ChatUser[] { user, user2, user3 };

            var t = users.Where(u => u.Equals(user));

            Assert.AreEqual(3, t.Count());
        }
Exemplo n.º 5
0
        public static ChatMessageText Create(string message)
        {
            ChatMessageText result  = new ChatMessageText();
            RegexOptions    options = RegexOptions.Multiline;

            List <ChatUser> mentionedUsersUsers = new List <ChatUser>();

            foreach (Match match in Regex.Matches(message, Constants.MentionedUsersRegex, options))
            {
                var user = ChatUser.Parse(match.Groups[Constants.UsernameRegexGroup].Value);

                message = Regex.Replace(message, match.Value, user.Name);
                mentionedUsersUsers.Add(user);
            }

            result.MentionedUsers = mentionedUsersUsers.ToArray();
            result.Text           = message;

            return(result);
        }