1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-11-08 20:12:39 +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 nameDeferred = async { loadUsername(cookie) }
val name: String = nameDeferred.await()
val name: String? = nameDeferred.await()
val foundImage: Boolean = imageDeferred.await()
L._d { "Logged in and received data" }
@ -127,7 +127,7 @@ class LoginActivity : BaseActivity() {
L._i { cookie }
}
textview.text = String.format(getString(R.string.welcome), name)
textview.text = String.format(getString(R.string.welcome), name ?: "")
textview.fadeIn()
frostEvent("Login", "success" to true)
@ -172,22 +172,23 @@ class LoginActivity : BaseActivity() {
}
}
private suspend fun loadUsername(cookie: CookieEntity): String = withContext(Dispatchers.IO) {
val result: String = try {
private suspend fun loadUsername(cookie: CookieEntity): String? = withContext(Dispatchers.IO) {
val result: String? = try {
withTimeout(5000) {
frostJsoup(cookie.cookie, FbItem.PROFILE.url).title()
}
} catch (e: Exception) {
if (e !is UnknownHostException)
e.logFrostEvent("Fetch username failed")
""
null
}
if (cookie.name?.isNotBlank() == false && result != cookie.name) {
if (result != null) {
cookieDao.save(cookie.copy(name = result))
return@withContext result
}
cookie.name ?: ""
return@withContext cookie.name
}
override fun backConsumer(): Boolean {

View File

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