nylas/nylas-java

Java SDK: Thread: thread.getMessages() return an empty list

Closed this issue · 3 comments

Describe the bug
The java SDK has a bug with thread.getMessages() method. Even if a thread has multiple messages, this method returns an empty array

To Reproduce

List<Message> messages = thread.getMessages();

Expected behavior
This method should return the message list

SDK Version:
1.9.0

Additional context
The doc samples or cases can not be achieved

Thanks for reporting this, we'll investigate and provide a fix soon!

@warunaperera I'm unable to replicate this issue. Are you getting the expanded view for threads? The API does not populated the messages key without explicitly fetching the threads in the expanded view. e.g.

List<Thread> allThreads = account.threads().expanded(query).chunkSize(10).fetchAll();

The following snippet works for me:

Instant end = ZonedDateTime.now().toInstant();
Instant start = end.minus(1, ChronoUnit.DAYS);
ThreadQuery query = new ThreadQuery()
		.limit(55)
		.lastMessageAfter(start)
		.lastMessageBefore(end)
		;
List<Thread> allThreads = account.threads().expanded(query).chunkSize(10).fetchAll();
System.out.println("result thread count: " + allThreads.size());
for (Thread thread : allThreads) {
	System.out.println(thread);
	List<Message> messages = thread.getMessages();
	for (Message email : messages) {
		System.out.println(email);
	}
}

If you're using the expanded view and it's still not working, please post your code snippet and any other relevant details that can help in reproducing this issue. Thank you!

@warunaperera closing the ticket for now. Please try the above code snippet and if it doesn't work, please re-open this ticket with more detail and/or a code sample. Thank you!