示例#1
0
文件: Chat.cs 项目: wangdeshui/JabbR
        private void AddMentions(ChatMessage message)
        {
            bool anyMentions = false;

            foreach (var userName in MentionExtractor.ExtractMentions(message.Content))
            {
                ChatUser mentionedUser = _repository.GetUserByName(userName);

                // Don't create a mention if
                // 1. If the mentioned user doesn't exist.
                // 2. If you mention yourself
                // 3. If you're mentioned in a private room that you don't have access to
                if (mentionedUser == null ||
                    mentionedUser == message.User ||
                    (message.Room.Private && !mentionedUser.AllowedRooms.Contains(message.Room)))
                {
                    continue;
                }

                anyMentions = true;

                // Mark the notification as read if the user is online
                bool markAsRead = mentionedUser.Status == (int)UserStatus.Active;

                _service.AddNotification(mentionedUser, message, markAsRead);
            }

            if (anyMentions)
            {
                _repository.CommitChanges();
            }
        }
示例#2
0
        public void FirstCharacter()
        {
            var users = MentionExtractor.ExtractMentions("@foo");

            Assert.Equal(1, users.Count);
            Assert.Equal("foo", users[0]);
        }
示例#3
0
        public void TrailingSpace()
        {
            var users = MentionExtractor.ExtractMentions("@foo ");

            Assert.Equal(1, users.Count);
            Assert.Equal("foo", users[0]);
        }
示例#4
0
        public void Multiple()
        {
            var users = MentionExtractor.ExtractMentions("@foo @bar");

            Assert.Equal(2, users.Count);
            Assert.Equal("foo", users[0]);
            Assert.Equal("bar", users[1]);
        }
示例#5
0
        private void AddMentions(ChatMessage message)
        {
            var mentionedUsers = new List <ChatUser>();

            foreach (var userName in MentionExtractor.ExtractMentions(message.Content))
            {
                ChatUser mentionedUser = _repository.GetUserByName(userName);

                // Don't create a mention if
                // 1. If the mentioned user doesn't exist.
                // 2. If you mention yourself
                // 3. If you're mentioned in a private room that you don't have access to
                // 4. You've already been mentioned in this message
                if (mentionedUser == null ||
                    mentionedUser == message.User ||
                    (message.Room.Private && !mentionedUser.AllowedRooms.Contains(message.Room)) ||
                    mentionedUsers.Contains(mentionedUser))
                {
                    continue;
                }

                // mark as read if ALL of the following
                // 1. user is not offline
                // 2. user is not AFK
                // 3. user has been active within the last 10 minutes
                // 4. user is currently in the room
                bool markAsRead = mentionedUser.Status != (int)UserStatus.Offline &&
                                  !mentionedUser.IsAfk &&
                                  (DateTimeOffset.UtcNow - mentionedUser.LastActivity) < TimeSpan.FromMinutes(10) &&
                                  _repository.IsUserInRoom(_cache, mentionedUser, message.Room);

                _service.AddNotification(mentionedUser, message, message.Room, markAsRead);

                mentionedUsers.Add(mentionedUser);
            }

            if (mentionedUsers.Count > 0)
            {
                _repository.CommitChanges();
            }

            foreach (var user in mentionedUsers)
            {
                UpdateUnreadMentions(user);
            }
        }
示例#6
0
        public void Nothing()
        {
            var users = MentionExtractor.ExtractMentions("@@@@@");

            Assert.Equal(0, users.Count);
        }