Skip to content

Commit

Permalink
70
Browse files Browse the repository at this point in the history
70
  • Loading branch information
umerov1999 committed Aug 28, 2024
1 parent b4dc462 commit 6f89adc
Show file tree
Hide file tree
Showing 181 changed files with 4,664 additions and 1,762 deletions.
4 changes: 0 additions & 4 deletions app_fenrir/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,10 @@ android {
minifyEnabled = true
shrinkResources = true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

signingConfig signingConfigs.fenrir
}
debug {
minifyEnabled = false
shrinkResources = false

signingConfig signingConfigs.fenrir
}
}

Expand Down
6 changes: 4 additions & 2 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object Constants {
const val FILE_PROVIDER_AUTHORITY: String = "${BuildConfig.APPLICATION_ID}.file_provider"
const val VK_ANDROID_APP_VERSION_NAME = "8.15"
const val VK_ANDROID_APP_VERSION_CODE = "15271"
const val KATE_APP_VERSION_NAME = "114 lite"
const val KATE_APP_VERSION_CODE = "560"
const val KATE_APP_VERSION_NAME = "118 lite"
const val KATE_APP_VERSION_CODE = "566"

const val IOS_APP_VERSION_CODE = "3893"

Expand Down Expand Up @@ -51,4 +51,6 @@ object Constants {
const val LONGPOLL_TIMEOUT = 45L
const val LONGPOLL_WAIT = 25L
const val PICASSO_TIMEOUT = 15L

val CATALOG_V2_IGNORE_SECTIONS = arrayOf("podcasts", "radiostations")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FcmListenerService : FirebaseMessagingService() {
override fun onNewToken(s: String) {
super.onNewToken(s)
pushRegistrationResolver
.resolvePushRegistration()
.resolvePushRegistration(Settings.get().accounts().current, applicationContext)
.hiddenIO()
}

Expand All @@ -52,7 +52,7 @@ class FcmListenerService : FirebaseMessagingService() {
return
}
val registrationResolver = pushRegistrationResolver
if (!registrationResolver.canReceivePushNotification()) {
if (!registrationResolver.canReceivePushNotification(accountId)) {
Logger.d(TAG, "Invalid push registration on VK")
return
}
Expand Down Expand Up @@ -115,22 +115,13 @@ class FcmListenerService : FirebaseMessagingService() {
PushType.BIRTHDAY -> BirthdayFCMMessage.fromRemoteMessage(message)
?.notify(context, accountId)

PushType.VALIDATE_DEVICE -> NotificationHelper.showSimpleNotification(
PushType.SHOW_MESSAGE, PushType.VALIDATE_DEVICE -> NotificationHelper.showSimpleNotification(
context,
message.data["body"],
message.data["title"],
null,
message.data["url"]
)

PushType.SHOW_MESSAGE -> NotificationHelper.showSimpleNotification(
context,
message.data["body"],
message.data["title"],
null,
null
)

PushType.MENTION -> MentionMessage.fromRemoteMessage(message)
.notify(context, accountId)

Expand Down
6 changes: 0 additions & 6 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/Includes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import dev.ragnarok.fenrir.media.story.AppStoryPlayerFactory
import dev.ragnarok.fenrir.media.story.IStoryPlayerFactory
import dev.ragnarok.fenrir.media.voice.IVoicePlayerFactory
import dev.ragnarok.fenrir.media.voice.VoicePlayerFactory
import dev.ragnarok.fenrir.push.IDeviceIdProvider
import dev.ragnarok.fenrir.push.IPushRegistrationResolver
import dev.ragnarok.fenrir.push.PushRegistrationResolver
import dev.ragnarok.fenrir.settings.IProxySettings
Expand All @@ -29,7 +28,6 @@ import dev.ragnarok.fenrir.settings.ProxySettingsImpl
import dev.ragnarok.fenrir.settings.SettingsImpl
import dev.ragnarok.fenrir.upload.IUploadManager
import dev.ragnarok.fenrir.upload.UploadManagerImpl
import dev.ragnarok.fenrir.util.Utils

object Includes {
val proxySettings: IProxySettings by lazy {
Expand All @@ -50,10 +48,6 @@ object Includes {

val pushRegistrationResolver: IPushRegistrationResolver by lazy {
PushRegistrationResolver(
object : IDeviceIdProvider {
override val deviceId: String
get() = Utils.getDeviceId(provideApplicationContext())
},
settings,
networkInterfaces
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ open class MainActivity : AppCompatActivity(), NavigationDrawerCallbacks, OnSect
return
}
mCompositeJob.add(
pushRegistrationResolver.resolvePushRegistration()
pushRegistrationResolver.resolvePushRegistration(mAccountId, this)
.hiddenIO()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract class AbsVKApiInterceptor(private val version: String) :
if (!hasDeviceId) {
formBuilder.add(
"device_id",
Utils.getDeviceId(provideApplicationContext())
Utils.getDeviceId(type, provideApplicationContext())
)
}
return chain.proceed(
Expand Down
1 change: 1 addition & 0 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ object Auth {
Constants.DEVICE_COUNTRY_CODE, "utf-8"
) + "&device_id=" + URLEncoder.encode(
Utils.getDeviceId(
Constants.DEFAULT_ACCOUNT_TYPE,
provideApplicationContext()
), "utf-8"
))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.ragnarok.fenrir.api

class NeedValidationException(
val phone: String?,
val validationType: String?,
val validationURL: String?,
val sid: String?,
Expand Down
49 changes: 46 additions & 3 deletions app_fenrir/src/main/kotlin/dev/ragnarok/fenrir/api/impl/AuthApi.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ragnarok.fenrir.api.impl

import dev.ragnarok.fenrir.Constants
import dev.ragnarok.fenrir.Constants.DEVICE_COUNTRY_CODE
import dev.ragnarok.fenrir.Includes.provideApplicationContext
import dev.ragnarok.fenrir.api.ApiException
Expand All @@ -8,6 +9,7 @@ import dev.ragnarok.fenrir.api.CaptchaNeedException
import dev.ragnarok.fenrir.api.IDirectLoginServiceProvider
import dev.ragnarok.fenrir.api.NeedValidationException
import dev.ragnarok.fenrir.api.interfaces.IAuthApi
import dev.ragnarok.fenrir.api.model.AnonymToken
import dev.ragnarok.fenrir.api.model.LoginResponse
import dev.ragnarok.fenrir.api.model.VKApiValidationResponse
import dev.ragnarok.fenrir.api.model.response.BaseResponse
Expand Down Expand Up @@ -50,6 +52,7 @@ class AuthApi(private val service: IDirectLoginServiceProvider) : IAuthApi {
captchaKey,
if (forceSms) 1 else null,
getDeviceId(
Constants.DEFAULT_ACCOUNT_TYPE,
provideApplicationContext()
),
if (libverify_support) 1 else null,
Expand All @@ -66,6 +69,7 @@ class AuthApi(private val service: IDirectLoginServiceProvider) : IAuthApi {

"need_validation".equals(response.error, ignoreCase = true) -> {
throw NeedValidationException(
username,
response.validationType,
response.redirect_uri,
response.validation_sid,
Expand All @@ -87,19 +91,31 @@ class AuthApi(private val service: IDirectLoginServiceProvider) : IAuthApi {
}

override fun validatePhone(
phone: String?,
apiId: Int,
clientId: Int,
clientSecret: String?,
sid: String?,
v: String?,
libverify_support: Boolean
libverify_support: Boolean,
allow_callreset: Boolean
): Flow<VKApiValidationResponse> {
return service.provideAuthService()
.flatMapConcat {
it.validatePhone(
apiId, clientId, clientSecret, sid, v, getDeviceId(
phone,
apiId,
clientId,
clientSecret,
sid,
v,
getDeviceId(
Constants.DEFAULT_ACCOUNT_TYPE,
provideApplicationContext()
), if (libverify_support) 1 else null, DEVICE_COUNTRY_CODE
),
if (libverify_support) 1 else null,
if (allow_callreset) 1 else null,
DEVICE_COUNTRY_CODE
)
.map(extractResponseWithErrorHandling())
}
Expand Down Expand Up @@ -140,6 +156,33 @@ class AuthApi(private val service: IDirectLoginServiceProvider) : IAuthApi {
}
}

override fun get_anonym_token(
apiId: Int,
clientId: Int,
clientSecret: String?,
v: String?,
device_id: String?
): Flow<AnonymToken> {
return service.provideAuthService()
.flatMapConcat {
it.get_anonym_token(
apiId,
clientId,
clientSecret,
v,
device_id,
DEVICE_COUNTRY_CODE
)
.map { s ->
if (s.error != null) {
throw AuthException(s.error.orEmpty(), s.errorDescription)
} else {
s
}
}
}
}

companion object {
fun <T : Any> extractResponseWithErrorHandling(): (BaseResponse<T>) -> T = { err ->
err.error?.let { throw ApiException(it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ragnarok.fenrir.api.interfaces

import dev.ragnarok.fenrir.api.model.AnonymToken
import dev.ragnarok.fenrir.api.model.LoginResponse
import dev.ragnarok.fenrir.api.model.VKApiValidationResponse
import dev.ragnarok.fenrir.api.model.response.VKUrlResponse
Expand All @@ -23,12 +24,14 @@ interface IAuthApi {
): Flow<LoginResponse>

fun validatePhone(
phone: String?,
apiId: Int,
clientId: Int,
clientSecret: String?,
sid: String?,
v: String?,
libverify_support: Boolean
libverify_support: Boolean,
allow_callreset: Boolean
): Flow<VKApiValidationResponse>

fun authByExchangeToken(
Expand All @@ -42,4 +45,12 @@ interface IAuthApi {
gaid: String?,
v: String?
): Flow<VKUrlResponse>

fun get_anonym_token(
apiId: Int,
clientId: Int,
clientSecret: String?,
v: String?,
device_id: String?
): Flow<AnonymToken>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package dev.ragnarok.fenrir.api.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
class AnonymToken {
@SerialName("token")
var token: String? = null

@SerialName("expired_at")
var expired_at: Long = 0

@SerialName("error")
var error: String? = null

@SerialName("error_description")
var errorDescription: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ class LoginResponse {

@SerialName("validation_sid")
var validation_sid: String? = null

@SerialName("expired_at")
var expired_at: Long = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ import kotlinx.serialization.Serializable
class RefreshToken {
@SerialName("token")
var token: String? = null

@SerialName("expired_at")
var expired_at: Long = 0
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.ragnarok.fenrir.api.services

import dev.ragnarok.fenrir.api.model.AnonymToken
import dev.ragnarok.fenrir.api.model.LoginResponse
import dev.ragnarok.fenrir.api.model.VKApiValidationResponse
import dev.ragnarok.fenrir.api.model.response.BaseResponse
Expand Down Expand Up @@ -82,19 +83,23 @@ class IAuthService : IServiceRest() {
}

fun validatePhone(
phone: String?,
apiId: Int,
clientId: Int,
clientSecret: String?,
sid: String?,
v: String?,
device_id: String?,
libverify_support: Int?,
allow_callreset: Int?,
lang: String?
): Flow<BaseResponse<VKApiValidationResponse>> {
return rest.request(
"auth.validatePhone",
form(
"libverify_support" to libverify_support,
"allow_callreset" to allow_callreset,
"phone" to phone,
"api_id" to apiId,
"client_id" to clientId,
"client_secret" to clientSecret,
Expand All @@ -108,6 +113,28 @@ class IAuthService : IServiceRest() {
)
}

fun get_anonym_token(
apiId: Int,
clientId: Int,
clientSecret: String?,
v: String?,
device_id: String?,
lang: String?
): Flow<AnonymToken> {
return rest.request(
"get_anonym_token",
form(
"api_id" to apiId,
"client_id" to clientId,
"client_secret" to clientSecret,
"v" to v,
"device_id" to device_id,
"lang" to lang,
"https" to 1
), AnonymToken.serializer()
)
}

/*
fun refreshTokens(
clientId: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class DirectAuthPresenter(savedInstanceState: Bundle?) :
} else {
val type = t.validationType
val sid = t.sid
val phone = t.phone
when {
"2fa_sms".equals(type, ignoreCase = true) || "2fa_libverify".equals(
type,
Expand All @@ -114,11 +115,13 @@ class DirectAuthPresenter(savedInstanceState: Bundle?) :
if (!sid.isNullOrEmpty() && requireSmsCode) {
appendJob(networker.vkAuth()
.validatePhone(
phone,
Constants.API_ID,
Constants.API_ID,
Constants.SECRET,
sid,
Constants.AUTH_API_VERSION,
true,
true
)
.delayedFlow(1000)
Expand Down
Loading

0 comments on commit 6f89adc

Please sign in to comment.