use of com.github.jamesnetherton.zulip.client.api.message.Message in project zulip-java-client by jamesnetherton.
the class ZulipIntegrationTestBase method afterEach.
@AfterEach
public void afterEach() throws Exception {
if (zulip != null) {
// Clean up messages
List<Message> messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).execute();
if (messages != null) {
for (Message message : messages) {
try {
zulip.messages().deleteMessage(message.getId()).execute();
} catch (ZulipClientException e) {
// Ignore
}
}
}
List<Message> privateMessages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("is", "private")).execute();
if (privateMessages != null) {
for (Message message : privateMessages) {
try {
zulip.messages().deleteMessage(message.getId()).execute();
} catch (ZulipClientException e) {
// Ignore
}
}
}
// Clean up streams
List<Stream> streams = zulip.streams().getAll().withIncludeDefault(false).execute();
if (streams != null) {
for (Stream stream : streams) {
try {
zulip.streams().delete(stream.getStreamId()).execute();
} catch (ZulipClientException e) {
// Ignore
}
}
}
// Clean up user groups
List<UserGroup> groups = zulip.users().getUserGroups().execute();
if (groups != null) {
for (UserGroup group : groups) {
try {
zulip.users().deleteUserGroup(group.getId()).execute();
} catch (ZulipClientException e) {
// Ignore
}
}
}
// Clean up profile fields
List<ProfileField> fields = zulip.server().getCustomProfileFields().execute();
if (fields != null) {
for (ProfileField field : fields) {
try {
zulip.server().deleteCustomProfileField(field.getId()).execute();
} catch (ZulipClientException e) {
// Ignore
}
}
}
}
// Clean up drafts
List<Draft> drafts = zulip.drafts().getDrafts().execute();
if (drafts != null) {
for (Draft draft : drafts) {
try {
zulip.drafts().deleteDraft(draft.getId()).execute();
} catch (ZulipClientException e) {
// Ignore
}
}
}
}
use of com.github.jamesnetherton.zulip.client.api.message.Message in project zulip-java-client by jamesnetherton.
the class ZulipEventIT method messageEventsWithNarrow.
@Test
public void messageEventsWithNarrow() throws Exception {
CountDownLatch latch = new CountDownLatch(5);
List<String> messages = new ArrayList<>();
String streamA = UUID.randomUUID().toString().split("-")[0];
String streamB = UUID.randomUUID().toString().split("-")[0];
zulip.streams().subscribe(StreamSubscriptionRequest.of(streamA, streamA), StreamSubscriptionRequest.of(streamB, streamB)).execute();
for (int i = 0; i < 10; i++) {
List<Stream> streams = zulip.streams().getAll().execute();
List<Stream> matches = streams.stream().filter(stream -> stream.getName().equals(streamA) || stream.getName().equals(streamB)).collect(Collectors.toList());
if (matches.size() == 2) {
break;
}
Thread.sleep(500);
}
EventPoller eventPoller = zulip.events().captureMessageEvents(new MessageEventListener() {
@Override
public void onEvent(Message event) {
messages.add(event.getContent());
latch.countDown();
}
}, Narrow.of("stream", streamA));
try {
eventPoller.start();
MessageService messageService = zulip.messages();
for (int i = 0; i < 10; i++) {
String streamName = i % 2 == 0 ? streamA : streamB;
messageService.sendStreamMessage("Stream " + streamName + " Content " + i, streamName, "testtopic").execute();
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
int count = 0;
for (int i = 0; i < 5; i++) {
assertEquals("Stream " + streamA + " Content " + count, messages.get(i));
count += 2;
}
} catch (ZulipClientException e) {
e.printStackTrace();
throw e;
} finally {
eventPoller.stop();
}
}
use of com.github.jamesnetherton.zulip.client.api.message.Message in project zulip-java-client by jamesnetherton.
the class ZulipEventIT method messageEvents.
@Test
public void messageEvents() throws Exception {
CountDownLatch latch = new CountDownLatch(3);
List<String> messages = new ArrayList<>();
String streamName = UUID.randomUUID().toString().split("-")[0];
StreamSubscriptionRequest subscriptionRequest = StreamSubscriptionRequest.of(streamName, streamName);
StreamService streamService = zulip.streams();
streamService.subscribe(subscriptionRequest).execute();
for (int i = 0; i < 10; i++) {
List<Stream> streams = streamService.getAll().execute();
List<Stream> matches = streams.stream().filter(stream -> stream.getName().equals(streamName)).collect(Collectors.toList());
if (matches.size() == 1) {
break;
}
Thread.sleep(500);
}
EventPoller eventPoller = zulip.events().captureMessageEvents(new MessageEventListener() {
@Override
public void onEvent(Message event) {
messages.add(event.getContent());
latch.countDown();
}
});
try {
eventPoller.start();
MessageService messageService = zulip.messages();
for (int i = 0; i < 3; i++) {
messageService.sendStreamMessage("Test Content " + i, streamName, "testtopic").execute();
}
assertTrue(latch.await(5, TimeUnit.SECONDS));
for (int i = 0; i < 3; i++) {
assertEquals("Test Content " + i, messages.get(i));
}
} catch (ZulipClientException e) {
e.printStackTrace();
throw e;
} finally {
eventPoller.stop();
}
}
use of com.github.jamesnetherton.zulip.client.api.message.Message in project zulip-java-client by jamesnetherton.
the class ZulipMessageIT method markTopicAsRead.
@Test
public void markTopicAsRead() throws ZulipClientException {
zulip.streams().subscribe(StreamSubscriptionRequest.of("Mark Topic As Read Stream", "Mark Topic As Read Stream")).withAuthorizationErrorsFatal(false).withHistoryPublicToSubscribers(true).withInviteOnly(false).withMessageRetention(RetentionPolicy.FOREVER).withStreamPostPolicy(StreamPostPolicy.ANY).execute();
zulip.messages().sendStreamMessage("content", "Mark Topic As Read Stream", "Test Topic").execute();
long streamId = zulip.streams().getStreamId("Mark Topic As Read Stream").execute();
zulip.messages().markTopicAsRead(streamId, "Test Topic").execute();
List<Message> messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Mark Topic As Read Stream")).execute();
assertFalse(messages.isEmpty());
Message message = messages.get(0);
List<MessageFlag> flags = message.getFlags();
assertFalse(flags.isEmpty());
MessageFlag flag = flags.get(0);
assertEquals(MessageFlag.READ, flag);
}
use of com.github.jamesnetherton.zulip.client.api.message.Message in project zulip-java-client by jamesnetherton.
the class ZulipMessageIT method markAsRead.
@Test
public void markAsRead() throws ZulipClientException {
zulip.streams().subscribe(StreamSubscriptionRequest.of("Mark As Read Stream", "Mark As Read Stream")).withAuthorizationErrorsFatal(false).withHistoryPublicToSubscribers(true).withInviteOnly(false).withMessageRetention(RetentionPolicy.FOREVER).withStreamPostPolicy(StreamPostPolicy.ANY).execute();
zulip.messages().sendStreamMessage("content", "Mark As Read Stream", "Test Topic").execute();
Long streamId = zulip.streams().getStreamId("Mark As Read Stream").execute();
zulip.messages().markStreamAsRead(streamId).execute();
List<Message> messages = zulip.messages().getMessages(100, 0, Anchor.NEWEST).withNarrows(Narrow.of("stream", "Mark As Read Stream")).execute();
assertFalse(messages.isEmpty());
Message message = messages.get(0);
List<MessageFlag> flags = message.getFlags();
assertFalse(flags.isEmpty());
MessageFlag flag = flags.get(0);
assertEquals(MessageFlag.READ, flag);
}
Aggregations