Skip to content

Commit 72dada5

Browse files
authored
CUST-3867 changed SendMessageRequest.sendAt to Long (#296)
Added a method overload that converts passed ints to Longs, so that the change is not breaking. There should be a warning thrown if Kotlin users pass int literals, but these can be ignored/corrected easily (and should not be happening anyway). Tested this thoroughly. # License <!-- Your PR comment must contain the following line for us to merge the PR. --> I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.
1 parent 7deff22 commit 72dada5

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Nylas Java SDK Changelog
22

3+
## [Unreleased]
4+
5+
### Changed
6+
* `SendMessageRequest.sendAt` field changed from `Int?` to `Long?` to support Unix timestamps beyond 2038. Maintains backward compatibility through method overloading - existing `Int` parameters are automatically converted to `Long`. **Note:** Kotlin users passing integer literals may need to specify type explicitly (e.g., `1620000000L` or `1620000000 as Int`).
7+
38
## [2.13.1]
49

510
### Fixed

src/main/kotlin/com/nylas/models/SendMessageRequest.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ data class SendMessageRequest(
5656
* Unix timestamp to send the message at.
5757
*/
5858
@Json(name = "send_at")
59-
val sendAt: Int? = null,
59+
val sendAt: Long? = null,
6060
/**
6161
* The ID of the message that you are replying to.
6262
*/
@@ -94,7 +94,7 @@ data class SendMessageRequest(
9494
internal var subject: String? = null
9595
private var body: String? = null
9696
private var starred: Boolean? = null
97-
private var sendAt: Int? = null
97+
private var sendAt: Long? = null
9898
private var replyToMessageId: String? = null
9999
private var trackingOptions: TrackingOptions? = null
100100
private var useDraft: Boolean? = null
@@ -162,7 +162,14 @@ data class SendMessageRequest(
162162
* @param sendAt The unix timestamp to send the message at.
163163
* @return The builder.
164164
*/
165-
fun sendAt(sendAt: Int?) = apply { this.sendAt = sendAt }
165+
fun sendAt(sendAt: Long?) = apply { this.sendAt = sendAt }
166+
167+
/**
168+
* Sets the unix timestamp to send the message at.
169+
* @param sendAt The unix timestamp to send the message at (automatically converted to Long).
170+
* @return The builder.
171+
*/
172+
fun sendAt(sendAt: Int?) = apply { this.sendAt = sendAt?.toLong() }
166173

167174
/**
168175
* Sets the ID of the message that you are replying to.

src/test/kotlin/com/nylas/resources/MessagesTests.kt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,75 @@ class MessagesTests {
616616
assertNull(queryParamCaptor.firstValue)
617617
}
618618

619+
@Test
620+
fun `sending a message with Int sendAt value calls requests with the correct params`() {
621+
val adapter = JsonHelper.moshi().adapter(SendMessageRequest::class.java)
622+
val sendMessageRequest =
623+
SendMessageRequest.Builder(to = listOf(EmailName(email = "[email protected]", name = "Test")))
624+
.body("Hello, I just sent a message using Nylas!")
625+
.subject("Hello from Nylas!")
626+
.sendAt(1620000000 as Int) // Explicitly test Int overload conversion to Long
627+
.build()
628+
629+
messages.send(grantId, sendMessageRequest)
630+
631+
val pathCaptor = argumentCaptor<String>()
632+
val typeCaptor = argumentCaptor<Type>()
633+
val requestBodyCaptor = argumentCaptor<String>()
634+
val queryParamCaptor = argumentCaptor<IQueryParams>()
635+
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
636+
verify(mockNylasClient).executePost<Response<Message>>(
637+
pathCaptor.capture(),
638+
typeCaptor.capture(),
639+
requestBodyCaptor.capture(),
640+
queryParamCaptor.capture(),
641+
overrideParamCaptor.capture(),
642+
)
643+
644+
assertEquals("v3/grants/$grantId/messages/send", pathCaptor.firstValue)
645+
assertEquals(Types.newParameterizedType(Response::class.java, Message::class.java), typeCaptor.firstValue)
646+
assertEquals(adapter.toJson(sendMessageRequest), requestBodyCaptor.firstValue)
647+
assertNull(queryParamCaptor.firstValue)
648+
649+
// Verify the sendAt field is properly set as Long
650+
assertEquals(1620000000L, sendMessageRequest.sendAt)
651+
}
652+
653+
@Test
654+
fun `sending a message with Long sendAt value calls requests with the correct params`() {
655+
val adapter = JsonHelper.moshi().adapter(SendMessageRequest::class.java)
656+
val longTimestamp = 1893456000L // Year 2030 timestamp that exceeds Int.MAX_VALUE in the future
657+
val sendMessageRequest =
658+
SendMessageRequest.Builder(to = listOf(EmailName(email = "[email protected]", name = "Test")))
659+
.body("Hello, I just sent a message using Nylas!")
660+
.subject("Hello from Nylas!")
661+
.sendAt(longTimestamp) // Long value
662+
.build()
663+
664+
messages.send(grantId, sendMessageRequest)
665+
666+
val pathCaptor = argumentCaptor<String>()
667+
val typeCaptor = argumentCaptor<Type>()
668+
val requestBodyCaptor = argumentCaptor<String>()
669+
val queryParamCaptor = argumentCaptor<IQueryParams>()
670+
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
671+
verify(mockNylasClient).executePost<Response<Message>>(
672+
pathCaptor.capture(),
673+
typeCaptor.capture(),
674+
requestBodyCaptor.capture(),
675+
queryParamCaptor.capture(),
676+
overrideParamCaptor.capture(),
677+
)
678+
679+
assertEquals("v3/grants/$grantId/messages/send", pathCaptor.firstValue)
680+
assertEquals(Types.newParameterizedType(Response::class.java, Message::class.java), typeCaptor.firstValue)
681+
assertEquals(adapter.toJson(sendMessageRequest), requestBodyCaptor.firstValue)
682+
assertNull(queryParamCaptor.firstValue)
683+
684+
// Verify the sendAt field is properly set as Long
685+
assertEquals(longTimestamp, sendMessageRequest.sendAt)
686+
}
687+
619688
@Test
620689
fun `sending a message with a large attachment calls requests with the correct params`() {
621690
val adapter = JsonHelper.moshi().adapter(SendMessageRequest::class.java)

0 commit comments

Comments
 (0)