Skip to content

Commit

Permalink
feat: .setAccessTokenHeader; refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yurizhuk committed Jun 8, 2024
1 parent 2e95482 commit 1ed8de3
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 11 deletions.
2 changes: 1 addition & 1 deletion mobile-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ afterEvaluate {

groupId = "com.webitel"
artifactId = "mobile-sdk"
version = "0.9.3"
version = "0.10.1"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ internal class AuthRepository(
}


fun setAccessTokenHeader(token: String) {
authApi.setAccessTokenHeader(token)
}


fun registerFcm(
token: String,
callback: CallbackListener<RegisterResult>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import com.webitel.mobile_sdk.domain.ChatClient
import com.webitel.mobile_sdk.domain.Code
import com.webitel.mobile_sdk.domain.Dialog
import com.webitel.mobile_sdk.domain.Error
import com.webitel.mobile_sdk.domain.Keyboard
import com.webitel.mobile_sdk.domain.Member
import com.webitel.mobile_sdk.domain.Message
import com.webitel.mobile_sdk.domain.MessageCallbackListener
import com.webitel.mobile_sdk.domain.ReplyMarkup
import io.grpc.StatusRuntimeException
import io.grpc.stub.StreamObserver
import webitel.chat.History.ChatMessages
Expand Down Expand Up @@ -539,7 +539,7 @@ internal class WebitelChat(
id = it.id,
sentAt = it.date,
postback = if (it.hasPostback()) toPostback(it.postback) else null,
keyboard = if (it.hasKeyboard()) toKeyboard(it.keyboard) else null
replyMarkup = if (it.hasKeyboard()) toKeyboard(it.keyboard) else null
)
)
} catch (_: Exception) {
Expand Down Expand Up @@ -575,9 +575,9 @@ internal class WebitelChat(
}


private fun toKeyboard(value: MessageOuterClass.ReplyMarkup?): Keyboard? {
private fun toKeyboard(value: MessageOuterClass.ReplyMarkup?): ReplyMarkup? {
if (value == null) return null
return Keyboard(value.noInput, toRows(value.buttonsList))
return ReplyMarkup(value.noInput, toRows(value.buttonsList))
}


Expand Down Expand Up @@ -709,7 +709,7 @@ internal class WebitelChat(
sentAt = message.date,
id = message.id,
postback = if (message.hasPostback()) toPostback(message.postback) else null,
keyboard = if (message.hasKeyboard()) toKeyboard(message.keyboard) else null
replyMarkup = if (message.hasKeyboard()) toKeyboard(message.keyboard) else null
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.webitel.mobile_sdk.data.chats

import com.webitel.mobile_sdk.domain.Keyboard
import com.webitel.mobile_sdk.domain.Member
import com.webitel.mobile_sdk.domain.Message
import com.webitel.mobile_sdk.domain.ReplyMarkup


internal class WebitelMessage(
Expand All @@ -14,5 +14,5 @@ internal class WebitelMessage(
override val id: Long,
override val sentAt: Long,
override val postback: Message.Postback?,
override val keyboard: Keyboard?,
override val replyMarkup: ReplyMarkup?,
): Message
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ internal interface AuthApi: BaseApi {
fun logout(callback: CallbackListener<Unit>)
fun inspect(callback: CallbackListener<UserSession>)
fun setSession(auth: String, callback: CallbackListener<UserSession>)
fun setAccessTokenHeader(auth: String)
fun registerFcm(token: String, callback: CallbackListener<RegisterResult>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,37 @@ internal class ClientGrpc(
}


override fun setAccessTokenHeader(auth: String) {
make {
setAccessToken(auth)
updateConnect()
}
}


private fun updateConnect() {
if (requestObserver != null) {
try {
resetBackoff()
val stub = CustomerGrpc.newStub(channel.channel)
val m = CustomerOuterClass.InspectRequest
.newBuilder()
.build()

stub.inspect(m, object : StreamObserver<Auth.AccessToken> {
override fun onNext(value: Auth.AccessToken?) {}
override fun onError(t: Throwable) {
logger.error("setAccessTokenHeader", "${t.message}")
}
override fun onCompleted() {}
})
} catch (e: Exception) {
logger.error("setAccessTokenHeader", "${e.message}")
}
}
}


override fun registerFcm(token: String, callback: CallbackListener<RegisterResult>) {
make {
registerFcmUnaryRequest(token, callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ internal class WebitelPortalClient(
}


override fun setAccessTokenHeader(token: String) {
authRepository.setAccessTokenHeader(token)
}


override fun registerDevice(pushToken: String, callback: CallbackListener<RegisterResult>) {
authRepository.registerFcm(pushToken, callback)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.webitel.mobile_sdk.domain
* @param noInput An option used to block input to force.
* @param rows Markup of button(s)
*/
data class Keyboard(val noInput: Boolean, val rows: List<ButtonRow>)
data class ReplyMarkup(val noInput: Boolean, val rows: List<ButtonRow>)

/**
* @param buttons Button(s) in a row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ interface Message {
val postback: Postback?

/**
* Keyboard. Buttons.
* Reply markup (buttons)
* */
val keyboard: Keyboard?
val replyMarkup: ReplyMarkup?


class options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ interface PortalClient {

fun getUserSession(callback: CallbackListener<Session>)

/**
* Sets and immediately validates the token. The result will be returned in the callback
* */
fun setAccessToken(token: String, callback: CallbackListener<Session>)

/**
* Sets the token in headers without validation
*/
fun setAccessTokenHeader(token: String)

/**
* Register device PUSH subscription
* */
Expand Down

0 comments on commit 1ed8de3

Please sign in to comment.