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

[RELEASE] Merge DEVELOP into BETA #261

Open
wants to merge 6 commits into
base: beta
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Comma-separated list of rules to disable (Since 0.34.0)
# Note that rules in any ruleset other than the standard ruleset will need to be prefixed
# by the ruleset identifier.

# Needed to disable due this missing improvement https://github.com/pinterest/ktlint/issues/527
[*.kt]
disabled_rules=import-ordering
21 changes: 10 additions & 11 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,23 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"

compile "se.ansman.kotshi:api:${versions.kotshi}"
implementation "se.ansman.kotshi:api:${versions.kotshi}"
kapt "se.ansman.kotshi:compiler:${versions.kotshi}"

compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

compile "com.squareup.okhttp3:okhttp:${versions.okhttp}"
implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"

compile "com.squareup.moshi:moshi:${versions.moshi}"
implementation "com.squareup.moshi:moshi:${versions.moshi}"

testCompile "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}"
testCompile "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.12.0'
testCompile 'org.assertj:assertj-core:3.8.0'
testCompile "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
testCompile 'com.github.luciofm:mockwebserver:852ce0b657'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testImplementation "org.junit.jupiter:junit-jupiter:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockitoCore}"
testImplementation "org.assertj:assertj-core:${versions.assertj}"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockitoKotlin}"
}

compileKotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import se.ansman.kotshi.KotshiJsonAdapterFactory
@KotshiJsonAdapterFactory
abstract class CommonJsonAdapterFactory : JsonAdapter.Factory {
companion object {
val INSTANCE: CommonJsonAdapterFactory = KotshiCommonJsonAdapterFactory()
val INSTANCE: CommonJsonAdapterFactory = KotshiCommonJsonAdapterFactory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ class FallbackSealedClassJsonAdapter<T>(private val classType: Class<T>,
/**
* Builds an adapter that can process sealed classes annotated with [FallbackSealedClass].
*/
val ADAPTER_FACTORY: JsonAdapter.Factory = JsonAdapter.Factory { type, annotations, moshi ->
if (!annotations.isEmpty()) return@Factory null
val ADAPTER_FACTORY: Factory = Factory { type, annotations, moshi ->
if (annotations.isNotEmpty()) return@Factory null

val rawType = Types.getRawType(type)
val annotation = rawType.getAnnotation(FallbackSealedClass::class.java) ?: return@Factory null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.Json

interface BaseRoom {
val id: String
val type: RoomType
val type: RoomType?
val fullName: String?
val user: SimpleUser?
val readonly: Boolean?
Expand Down
6 changes: 1 addition & 5 deletions common/src/main/kotlin/chat/rocket/common/model/Email.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package chat.rocket.common.model

import se.ansman.kotshi.JsonDefaultValueBoolean
import se.ansman.kotshi.JsonSerializable

@JsonSerializable
data class Email(val address: String,
@JsonDefaultValueBoolean(false)
val verified: Boolean
)
data class Email(val address: String, val verified: Boolean)
22 changes: 11 additions & 11 deletions compat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutine}"
implementation project (':core')
implementation project (':common')

compileOnly 'com.google.code.findbugs:jsr305:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutine}"

compile project (':core')
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

testCompile "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}"
testCompile "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.10.0'
testCompile 'org.assertj:assertj-core:3.8.0'
testCompile "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
testCompile 'com.github.luciofm:mockwebserver:852ce0b657'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testImplementation "org.junit.jupiter:junit-jupiter:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockitoCore}"
testImplementation "org.assertj:assertj-core:${versions.assertj}"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockitoKotlin}"
}

compileKotlin {
Expand Down
2 changes: 1 addition & 1 deletion compat/src/main/kotlin/chat/rocket/core/compat/Call.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class Call(val job: Job) {
fun cancel() {
job.cancel()
}
}
}
2 changes: 1 addition & 1 deletion compat/src/main/kotlin/chat/rocket/core/compat/Server.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import kotlinx.coroutines.Dispatchers
* Returns the current logged server information.
* Must be used with a coroutine context (async, launch, etc)
*/
fun RocketChatClient.serverInfo(future: Callback<ServerInfo>): Call = callback(Dispatchers.IO, future) { serverInfo() }
fun RocketChatClient.serverInfo(future: Callback<ServerInfo>): Call = callback(Dispatchers.IO, future) { serverInfo() }
2 changes: 1 addition & 1 deletion compat/src/main/kotlin/chat/rocket/core/compat/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import kotlinx.coroutines.Dispatchers
* Returns the current logged user information, useful to check if the Token from TokenProvider
* is still valid. Must be used with a coroutine context (async, launch, etc)
*/
fun RocketChatClient.me(future: Callback<Myself>): Call = callback(Dispatchers.IO, future) { me() }
fun RocketChatClient.me(future: Callback<Myself>): Call = callback(Dispatchers.IO, future) { me() }
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import chat.rocket.core.compat.Callback
import kotlinx.coroutines.AbstractCoroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.newCoroutineContext
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.startCoroutine

@ExperimentalCoroutinesApi
@JvmOverloads
fun <T> callback(
context: CoroutineContext = Dispatchers.Default,
Expand All @@ -36,11 +38,11 @@ private class CallbackCoroutine<in T>(
callback.onSuccess(value)
}

override fun onCompletedExceptionally(exception: Throwable) {
if (exception is RocketChatException) {
callback.onError(exception)
override fun onCancelled(cause: Throwable, handled: Boolean) {
if (cause is RocketChatException) {
callback.onError(cause)
} else {
callback.onError(RocketChatException(exception.message ?: "Unknown Error", exception))
callback.onError(RocketChatException(cause.message ?: "Unknown Error", cause))
}
}
}
25 changes: 14 additions & 11 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
compile project (':common')
implementation project (':common')

compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutine}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${versions.coroutine}"

compile "se.ansman.kotshi:api:${versions.kotshi}"
implementation "se.ansman.kotshi:api:${versions.kotshi}"
kapt "se.ansman.kotshi:compiler:${versions.kotshi}"

implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"

compileOnly 'org.json:json:20090211'
compileOnly 'com.google.code.findbugs:jsr305:3.0.2'

testCompile "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}"
testCompile "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.12.0'
testCompile 'org.assertj:assertj-core:3.8.0'
testCompile "com.nhaarman:mockito-kotlin-kt1.1:1.5.0"
testCompile 'com.github.luciofm:mockwebserver:852ce0b657'
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:${versions.kotlin}"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
testImplementation "org.junit.jupiter:junit-jupiter:${versions.junit}"
testImplementation "org.mockito:mockito-core:${versions.mockitoCore}"
testImplementation "org.assertj:assertj-core:${versions.assertj}"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:${versions.mockitoKotlin}"
testImplementation "com.squareup.okhttp3:mockwebserver:${versions.okhttpMockWebServer}"
testImplementation "io.fabric8:mockwebserver:${versions.mockWebServer}"
}

compileKotlin {
Expand Down
26 changes: 12 additions & 14 deletions core/src/main/kotlin/chat/rocket/core/RocketChatClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import chat.rocket.common.util.NoOpLogger
import chat.rocket.common.util.PlatformLogger
import chat.rocket.common.util.RealLogger
import chat.rocket.common.util.ifNull
import chat.rocket.core.internal.RestResult
import chat.rocket.core.internal.RestMultiResult
import chat.rocket.core.internal.SettingsAdapter
import chat.rocket.core.internal.AttachmentAdapterFactory
import chat.rocket.core.internal.RoomListAdapterFactory
import chat.rocket.core.internal.CoreJsonAdapterFactory
import chat.rocket.core.internal.ReactionsAdapter
import chat.rocket.core.internal.RestMultiResult
import chat.rocket.core.internal.RestResult
import chat.rocket.core.internal.RoomListAdapterFactory
import chat.rocket.core.internal.SettingsAdapter
import chat.rocket.core.internal.model.Subscription
import chat.rocket.core.internal.realtime.socket.Socket
import chat.rocket.core.internal.realtime.socket.model.State
Expand All @@ -27,14 +27,18 @@ import chat.rocket.core.model.Myself
import chat.rocket.core.model.Room
import chat.rocket.core.model.url.MetaJsonAdapter
import com.squareup.moshi.Moshi
import java.security.InvalidParameterException
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import okhttp3.HttpUrl
import okhttp3.MediaType
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.OkHttpClient
import java.security.InvalidParameterException
import kotlin.coroutines.CoroutineContext

val CONTENT_TYPE_JSON = "application/json; charset=utf-8".toMediaTypeOrNull()
fun createRocketChatClient(init: RocketChatClient.Builder.() -> Unit) = RocketChatClient.Builder(init).build()

class RocketChatClient private constructor(
internal val httpClient: OkHttpClient,
Expand Down Expand Up @@ -77,7 +81,7 @@ class RocketChatClient private constructor(
url = sanitizeUrl(baseUrl)
agent = userAgent

HttpUrl.parse(url)?.let {
url.toHttpUrlOrNull()?.let {
restUrl = it
}.ifNull {
throw InvalidParameterException("You must pass a valid HTTP or HTTPS URL")
Expand Down Expand Up @@ -109,12 +113,6 @@ class RocketChatClient private constructor(
builder.tokenRepository,
if (builder.enableLogger) RealLogger(builder.platformLogger, builder.restUrl) else NoOpLogger)

companion object {
val CONTENT_TYPE_JSON = MediaType.parse("application/json; charset=utf-8")

fun create(init: Builder.() -> Unit) = Builder(init).build()
}

class Builder private constructor() {

constructor(init: Builder.() -> Unit) : this() {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/chat/rocket/core/TokenRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface TokenRepository {
fun save(url: String, token: Token)

fun get(url: String): Token?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import chat.rocket.common.util.Logger
import chat.rocket.core.model.attachment.Attachment
import chat.rocket.core.model.attachment.Color
import chat.rocket.core.model.attachment.Field
import chat.rocket.core.model.attachment.actions.Action
import chat.rocket.core.model.attachment.actions.ButtonAction
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import chat.rocket.core.model.attachment.actions.Action
import chat.rocket.core.model.attachment.actions.ButtonAction
import java.lang.reflect.Type

class AttachmentAdapter(moshi: Moshi, private val logger: Logger) : JsonAdapter<Attachment>() {
Expand Down Expand Up @@ -359,4 +359,4 @@ fun JsonReader.nextBooleanOrFalse(): Boolean {
return false
}
return nextBoolean()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import se.ansman.kotshi.KotshiJsonAdapterFactory
@KotshiJsonAdapterFactory
abstract class CoreJsonAdapterFactory : JsonAdapter.Factory {
companion object {
val INSTANCE: CoreJsonAdapterFactory = KotshiCoreJsonAdapterFactory()
val INSTANCE: CoreJsonAdapterFactory = KotshiCoreJsonAdapterFactory
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import chat.rocket.core.model.Reactions
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.ToJson
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.ToJson

class ReactionsAdapter : JsonAdapter<Reactions>() {

Expand Down Expand Up @@ -97,4 +97,4 @@ class ReactionsAdapter : JsonAdapter<Reactions>() {
endObject()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ internal class RoomListAdapterFactory(private val logger: Logger) : JsonAdapter.

return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,4 @@ class SettingsAdapter : JsonAdapter<Map<String, Value<Any>>>() {
throw JsonEncodingException("expected a \"$expected\" value, got \"$name\"")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import se.ansman.kotshi.JsonSerializable
data class CasLoginPayload(val cas: CasData)

@JsonSerializable
data class CasData(val credentialToken: String)
data class CasData(val credentialToken: String)
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ data class ChatRoomJoinCodePayload(val roomId: String, val joinCode: String)
data class ChatRoomKickPayload(val roomId: String, val userId: String)

@JsonSerializable
data class ChatRoomFavoritePayload(val roomId: String, val favorite: Boolean)
data class ChatRoomFavoritePayload(val roomId: String, val favorite: Boolean)
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class CommandPayload(
val command: String,
val roomId: String,
val params: String?
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package chat.rocket.core.internal.model
import se.ansman.kotshi.JsonSerializable

@JsonSerializable
data class ConfigurationsPayload(val configurations: List<Map<String, String>>)
data class ConfigurationsPayload(val configurations: List<Map<String, String>>)
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ data class CreateNewChannelPayload(
@Json(name = "name") val channelName: String,
@Json(name = "members") val membersToInvite: List<String>?,
val readOnly: Boolean?
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class DeletePayload(
val roomId: String,
val msgId: String,
val asUser: Boolean = false
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ data class EmailLoginPayload(
val user: String,
val password: String,
val code: String? = null
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package chat.rocket.core.internal.model
import se.ansman.kotshi.JsonSerializable

@JsonSerializable
data class ForgotPasswordPayload(val email: String?)
data class ForgotPasswordPayload(val email: String?)
Loading