예제 #1
0
        public override void Execute(CommandContext context, CallerContext callerContext, ChatUser callingUser, string[] args)
        {
            if (context.Repository.Users.Count() == 1)
            {
                throw new InvalidOperationException("You're the only person in here...");
            }

            if (args.Length == 0 || String.IsNullOrWhiteSpace(args[0]))
            {
                throw new InvalidOperationException("Who are you trying send a private message to?");
            }
            var toUserName = HttpUtility.HtmlDecode(args[0]);
            ChatUser toUser = context.Repository.VerifyUser(toUserName);

            if (toUser == callingUser)
            {
                throw new InvalidOperationException("You can't private message yourself!");
            }

            string messageText = String.Join(" ", args.Skip(1)).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException(String.Format("What did you want to say to '{0}'?", toUser.Name));
            }

            HashSet<string> urls;
            var transform = new TextTransform(context.Repository);
            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            context.NotificationService.SendPrivateMessage(callingUser, toUser, messageText);
        }
예제 #2
0
        public static string TransformAndParseUrls(IJabbrRepository repository, string text)
        {
            HashSet<string> urls;
            var transform = new TextTransform(repository);
            var parsedText = transform.Parse(text);

            return TextTransform.TransformAndExtractUrls(parsedText, out urls);
        }
예제 #3
0
            public void StringWithHashtagButRoomDoesntExistDoesNotModifyMessage()
            {
                IJabbrRepository repository = CreateRoomRepository();

                TextTransform transform = new TextTransform(repository);
                string result = transform.Parse("#thisdoesnotexist");

                Assert.Equal("#thisdoesnotexist", result);
            }
예제 #4
0
        public override void ExecuteAdminOperation(CommandContext context, CallerContext callerContext, Models.ChatUser callingUser, string[] args)
        {
            string messageText = String.Join(" ", args).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException("What did you want to broadcast?");
            }

            HashSet<string> urls;
            var transform = new TextTransform(context.Repository);
            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            context.NotificationService.BroadcastMessage(callingUser, messageText);
        }
예제 #5
0
파일: Chat.cs 프로젝트: NTaylorMullen/JabbR
 private string ParseChatMessageText(string content, out HashSet<string> links)
 {
     var textTransform = new TextTransform(_repository);
     string message = textTransform.Parse(content);
     return TextTransform.TransformAndExtractUrls(message, out links);
 }
예제 #6
0
파일: Chat.cs 프로젝트: NTaylorMullen/JabbR
 private string ConvertUrlsAndRoomLinks(string message)
 {
     TextTransform textTransform = new TextTransform(_repository);
     message = textTransform.ConvertHashtagsToRoomLinks(message);
     HashSet<string> urls;
     return TextTransform.TransformAndExtractUrls(message, out urls);
 }
예제 #7
0
파일: Chat.cs 프로젝트: NTaylorMullen/JabbR
        void INotificationService.Invite(ChatUser user, ChatUser targetUser, ChatRoom targetRoom)
        {
            var transform = new TextTransform(_repository);
            string roomLink = transform.ConvertHashtagsToRoomLinks("#" + targetRoom.Name);

            // Send the invite message to the sendee
            foreach (var client in targetUser.ConnectedClients)
            {
                Clients[client.Id].sendInvite(user.Name, targetUser.Name, roomLink);
            }

            // Send the invite notification to the sender
            foreach (var client in user.ConnectedClients)
            {
                Clients[client.Id].sendInvite(user.Name, targetUser.Name, roomLink);
            }
        }
예제 #8
0
        private void HandleMsg(ChatUser user, string[] parts)
        {
            if (_repository.Users.Count() == 1)
            {
                throw new InvalidOperationException("You're the only person in here...");
            }

            if (parts.Length < 2 || String.IsNullOrWhiteSpace(parts[1]))
            {
                throw new InvalidOperationException("Who are you trying send a private message to?");
            }
            var toUserName = parts[1];
            ChatUser toUser = _repository.VerifyUser(toUserName);

            if (toUser == user)
            {
                throw new InvalidOperationException("You can't private message yourself!");
            }

            string messageText = String.Join(" ", parts.Skip(2)).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException(String.Format("What did you want to say to '{0}'.", toUser.Name));
            }

            HashSet<string> urls;
            var transform = new TextTransform(_repository);
            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            _notificationService.SendPrivateMessage(user, toUser, messageText);
        }
예제 #9
0
            public void StringWithHashtagModifiesHashtagToRoomLink()
            {
                IJabbrRepository repository = CreateRoomRepository();
                string expected = "<a href=\"#/rooms/hashtag\" title=\"#hashtag\">#hashtag</a>";

                TextTransform transform = new TextTransform(repository);
                string result = transform.Parse("#hashtag");

                Assert.Equal(expected, result);
            }
예제 #10
0
        private void HandleBroadcast(ChatUser user, string[] parts)
        {
            if (!user.IsAdmin)
            {
                throw new InvalidOperationException("You are not an admin.");
            }

            string messageText = String.Join(" ", parts.Skip(1)).Trim();

            if (String.IsNullOrEmpty(messageText))
            {
                throw new InvalidOperationException("What did you want to broadcast?");
            }

            HashSet<string> urls;
            var transform = new TextTransform(_repository);
            messageText = transform.Parse(messageText);

            messageText = TextTransform.TransformAndExtractUrls(messageText, out urls);

            _notificationService.BroadcastMessage(user, messageText);
        }