diff --git a/JabbR.Test/CommandManagerFacts.cs b/JabbR.Test/CommandManagerFacts.cs index e34fd9c3b..ced081ca0 100644 --- a/JabbR.Test/CommandManagerFacts.cs +++ b/JabbR.Test/CommandManagerFacts.cs @@ -1307,6 +1307,64 @@ public void CanSetNoteWithNoTextClearsTheNoteProperty() } } + public class AfkCommand + { + [Fact] + public void CanSetAfkWithTextSetsTheNoteProperty() + { + // Arrange. + const string note = "I'll be back later!"; + var repository = new InMemoryRepository(); + var user = new ChatUser + { + Name = "asshat", + Id = "1" + }; + repository.Add(user); + var service = new ChatService(repository, new Mock().Object); + var notificationService = new Mock(); + var commandManager = new CommandManager("clientid", + "1", + null, + service, + repository, + notificationService.Object); + // Act. + bool result = commandManager.TryHandleCommand("/afk " + note); + + Assert.True(result); + Assert.Equal("Afk " + note, user.Note); + notificationService.Verify(x => x.ChangeNote(user, user.Note), Times.Once()); + } + + [Fact] + public void CanSetAfkWithNoTextSetTheNoteProperty() + { + // Arrange. + var repository = new InMemoryRepository(); + var user = new ChatUser + { + Name = "asshat", + Id = "1" + }; + repository.Add(user); + var service = new ChatService(repository, new Mock().Object); + var notificationService = new Mock(); + var commandManager = new CommandManager("clientid", + "1", + null, + service, + repository, + notificationService.Object); + // Act. + bool result = commandManager.TryHandleCommand("/afk "); + + Assert.True(result); + Assert.Equal("Afk", user.Note); + notificationService.Verify(x => x.ChangeNote(user, user.Note), Times.Once()); + } + } + public class HelpCommand { [Fact] diff --git a/JabbR/Chat.ui.js b/JabbR/Chat.ui.js index e41319619..c476cb45a 100644 --- a/JabbR/Chat.ui.js +++ b/JabbR/Chat.ui.js @@ -1042,13 +1042,11 @@ }, changeNote: function (user, roomName, note) { var room = getRoomElements(roomName), - $user = room.getUserReferences(user.Name), - src = 'http://jabbr.net/Content/images/toast-on.png'; + $user = room.getUserReferences(user.Name), + src = 'http://jabbr.net/Content/images/toast-on.png'; - var element = $user.find('.note'); - if (note == null && element != null) { - element.empty(); - } else { + var element = $user.find('.note').empty(); + if (note != null) { element.append('' + note + ''); } } diff --git a/JabbR/Commands/CommandManager.cs b/JabbR/Commands/CommandManager.cs index aafca517b..287876d4e 100644 --- a/JabbR/Commands/CommandManager.cs +++ b/JabbR/Commands/CommandManager.cs @@ -240,7 +240,12 @@ private bool TryHandleUserCommand(string commandName, string[] parts) return true; } + else if (commandName.Equals("afk", StringComparison.OrdinalIgnoreCase)) + { + HandleAfk(user, parts); + return true; + } return false; } @@ -794,5 +799,25 @@ private void HandleNote(ChatUser user, ICollection parts) _repository.CommitChanges(); } + + private void HandleAfk(ChatUser user, IEnumerable parts) + { + if (user == null) + { + throw new ArgumentNullException("user"); + } + + if (parts == null) + { + throw new ArgumentNullException("parts"); + } + + // First part is the command. + // Second is the AFK initial text. + var newParts = new List {"afk", "Afk"}; + newParts.AddRange(parts.Skip(1)); + + HandleNote(user, newParts); + } } } \ No newline at end of file