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

[PROJECT] Keep a single class to represent User #232

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 0 additions & 10 deletions common/src/main/kotlin/chat/rocket/common/model/Email.kt

This file was deleted.

15 changes: 0 additions & 15 deletions common/src/main/kotlin/chat/rocket/common/model/User.kt

This file was deleted.

4 changes: 2 additions & 2 deletions compat/src/main/kotlin/chat/rocket/core/compat/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package chat.rocket.core.compat
import chat.rocket.core.RocketChatClient
import chat.rocket.core.compat.internal.callback
import chat.rocket.core.internal.rest.me
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import kotlinx.coroutines.experimental.CommonPool

/**
Expand All @@ -14,7 +14,7 @@ import kotlinx.coroutines.experimental.CommonPool
* @see
* @see RocketChatException
*/
fun RocketChatClient.me(future: Callback<Myself>): Call =
fun RocketChatClient.me(future: Callback<User>): Call =
callback(CommonPool, future) {
me()
}
5 changes: 2 additions & 3 deletions core/src/main/kotlin/chat/rocket/core/RocketChatClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import chat.rocket.common.CommonJsonAdapterFactory
import chat.rocket.common.internal.FallbackSealedClassJsonAdapter
import chat.rocket.common.internal.ISO8601Date
import chat.rocket.common.model.TimestampAdapter
import chat.rocket.common.model.User
import chat.rocket.common.util.CalendarISO8601Converter
import chat.rocket.common.util.Logger
import chat.rocket.common.util.NoOpLogger
Expand All @@ -23,7 +22,7 @@ import chat.rocket.core.internal.realtime.socket.Socket
import chat.rocket.core.internal.realtime.socket.model.State
import chat.rocket.core.internal.realtime.socket.model.StreamMessage
import chat.rocket.core.model.Message
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import chat.rocket.core.model.Room
import chat.rocket.core.model.url.MetaJsonAdapter
import com.squareup.moshi.Moshi
Expand Down Expand Up @@ -62,7 +61,7 @@ class RocketChatClient private constructor(
val roomsChannel = Channel<StreamMessage<Room>>(Channel.UNLIMITED)
val subscriptionsChannel = Channel<StreamMessage<Subscription>>(Channel.UNLIMITED)
val messagesChannel = Channel<Message>(Channel.UNLIMITED)
val userDataChannel = Channel<Myself>(Channel.UNLIMITED)
val userDataChannel = Channel<User>(Channel.UNLIMITED)
val activeUsersChannel = Channel<User>(Channel.UNLIMITED)
val typingStatusChannel = Channel<Pair<String, Boolean>>(Channel.UNLIMITED)
internal val socket: Socket
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package chat.rocket.core.internal.realtime.socket

import chat.rocket.common.model.User
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.model.Subscription
import chat.rocket.core.internal.realtime.message.CONNECT_MESSAGE
Expand All @@ -12,7 +11,7 @@ import chat.rocket.core.internal.realtime.socket.model.ReconnectionStrategy
import chat.rocket.core.internal.realtime.socket.model.State
import chat.rocket.core.internal.realtime.socket.model.StreamMessage
import chat.rocket.core.model.Message
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import chat.rocket.core.model.Room
import com.squareup.moshi.JsonAdapter
import kotlinx.coroutines.experimental.Job
Expand All @@ -39,7 +38,7 @@ class Socket(
internal val roomsChannel: SendChannel<StreamMessage<Room>>,
internal val subscriptionsChannel: SendChannel<StreamMessage<Subscription>>,
internal val messagesChannel: SendChannel<Message>,
internal val userDataChannel: SendChannel<Myself>,
internal val userDataChannel: SendChannel<User>,
internal val activeUsersChannel: SendChannel<User>,
internal val typingStatusChannel: SendChannel<Pair<String, Boolean>>
) : WebSocketListener() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package chat.rocket.core.internal.realtime.socket.message.collection

import chat.rocket.common.model.User
import chat.rocket.core.internal.realtime.socket.Socket
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import kotlinx.coroutines.experimental.launch
import org.json.JSONObject

Expand All @@ -29,7 +28,7 @@ private fun Socket.processUserDataStream(json: JSONObject, id: String) {
val fields = json.optJSONObject("fields")
fields.put("_id", id)

val adapter = moshi.adapter<Myself>(Myself::class.java)
val adapter = moshi.adapter<User>(User::class.java)
val myself = adapter.fromJson(fields.toString())
myself?.let {
if (parentJob == null || !parentJob!!.isActive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chat.rocket.core.internal.rest

import chat.rocket.common.model.BaseResult
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.User
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.model.ChatRoomAnnouncementPayload
import chat.rocket.core.internal.model.ChatRoomDescriptionPayload
Expand All @@ -16,10 +15,7 @@ import chat.rocket.core.internal.model.ChatRoomTypePayload
import chat.rocket.core.internal.model.ChatRoomFavoritePayload
import chat.rocket.core.internal.RestResult
import chat.rocket.core.internal.model.RoomIdPayload
import chat.rocket.core.model.ChatRoomRole
import chat.rocket.core.model.Message
import chat.rocket.core.model.Room
import chat.rocket.core.model.PagedResult
import chat.rocket.core.model.*
import chat.rocket.core.model.attachment.GenericAttachment
import com.squareup.moshi.Types
import kotlinx.coroutines.experimental.CommonPool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chat.rocket.core.internal.rest
import chat.rocket.common.RocketChatException
import chat.rocket.common.model.BaseResult
import chat.rocket.common.model.Token
import chat.rocket.common.model.User
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.RestResult
import chat.rocket.core.internal.model.CasLoginPayload
Expand All @@ -16,6 +15,7 @@ import chat.rocket.core.internal.model.SignUpPayload
import chat.rocket.core.internal.model.ForgotPasswordPayload
import chat.rocket.core.internal.model.CasData
import chat.rocket.core.internal.model.OauthData
import chat.rocket.core.model.User
import com.squareup.moshi.Types
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.withContext
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/kotlin/chat/rocket/core/internal/rest/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package chat.rocket.core.internal.rest
import chat.rocket.common.RocketChatException
import chat.rocket.common.model.BaseResult
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.User
import chat.rocket.common.util.CalendarISO8601Converter
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.RestMultiResult
Expand All @@ -15,7 +14,7 @@ import chat.rocket.core.internal.model.OwnBasicInformationPayload
import chat.rocket.core.internal.model.OwnBasicInformationPayloadData
import chat.rocket.core.internal.model.PasswordPayload
import chat.rocket.core.model.ChatRoom
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import chat.rocket.core.model.Removed
import chat.rocket.core.model.UserRole
import chat.rocket.core.model.Room
Expand All @@ -32,14 +31,14 @@ import java.io.InputStream
* Returns the current logged user information, useful to check if the Token from TokenProvider
* is still valid.
*
* @see Myself
* @see User
* @see RocketChatException
*/
suspend fun RocketChatClient.me(): Myself {
suspend fun RocketChatClient.me(): User {
val httpUrl = requestUrl(restUrl, "me").build()
val request = requestBuilderForAuthenticatedMethods(httpUrl).get().build()

return handleRestCall(request, Myself::class.java)
return handleRestCall(request, User::class.java)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package chat.rocket.core.model

import chat.rocket.common.model.User
import se.ansman.kotshi.JsonSerializable

@JsonSerializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.squareup.moshi.Json
import se.ansman.kotshi.JsonSerializable

@JsonSerializable
data class Myself(
data class User(
@Json(name = "_id") val id: String,
val active: Boolean?,
override val username: String?,
Expand Down
2 changes: 1 addition & 1 deletion rxjava/src/main/kotlin/chat/rocket/core/rxjava/Login.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package chat.rocket.core.rxjava

import chat.rocket.common.model.Token
import chat.rocket.common.model.User
import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.login
import chat.rocket.core.internal.rest.signup
import chat.rocket.core.model.User
import io.reactivex.Single
import kotlinx.coroutines.experimental.rx2.rxSingle

Expand Down
4 changes: 2 additions & 2 deletions rxjava/src/main/kotlin/chat/rocket/core/rxjava/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package chat.rocket.core.rxjava

import chat.rocket.core.RocketChatClient
import chat.rocket.core.internal.rest.me
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import io.reactivex.Single
import kotlinx.coroutines.experimental.rx2.rxSingle

fun RocketChatClient.me(): Single<Myself> =
fun RocketChatClient.me(): Single<User> =
rxSingle {
me()
}
9 changes: 3 additions & 6 deletions sample/src/main/kotlin/rocket/chat/kotlin/sample/Sample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import chat.rocket.common.RocketChatException
import chat.rocket.common.model.RoomType
import chat.rocket.common.model.ServerInfo
import chat.rocket.common.model.Token
import chat.rocket.common.model.UserStatus
import chat.rocket.common.util.PlatformLogger
import chat.rocket.core.RocketChatClient
import chat.rocket.core.TokenRepository
Expand All @@ -17,18 +16,16 @@ import chat.rocket.core.internal.rest.chatRooms
import chat.rocket.core.internal.rest.getFavoriteMessages
import chat.rocket.core.internal.rest.getFiles
import chat.rocket.core.internal.rest.login
import chat.rocket.core.model.Myself
import chat.rocket.core.model.User
import chat.rocket.core.model.history
import chat.rocket.core.model.messages
import chat.rocket.core.rxjava.me
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -180,8 +177,8 @@ fun main(args: Array<String>) {

fun getMeInfoByRx(client: RocketChatClient) {
// using RxJava2
val myself: Single<Myself> = client.me()
myself
val user: Single<User> = client.me()
user
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.newThread())
.subscribe { self ->
Expand Down