mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-14 02:37:30 +00:00
update null checks
This commit is contained in:
parent
d611006438
commit
5f217829b8
@ -48,11 +48,10 @@ fun setupCookies(cookieRaw: String) {
|
||||
}
|
||||
}
|
||||
|
||||
fun removeAllAccounts(context: Context?, callback: RepositoryCallback<Void?>?) {
|
||||
val cookieStore = NET_COOKIE_MANAGER.cookieStore ?: return
|
||||
cookieStore.removeAll()
|
||||
fun removeAllAccounts(context: Context, callback: RepositoryCallback<Void?>?) {
|
||||
NET_COOKIE_MANAGER.cookieStore.removeAll()
|
||||
try {
|
||||
AccountRepository.getInstance(AccountDataSource.getInstance(context!!))
|
||||
AccountRepository.getInstance(AccountDataSource.getInstance(context))
|
||||
.deleteAllAccounts(callback)
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "setupCookies", e)
|
||||
@ -60,6 +59,7 @@ fun removeAllAccounts(context: Context?, callback: RepositoryCallback<Void?>?) {
|
||||
}
|
||||
|
||||
fun getUserIdFromCookie(cookies: String?): Long {
|
||||
cookies ?: return 0
|
||||
val dsUserId = getCookieValue(cookies, "ds_user_id") ?: return 0
|
||||
try {
|
||||
return dsUserId.toLong()
|
||||
@ -69,12 +69,11 @@ fun getUserIdFromCookie(cookies: String?): Long {
|
||||
return 0
|
||||
}
|
||||
|
||||
fun getCsrfTokenFromCookie(cookies: String?): String? {
|
||||
fun getCsrfTokenFromCookie(cookies: String): String? {
|
||||
return getCookieValue(cookies, "csrftoken")
|
||||
}
|
||||
|
||||
private fun getCookieValue(cookies: String?, name: String): String? {
|
||||
if (cookies == null) return null
|
||||
private fun getCookieValue(cookies: String, name: String): String? {
|
||||
val pattern = Pattern.compile("$name=(.+?);")
|
||||
val matcher = pattern.matcher(cookies)
|
||||
return if (matcher.find()) {
|
||||
|
Loading…
Reference in New Issue
Block a user