1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-13 22:43:06 +01:00

Make cookie name null by default

This commit is contained in:
Allan Wang 2019-03-07 18:56:42 -05:00
parent 9edbab9845
commit 2056d9cb72
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
2 changed files with 9 additions and 9 deletions

View File

@ -116,7 +116,7 @@ class LoginActivity : BaseActivity() {
val imageDeferred = async { loadProfile(cookie.id) } val imageDeferred = async { loadProfile(cookie.id) }
val nameDeferred = async { loadUsername(cookie) } val nameDeferred = async { loadUsername(cookie) }
val name: String = nameDeferred.await() val name: String? = nameDeferred.await()
val foundImage: Boolean = imageDeferred.await() val foundImage: Boolean = imageDeferred.await()
L._d { "Logged in and received data" } L._d { "Logged in and received data" }
@ -127,7 +127,7 @@ class LoginActivity : BaseActivity() {
L._i { cookie } L._i { cookie }
} }
textview.text = String.format(getString(R.string.welcome), name) textview.text = String.format(getString(R.string.welcome), name ?: "")
textview.fadeIn() textview.fadeIn()
frostEvent("Login", "success" to true) frostEvent("Login", "success" to true)
@ -172,22 +172,23 @@ class LoginActivity : BaseActivity() {
} }
} }
private suspend fun loadUsername(cookie: CookieEntity): String = withContext(Dispatchers.IO) { private suspend fun loadUsername(cookie: CookieEntity): String? = withContext(Dispatchers.IO) {
val result: String = try { val result: String? = try {
withTimeout(5000) { withTimeout(5000) {
frostJsoup(cookie.cookie, FbItem.PROFILE.url).title() frostJsoup(cookie.cookie, FbItem.PROFILE.url).title()
} }
} catch (e: Exception) { } catch (e: Exception) {
if (e !is UnknownHostException) if (e !is UnknownHostException)
e.logFrostEvent("Fetch username failed") e.logFrostEvent("Fetch username failed")
"" null
} }
if (cookie.name?.isNotBlank() == false && result != cookie.name) { if (result != null) {
cookieDao.save(cookie.copy(name = result)) cookieDao.save(cookie.copy(name = result))
return@withContext result
} }
cookie.name ?: "" return@withContext cookie.name
} }
override fun backConsumer(): Boolean { override fun backConsumer(): Boolean {

View File

@ -89,8 +89,7 @@ class LoginWebView @JvmOverloads constructor(
val cookie = CookieManager.getInstance().getCookie(url) ?: return null val cookie = CookieManager.getInstance().getCookie(url) ?: return null
L.d { "Checking cookie for login" } L.d { "Checking cookie for login" }
val id = FB_USER_MATCHER.find(cookie)[1]?.toLong() ?: return null val id = FB_USER_MATCHER.find(cookie)[1]?.toLong() ?: return null
// TODO set name to null? return CookieEntity(id, null, cookie)
return CookieEntity(id, "", cookie)
} }
override fun onPageCommitVisible(view: WebView, url: String?) { override fun onPageCommitVisible(view: WebView, url: String?) {