Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Handle android time with unix seconds not ms + unify API response formats #17

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,37 @@ fun WritableArray.pushMapList(list: List<WritableMap>): WritableArray {
fun WritableMap.putBooleanIfNotNull(
key: String,
value: Boolean?,
) {
): WritableMap {
if (value != null) {
putBoolean(key, value)
} else {
putNull(key)
}
return this
}

fun WritableMap.putIntIfNotNull(
key: String,
value: Int?,
) {
): WritableMap {
if (value != null) {
putInt(key, value)
} else {
putNull(key)
}
return this
}

fun WritableMap.putDoubleIfNotNull(
key: String,
value: Double?,
) {
): WritableMap {
if (value != null) {
putDouble(key, value)
} else {
putNull(key)
}
return this
}

fun argMap(): WritableMap {
Expand Down Expand Up @@ -177,3 +186,6 @@ object RNCKakaoUtil {
return (d1.time - d2.time) / 1000L
}
}

val Date.unix: Long
get() = time / 1000
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import net.mjstudio.rnkakao.core.util.getIntElseNull
import net.mjstudio.rnkakao.core.util.onMain
import net.mjstudio.rnkakao.core.util.pushMapList
import net.mjstudio.rnkakao.core.util.putBooleanIfNotNull
import net.mjstudio.rnkakao.core.util.putDoubleIfNotNull
import net.mjstudio.rnkakao.core.util.putIntIfNotNull
import net.mjstudio.rnkakao.core.util.rejectWith

Expand Down Expand Up @@ -84,7 +85,7 @@ class RNCKakaoSocialModule internal constructor(context: ReactApplicationContext
users.users?.map {
argMap().apply {
putString("uuid", it.uuid)
putIntIfNotNull("id", it.id?.toInt())
putDoubleIfNotNull("id", it.id?.toDouble())
putBooleanIfNotNull("favorite", it.favorite)
putString("profileNickname", it.profileNickname)
putString("profileThumbnailImage", it.profileThumbnailImage)
Expand Down Expand Up @@ -171,7 +172,7 @@ class RNCKakaoSocialModule internal constructor(context: ReactApplicationContext
argArr().pushMapList(
friends.elements!!.map {
argMap().apply {
putIntIfNotNull("id", it.id?.toInt())
putDoubleIfNotNull("id", it.id?.toDouble())
putString("uuid", it.uuid)
putString("profileNickname", it.profileNickname)
putString("profileThumbnailImage", it.profileThumbnailImage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import net.mjstudio.rnkakao.core.util.pushMapList
import net.mjstudio.rnkakao.core.util.pushStringList
import net.mjstudio.rnkakao.core.util.putBooleanIfNotNull
import net.mjstudio.rnkakao.core.util.putDoubleIfNotNull
import net.mjstudio.rnkakao.core.util.putIntIfNotNull
import net.mjstudio.rnkakao.core.util.rejectWith
import net.mjstudio.rnkakao.core.util.unix
import java.util.Date

class RNCKakaoUserModule internal constructor(context: ReactApplicationContext) :
Expand Down Expand Up @@ -61,11 +61,11 @@ class RNCKakaoUserModule internal constructor(context: ReactApplicationContext)
putString("idToken", token.idToken)
putDouble(
"accessTokenExpiresAt",
token.accessTokenExpiresAt.time.toDouble(),
token.accessTokenExpiresAt.unix.toDouble(),
)
putDouble(
"refreshTokenExpiresAt",
token.refreshTokenExpiresAt.time.toDouble(),
token.refreshTokenExpiresAt.unix.toDouble(),
)
putDouble(
"accessTokenExpiresIn",
Expand Down Expand Up @@ -230,24 +230,17 @@ class RNCKakaoUserModule internal constructor(context: ReactApplicationContext)
promise.rejectWith(RNCKakaoResponseNotFoundException("serviceTerms"))
} else {
promise.resolve(
argMap().apply {
putArray(
"allowedServiceTerms",
argArr().apply {
serviceTerms.serviceTerms?.forEach { term ->
pushMap(
argMap().apply {
putString("tag", term.tag)
putDoubleIfNotNull("agreedAt", term.agreedAt?.time?.toDouble())
putBoolean("agreed", term.agreed)
putBoolean("required", term.required)
putBoolean("revocable", term.revocable)
},
)
}
},
)
},
argArr().pushMapList(
serviceTerms.serviceTerms?.map { term ->
argMap().apply {
putString("tag", term.tag)
putDoubleIfNotNull("agreedAt", term.agreedAt?.unix?.toDouble())
putBoolean("agreed", term.agreed)
putBoolean("required", term.required)
putBoolean("revocable", term.revocable)
}
} ?: listOf(),
),
)
}
}
Expand All @@ -264,18 +257,18 @@ class RNCKakaoUserModule internal constructor(context: ReactApplicationContext)
} else {
promise.resolve(
argMap().apply {
putIntIfNotNull("userId", addrs.userId?.toInt())
putDoubleIfNotNull("userId", addrs.userId?.toDouble())
putBooleanIfNotNull("needsAgreement", addrs.needsAgreement)
putArray(
"shippingAddresses",
argArr().apply {
pushMapList(
addrs.shippingAddresses?.map { addr ->
argMap().apply {
putInt("id", addr.id.toInt())
putDouble("id", addr.id.toDouble())
putString("name", addr.name)
putBoolean("isDefault", addr.isDefault)
putDoubleIfNotNull("updatedAt", addr.updatedAt?.time?.toDouble())
putDoubleIfNotNull("updatedAt", addr.updatedAt?.unix?.toDouble())
putString("type", addr.type?.name)
putString("baseAddress", addr.baseAddress)
putString("detailAddress", addr.detailAddress)
Expand Down Expand Up @@ -306,7 +299,7 @@ class RNCKakaoUserModule internal constructor(context: ReactApplicationContext)
} else {
promise.resolve(
argMap().apply {
putIntIfNotNull("id", user.id?.toInt())
putDoubleIfNotNull("id", user.id?.toDouble())
putString("name", user.kakaoAccount?.name)

putString("email", user.kakaoAccount?.email)
Expand Down
Loading