Search in sources :

Example 1 with ChatMessageEvent

use of com.faforever.client.chat.event.ChatMessageEvent in project downlords-faf-client by FAForever.

the class PircBotXChatService method sendMessageInBackground.

@Override
public CompletableFuture<String> sendMessageInBackground(String target, String message) {
    eventBus.post(new ChatMessageEvent(new ChatMessage(target, Instant.now(), userService.getUsername(), message)));
    return taskService.submitTask(new CompletableTask<String>(HIGH) {

        @Override
        protected String call() throws Exception {
            updateTitle(i18n.get("chat.sendMessageTask.title"));
            pircBotX.sendIRC().message(target, message);
            return message;
        }
    }).getFuture();
}
Also used : ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent) CompletableTask(com.faforever.client.task.CompletableTask)

Example 2 with ChatMessageEvent

use of com.faforever.client.chat.event.ChatMessageEvent in project downlords-faf-client by FAForever.

the class ChatControllerTest method testOnPrivateMessage.

@Test
public void testOnPrivateMessage() throws Exception {
    when(privateChatTabController.getRoot()).thenReturn(new Tab());
    ChatMessage chatMessage = new ChatMessage(null, Instant.now(), TEST_USER_NAME, "message");
    instance.onChatMessage(new ChatMessageEvent(chatMessage));
    WaitForAsyncUtils.waitForFxEvents();
    verify(privateChatTabController).onChatMessage(chatMessage);
    verify(channelTabController, never()).onChatMessage(chatMessage);
}
Also used : Tab(javafx.scene.control.Tab) ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 3 with ChatMessageEvent

use of com.faforever.client.chat.event.ChatMessageEvent in project downlords-faf-client by FAForever.

the class ChatControllerTest method testOnMessageForChannel.

@Test
public void testOnMessageForChannel() throws Exception {
    when(channelTabController.getRoot()).thenReturn(new Tab());
    ChatMessage chatMessage = new ChatMessage(TEST_CHANNEL_NAME, Instant.now(), TEST_USER_NAME, "message");
    instance.onChatMessage(new ChatMessageEvent(chatMessage));
    WaitForAsyncUtils.waitForFxEvents();
    verify(channelTabController).onChatMessage(chatMessage);
    verify(privateChatTabController, never()).onChatMessage(chatMessage);
}
Also used : Tab(javafx.scene.control.Tab) ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 4 with ChatMessageEvent

use of com.faforever.client.chat.event.ChatMessageEvent in project downlords-faf-client by FAForever.

the class PircBotXChatServiceTest method testChatMessageEventTriggeredByPrivateMessage.

@Test
public void testChatMessageEventTriggeredByPrivateMessage() throws Exception {
    CompletableFuture<ChatMessage> chatMessageFuture = new CompletableFuture<>();
    doAnswer(invocation -> chatMessageFuture.complete(((ChatMessageEvent) invocation.getArgument(0)).getMessage())).when(eventBus).post(any());
    String message = "private message";
    User user = mock(User.class);
    when(user.getNick()).thenReturn(chatUser1.getUsername());
    connect();
    firePircBotXEvent(createPrivateMessageEvent(user, message));
    ChatMessage chatMessage = chatMessageFuture.get(TIMEOUT, TIMEOUT_UNIT);
    assertThat(chatMessage.getMessage(), is(message));
    assertThat(chatMessage.getSource(), is(chatUser1.getUsername()));
    assertThat(chatMessage.getUsername(), is(chatUser1.getUsername()));
    assertThat(chatMessage.getTime(), is(greaterThan(Instant.ofEpochMilli(System.currentTimeMillis() - 1000))));
    assertThat(chatMessage.isAction(), is(false));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) User(org.pircbotx.User) ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent) Test(org.junit.Test) AbstractPlainJavaFxTest(com.faforever.client.test.AbstractPlainJavaFxTest)

Example 5 with ChatMessageEvent

use of com.faforever.client.chat.event.ChatMessageEvent in project downlords-faf-client by FAForever.

the class PircBotXChatService method onPrivateMessage.

private void onPrivateMessage(PrivateMessageEvent event) {
    User user = event.getUser();
    if (user == null) {
        logger.warn("Private message without user: {}", event);
        return;
    }
    logger.debug("Received private message: {}", event);
    Player sourcePlayer = playerService.getPlayerForUsername(user.getNick());
    if (sourcePlayer != null && sourcePlayer.getSocialStatus() == SocialStatus.FOE && preferencesService.getPreferences().getChat().getHideFoeMessages()) {
        log.debug("Suppressing chat message from foe '{}'", user.getNick());
        return;
    }
    eventBus.post(new ChatMessageEvent(new ChatMessage(user.getNick(), Instant.ofEpochMilli(event.getTimestamp()), user.getNick(), event.getMessage())));
}
Also used : Player(com.faforever.client.player.Player) User(org.pircbotx.User) ChatMessageEvent(com.faforever.client.chat.event.ChatMessageEvent)

Aggregations

ChatMessageEvent (com.faforever.client.chat.event.ChatMessageEvent)7 User (org.pircbotx.User)4 AbstractPlainJavaFxTest (com.faforever.client.test.AbstractPlainJavaFxTest)3 Test (org.junit.Test)3 Tab (javafx.scene.control.Tab)2 Player (com.faforever.client.player.Player)1 CompletableTask (com.faforever.client.task.CompletableTask)1 CompletableFuture (java.util.concurrent.CompletableFuture)1