forked from melod1n/fast-messenger
some improvements
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</manifest>
|
||||
+12
-6
@@ -1,15 +1,21 @@
|
||||
package com.meloda.app.fast.data.api.account
|
||||
|
||||
import com.meloda.app.fast.model.api.requests.AccountSetOfflineRequest
|
||||
import com.meloda.app.fast.model.api.requests.AccountSetOnlineRequest
|
||||
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||
import com.slack.eithernet.ApiResult
|
||||
|
||||
interface AccountRepository {
|
||||
|
||||
suspend fun setOnline(
|
||||
params: AccountSetOnlineRequest
|
||||
): Boolean
|
||||
accessToken: String? = null,
|
||||
voip: Boolean = false
|
||||
): ApiResult<Int, RestApiErrorDomain>
|
||||
|
||||
suspend fun setOffline(
|
||||
params: AccountSetOfflineRequest
|
||||
): Boolean
|
||||
accessToken: String? = null
|
||||
): ApiResult<Int, RestApiErrorDomain>
|
||||
|
||||
suspend fun registerDevice(
|
||||
token: String,
|
||||
deviceId: String
|
||||
): ApiResult<Int, RestApiErrorDomain>
|
||||
}
|
||||
|
||||
+44
-9
@@ -1,19 +1,54 @@
|
||||
package com.meloda.app.fast.data.api.account
|
||||
|
||||
import com.meloda.app.fast.model.api.requests.AccountSetOfflineRequest
|
||||
import com.meloda.app.fast.model.api.requests.AccountSetOnlineRequest
|
||||
import android.os.Build
|
||||
import com.meloda.app.fast.model.api.asInt
|
||||
import com.meloda.app.fast.network.RestApiErrorDomain
|
||||
import com.meloda.app.fast.network.mapApiDefault
|
||||
import com.meloda.app.fast.network.service.account.AccountService
|
||||
import com.slack.eithernet.ApiResult
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
// TODO: 05/05/2024, Danil Nikolaev: implement
|
||||
class AccountRepositoryImpl(
|
||||
private val accountService: AccountService
|
||||
) : com.meloda.app.fast.data.api.account.AccountRepository {
|
||||
private val service: AccountService
|
||||
) : AccountRepository {
|
||||
|
||||
override suspend fun setOnline(params: AccountSetOnlineRequest): Boolean {
|
||||
return false
|
||||
override suspend fun setOnline(
|
||||
accessToken: String?,
|
||||
voip: Boolean
|
||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||
service.setOnline(
|
||||
mutableMapOf(
|
||||
"voip" to voip.asInt().toString()
|
||||
).apply {
|
||||
accessToken?.let { this["access_token"] = it }
|
||||
}
|
||||
).mapApiDefault()
|
||||
}
|
||||
|
||||
override suspend fun setOffline(params: AccountSetOfflineRequest): Boolean {
|
||||
return false
|
||||
override suspend fun setOffline(
|
||||
accessToken: String?
|
||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||
service.setOffline(
|
||||
accessToken?.let { mapOf("access_token" to it) } ?: emptyMap()
|
||||
).mapApiDefault()
|
||||
}
|
||||
|
||||
override suspend fun registerDevice(
|
||||
token: String,
|
||||
deviceId: String
|
||||
): ApiResult<Int, RestApiErrorDomain> = withContext(Dispatchers.IO) {
|
||||
service.registerDevice(
|
||||
mapOf(
|
||||
"token" to token,
|
||||
"pushes_granted" to "1",
|
||||
"app_version" to "15271",
|
||||
"push_provider" to "fcm",
|
||||
"companion_apps" to "vk_client",
|
||||
"type" to "4",
|
||||
"device_id" to deviceId,
|
||||
"system_version" to Build.VERSION.RELEASE
|
||||
)
|
||||
).mapApiDefault()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,14 +51,14 @@ object SettingsController {
|
||||
}
|
||||
}
|
||||
|
||||
var isLongPollInBackgroundEnabled: Boolean =
|
||||
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
||||
var isLongPollInBackgroundEnabled: Boolean
|
||||
get() = getBoolean(
|
||||
SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND,
|
||||
SettingsKeys.DEFAULT_VALUE_FEATURES_LONG_POLL_IN_BACKGROUND
|
||||
)
|
||||
set(value) {
|
||||
field = value
|
||||
put(SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND, value)
|
||||
}
|
||||
set(value) = put(SettingsKeys.KEY_FEATURES_LONG_POLL_IN_BACKGROUND, value)
|
||||
|
||||
var deviceId: String
|
||||
get() = getString("device_id", "").orEmpty()
|
||||
set(value) = put("device_id", value)
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.meloda.app.fast.model.api.requests
|
||||
|
||||
import com.meloda.app.fast.model.api.asInt
|
||||
|
||||
data class AccountSetOnlineRequest(
|
||||
val voip: Boolean,
|
||||
val accessToken: String
|
||||
) {
|
||||
|
||||
val map
|
||||
get() = mutableMapOf(
|
||||
"voip" to voip.asInt().toString(),
|
||||
"access_token" to accessToken
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
data class AccountSetOfflineRequest(val accessToken: String) {
|
||||
val map get() = mutableMapOf("access_token" to accessToken)
|
||||
}
|
||||
+11
-3
@@ -3,6 +3,8 @@ package com.meloda.app.fast.network.service.account
|
||||
import com.meloda.app.fast.network.ApiResponse
|
||||
import com.meloda.app.fast.network.RestApiError
|
||||
import com.slack.eithernet.ApiResult
|
||||
import retrofit2.http.FieldMap
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.QueryMap
|
||||
@@ -12,10 +14,16 @@ interface AccountService {
|
||||
@GET(AccountUrls.SET_ONLINE)
|
||||
suspend fun setOnline(
|
||||
@QueryMap params: Map<String, String>
|
||||
): ApiResult<ApiResponse<Any>, RestApiError>
|
||||
): ApiResult<ApiResponse<Int>, RestApiError>
|
||||
|
||||
@POST(AccountUrls.SET_OFFLINE)
|
||||
@GET(AccountUrls.SET_OFFLINE)
|
||||
suspend fun setOffline(
|
||||
@QueryMap params: Map<String, String>
|
||||
): ApiResult<ApiResponse<Any>, RestApiError>
|
||||
): ApiResult<ApiResponse<Int>, RestApiError>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST(AccountUrls.REGISTER_DEVICE)
|
||||
suspend fun registerDevice(
|
||||
@FieldMap params: Map<String, String>
|
||||
): ApiResult<ApiResponse<Int>, RestApiError>
|
||||
}
|
||||
|
||||
+5
-2
@@ -3,6 +3,9 @@ package com.meloda.app.fast.network.service.account
|
||||
import com.meloda.app.fast.common.AppConstants
|
||||
|
||||
object AccountUrls {
|
||||
const val SET_ONLINE = "${AppConstants.URL_API}/account.setOnline"
|
||||
const val SET_OFFLINE = "${AppConstants.URL_API}/account.setOffline"
|
||||
private const val URL = AppConstants.URL_API
|
||||
|
||||
const val SET_ONLINE = "$URL/account.setOnline"
|
||||
const val SET_OFFLINE = "$URL/account.setOffline"
|
||||
const val REGISTER_DEVICE = "$URL/account.registerDevice"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user