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();
}
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);
}
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);
}
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));
}
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())));
}
Aggregations