@@ -14,8 +14,8 @@ import kotlinx.coroutines.flow.MutableStateFlow
14
14
import kotlinx.coroutines.sync.Mutex
15
15
import kotlinx.coroutines.sync.withLock
16
16
import ru.usedesk.chat_sdk.data.repository._extra.retrofit.RetrofitApi
17
- import ru.usedesk.chat_sdk.data.repository.api.IApiRepository .*
18
- import ru.usedesk.chat_sdk.data.repository.api.IApiRepository .EventListener
17
+ import ru.usedesk.chat_sdk.data.repository.api.ChatApi .*
18
+ import ru.usedesk.chat_sdk.data.repository.api.ChatApi .EventListener
19
19
import ru.usedesk.chat_sdk.data.repository.api.entity.*
20
20
import ru.usedesk.chat_sdk.data.repository.api.loader.IInitChatResponseConverter
21
21
import ru.usedesk.chat_sdk.data.repository.api.loader.IMessageResponseConverter
@@ -34,7 +34,7 @@ import java.util.*
34
34
import javax.inject.Inject
35
35
import kotlin.math.min
36
36
37
- internal class ApiRepository @Inject constructor(
37
+ internal class ChatApiImpl @Inject constructor(
38
38
private val context : Context ,
39
39
private val socketApi : SocketApi ,
40
40
private val initChatResponseConverter : IInitChatResponseConverter ,
@@ -48,7 +48,7 @@ internal class ApiRepository @Inject constructor(
48
48
multipartConverter,
49
49
gson,
50
50
RetrofitApi : :class.java
51
- ), IApiRepository {
51
+ ), ChatApi {
52
52
53
53
private lateinit var eventListener: EventListener
54
54
private val requestDeferredMap = mutableMapOf<String , CompletableDeferred <SocketSendResponse >>()
@@ -144,15 +144,13 @@ internal class ApiRepository @Inject constructor(
144
144
}
145
145
146
146
override suspend fun connect (
147
- url : String ,
148
- token : String? ,
149
147
configuration : UsedeskChatConfiguration ,
150
- eventListener : EventListener
148
+ eventListener : EventListener ,
151
149
): SocketSendResponse = try {
152
150
this .eventListener = eventListener
153
151
socketApi.connect(
154
- url ,
155
- configuration.toInitChatRequest(token ),
152
+ configuration.urlChat ,
153
+ configuration.toInitChatRequest(),
156
154
socketEventListener
157
155
)
158
156
SocketSendResponse .Done
@@ -181,16 +179,13 @@ internal class ApiRepository @Inject constructor(
181
179
182
180
override suspend fun sendInit (
183
181
configuration : UsedeskChatConfiguration ,
184
- token : String?
185
182
): SocketSendResponse {
186
- val result = socketApi.sendRequest(configuration.toInitChatRequest(token ))
183
+ val result = socketApi.sendRequest(configuration.toInitChatRequest())
187
184
return result // TODO:
188
185
}
189
186
190
- private fun UsedeskChatConfiguration.toInitChatRequest (
191
- token : String?
192
- ) = SocketRequest .Init (
193
- token,
187
+ private fun UsedeskChatConfiguration.toInitChatRequest () = SocketRequest .Init (
188
+ clientToken,
194
189
companyAndChannel(),
195
190
urlChat,
196
191
when {
@@ -243,14 +238,13 @@ internal class ApiRepository @Inject constructor(
243
238
244
239
override suspend fun sendFile (
245
240
configuration : UsedeskChatConfiguration ,
246
- token : String ,
247
241
fileInfo : UsedeskFileInfo ,
248
242
messageId : String ,
249
243
progressFlow : MutableStateFlow <Pair <Long , Long >>
250
244
): SendFileResponse = when {
251
245
isConnected() -> {
252
246
val request = SendFile .Request (
253
- token ,
247
+ configuration.clientToken ,
254
248
messageId,
255
249
fileInfo.uri
256
250
)
@@ -342,11 +336,10 @@ internal class ApiRepository @Inject constructor(
342
336
343
337
override suspend fun loadPreviousMessages (
344
338
configuration : UsedeskChatConfiguration ,
345
- token : String ,
346
339
messageId : String
347
340
): LoadPreviousMessageResponse {
348
341
val request = LoadPreviousMessages .Request (
349
- token ,
342
+ configuration.clientToken ,
350
343
messageId
351
344
)
352
345
val response = doRequestJson(
@@ -398,20 +391,17 @@ internal class ApiRepository @Inject constructor(
398
391
private fun UsedeskChatConfiguration.companyAndChannel () = " ${companyId} _$channelId "
399
392
400
393
override suspend fun sendFields (
401
- token : String ,
402
394
configuration : UsedeskChatConfiguration ,
403
- additionalFields : Map <Long , String >,
404
- additionalNestedFields : List <Map <Long , String >>
405
395
): SendAdditionalFieldsResponse {
406
- val totalFields =
407
- ( additionalFields.toList() + additionalNestedFields.flatMap( Map < Long , String >::toList) )
408
- .map { field ->
409
- SendAdditionalFields .Request .AdditionalField (
410
- field.first,
411
- field.second
412
- )
413
- }
414
- val request = SendAdditionalFields .Request (token , totalFields)
396
+ val nestedFields = configuration.additionalNestedFields.flatMap( Map < Long , String >::toList)
397
+ val totalFields = (configuration. additionalFields.toList() + nestedFields )
398
+ .map { field ->
399
+ SendAdditionalFields .Request .AdditionalField (
400
+ field.first,
401
+ field.second
402
+ )
403
+ }
404
+ val request = SendAdditionalFields .Request (configuration.clientToken , totalFields)
415
405
val response = doRequestJson(
416
406
configuration.urlChatApi,
417
407
request,
0 commit comments