Search in sources :

Example 1 with MessageReaction

use of com.github.jamesnetherton.zulip.client.api.message.MessageReaction in project zulip-java-client by jamesnetherton.

the class ZulipMessageIT method reactions.

@Test
public void reactions() throws ZulipClientException {
    zulip.streams().subscribe(StreamSubscriptionRequest.of("Test Message Reaction", "Test Message Reaction")).withAuthorizationErrorsFatal(false).withHistoryPublicToSubscribers(true).withInviteOnly(false).withMessageRetention(RetentionPolicy.FOREVER).withStreamPostPolicy(StreamPostPolicy.ANY).execute();
    // Create message
    long messageId = zulip.messages().sendStreamMessage("Test Content", "Test Message Reaction", "Test Topic 1").execute();
    // Add reaction
    zulip.messages().addEmojiReaction(messageId, Emoji.PIGLET.getName()).execute();
    // Verify reaction added
    List<Message> messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Test Message Reaction")).execute();
    assertEquals(2, messages.size());
    Message message = messages.get(1);
    List<MessageReaction> reactions = message.getReactions();
    assertEquals(1, reactions.size());
    assertEquals("piglet", reactions.get(0).getEmojiName());
    // Delete reaction
    zulip.messages().deleteEmojiReaction(messageId, Emoji.PIGLET.getName()).execute();
    // Verify reaction removed
    messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Test Message Reaction")).execute();
    assertEquals(2, messages.size());
    message = messages.get(1);
    reactions = message.getReactions();
    assertTrue(reactions.isEmpty());
}
Also used : MessageReaction(com.github.jamesnetherton.zulip.client.api.message.MessageReaction) Message(com.github.jamesnetherton.zulip.client.api.message.Message) Test(org.junit.jupiter.api.Test)

Aggregations

Message (com.github.jamesnetherton.zulip.client.api.message.Message)1 MessageReaction (com.github.jamesnetherton.zulip.client.api.message.MessageReaction)1 Test (org.junit.jupiter.api.Test)1