Search in sources :

Example 1 with MessageHistory

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

the class ZulipMessageIT method messageCrudOperations.

@Test
public void messageCrudOperations() throws ZulipClientException {
    zulip.streams().subscribe(StreamSubscriptionRequest.of("Test Message Stream 1", "Test Message Stream 1"), StreamSubscriptionRequest.of("Test Message Stream 2", "Test Message Stream 2"), StreamSubscriptionRequest.of("Test Message Stream 3", "Test Message Stream 3")).withAuthorizationErrorsFatal(false).withHistoryPublicToSubscribers(true).withInviteOnly(false).withAnnounce(true).withMessageRetention(RetentionPolicy.FOREVER).withStreamPostPolicy(StreamPostPolicy.ANY).execute();
    Long streamId = zulip.streams().getStreamId("Test Message Stream 2").execute();
    // Create messages using each variant of sendStreamMessage
    zulip.messages().sendStreamMessage("Test Content", "Test Message Stream 1", "Test Topic 1").execute();
    zulip.messages().sendStreamMessage("Test Content", streamId, "Test Topic 2").execute();
    List<Message> messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Test Message Stream 1")).execute();
    assertEquals(2, messages.size());
    Message message = messages.get(0);
    assertEquals("Internal", message.getClient());
    assertEquals("stream events", message.getSubject());
    assertEquals("Test Message Stream 1", message.getStream());
    assertEquals(MessageType.STREAM, message.getType());
    message = messages.get(1);
    assertTrue(message.getAvatarUrl().startsWith("https://secure.gravatar.com"));
    assertEquals("<p>Test Content</p>", message.getContent());
    assertEquals("text/html", message.getContentType());
    assertEquals("Apache-HttpClient", message.getClient());
    assertEquals("Test Message Stream 1", message.getStream());
    assertEquals(MessageType.STREAM, message.getType());
    assertTrue(message.getId() > 0);
    assertEquals("test@test.com", message.getSenderEmail());
    assertEquals("tester", message.getSenderFullName());
    assertEquals("Test Topic 1", message.getSubject());
    assertNotNull(message.getTimestamp());
    assertFalse(message.isMeMessage());
    messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Test Message Stream 2")).execute();
    assertEquals(2, messages.size());
    message = messages.get(0);
    assertEquals("Internal", message.getClient());
    assertEquals("stream events", message.getSubject());
    assertEquals("Test Message Stream 2", message.getStream());
    assertEquals(MessageType.STREAM, message.getType());
    message = messages.get(1);
    assertTrue(message.getAvatarUrl().startsWith("https://secure.gravatar.com"));
    assertEquals("<p>Test Content</p>", message.getContent());
    assertEquals("text/html", message.getContentType());
    assertEquals("Apache-HttpClient", message.getClient());
    assertEquals("Test Message Stream 2", message.getStream());
    assertEquals(MessageType.STREAM, message.getType());
    assertTrue(message.getId() > 0);
    assertEquals("test@test.com", message.getSenderEmail());
    assertEquals("tester", message.getSenderFullName());
    assertEquals("Test Topic 2", message.getSubject());
    assertNotNull(message.getTimestamp());
    assertFalse(message.isMeMessage());
    // Update message
    Long stream3Id = zulip.streams().getStreamId("Test Message Stream 3").execute();
    zulip.messages().editMessage(message.getId()).withStreamId(stream3Id).withPropagateMode(PropagateMode.CHANGE_ONE).withSendNotificationToNewThread(true).withSendNotificationToOldThread(false).withTopic("Edited Topic").execute();
    zulip.messages().updateMessageFlags(MessageFlag.STARRED, Operation.ADD, message.getId()).execute();
    messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Test Message Stream 3")).execute();
    message = messages.get(1);
    assertEquals(1, message.getFlags().size());
    assertEquals(MessageFlag.STARRED, message.getFlags().get(0));
    assertEquals("Edited Topic", message.getSubject());
    List<MessageHistory> messageHistories = zulip.messages().getMessageHistory(message.getId()).execute();
    assertEquals(2, messageHistories.size());
    MessageHistory messageHistory = messageHistories.get(1);
    assertEquals("Edited Topic", messageHistory.getTopic());
    assertEquals("Test Topic 2", messageHistory.getPreviousTopic());
    // Delete message
    zulip.messages().deleteMessage(message.getId()).execute();
    messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Test Message Stream 2")).execute();
    assertEquals(1, messages.size());
}
Also used : MessageHistory(com.github.jamesnetherton.zulip.client.api.message.MessageHistory) 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 MessageHistory (com.github.jamesnetherton.zulip.client.api.message.MessageHistory)1 Test (org.junit.jupiter.api.Test)1