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); }
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); }
public void StringWithHashtagButRoomDoesntExistDoesNotModifyMessage() { IJabbrRepository repository = CreateRoomRepository(); TextTransform transform = new TextTransform(repository); string result = transform.Parse("#thisdoesnotexist"); Assert.Equal("#thisdoesnotexist", result); }
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); }
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); }
private string ConvertUrlsAndRoomLinks(string message) { TextTransform textTransform = new TextTransform(_repository); message = textTransform.ConvertHashtagsToRoomLinks(message); HashSet<string> urls; return TextTransform.TransformAndExtractUrls(message, out urls); }
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); } }
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); }
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); }
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); }