aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt6
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt2
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt13
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt4
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt8
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Notifications.kt2
7 files changed, 18 insertions, 21 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
index 38de6150..ab7e165a 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -29,15 +29,15 @@ object FbCookie {
private fun setWebCookie(cookie: String?, callback: (() -> Unit)?) {
with(CookieManager.getInstance()) {
- removeAllCookies {
+ removeAllCookies { _ ->
if (cookie == null) {
callback?.invoke()
return@removeAllCookies
}
L.d { "Setting cookie" }
val cookies = cookie.split(";").map { Pair(it, SingleSubject.create<Boolean>()) }
- cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie, { callback.onSuccess(it) }) }
- Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }, {})
+ cookies.forEach { (cookie, callback) -> setCookie(FB_URL_BASE, cookie) { callback.onSuccess(it) } }
+ Observable.zip<Boolean, Unit>(cookies.map { (_, callback) -> callback.toObservable() }) {}
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
callback?.invoke()
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
index cfa2796c..a57ced11 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbRegex.kt
@@ -22,7 +22,7 @@ val FB_USER_MATCHER: Regex by lazy { Regex("c_user=([0-9]*);") }
val FB_EPOCH_MATCHER: Regex by lazy { Regex(":([0-9]+)") }
val FB_NOTIF_ID_MATCHER: Regex by lazy { Regex("notif_([0-9]+)") }
-val FB_MESSAGE_NOTIF_ID_MATCHER: Regex by lazy { Regex("[thread|user]_fbid_([0-9]+)") }
+val FB_MESSAGE_NOTIF_ID_MATCHER: Regex by lazy { Regex("(?:thread|user)_fbid_([0-9]+)") }
val FB_CSS_URL_MATCHER: Regex by lazy { Regex("url\\([\"|']?(.*?)[\"|']?\\)") }
val FB_JSON_URL_MATCHER: Regex by lazy { Regex("\"(http.*?)\"") }
val FB_IMAGE_ID_MATCHER: Regex by lazy { Regex("fbcdn.*?/[0-9]+_([0-9]+)_") }
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt
index 5d023023..3d5c5bce 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/FrostParser.kt
@@ -104,22 +104,19 @@ internal abstract class FrostParserBase<out T : Any>(private val redirectToText:
protected abstract fun parseImpl(doc: Document): T?
- // protected abstract fun parse(doc: Document): T?
-
/**
* Attempts to find inner <i> element with some style containing a url
* Returns the formatted url, or an empty string if nothing was found
*/
- protected fun Element.getInnerImgStyle() =
+ protected fun Element.getInnerImgStyle(): String? =
select("i.img[style*=url]").getStyleUrl()
- protected fun Elements.getStyleUrl() =
+ protected fun Elements.getStyleUrl(): String? =
FB_CSS_URL_MATCHER.find(attr("style"))[1]?.formattedFbUrl
- protected open fun textToDoc(text: String) = if (!redirectToText)
- Jsoup.parse(text)
- else
- throw RuntimeException("${this::class.java.simpleName} requires text redirect but did not implement textToDoc")
+ protected open fun textToDoc(text: String): Document? =
+ if (!redirectToText) Jsoup.parse(text)
+ else throw RuntimeException("${this::class.java.simpleName} requires text redirect but did not implement textToDoc")
protected fun parseLink(element: Element?): FrostLink? {
val a = element?.getElementsByTag("a")?.first() ?: return null
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt
index f32c3452..a3ebf998 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/MessageParser.kt
@@ -35,7 +35,7 @@ data class FrostMessages(val threads: List<FrostThread>,
}.toString()
override fun getUnreadNotifications(data: CookieModel) =
- threads.filter(FrostThread::unread).map {
+ threads.asSequence().filter(FrostThread::unread).map {
with(it) {
NotificationContent(
data = data,
@@ -47,7 +47,7 @@ data class FrostMessages(val threads: List<FrostThread>,
profileUrl = img
)
}
- }
+ }.toList()
}
/**
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt
index 03b913c7..410a0e84 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/NotifParser.kt
@@ -24,7 +24,7 @@ data class FrostNotifs(
}.toString()
override fun getUnreadNotifications(data: CookieModel) =
- notifs.filter(FrostNotif::unread).map {
+ notifs.asSequence().filter(FrostNotif::unread).map {
with(it) {
NotificationContent(
data = data,
@@ -36,7 +36,7 @@ data class FrostNotifs(
profileUrl = img
)
}
- }
+ }.toList()
}
/**
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
index a4b0a347..500c4102 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt
@@ -115,8 +115,8 @@ fun String.getAuth(): RequestAuth {
.url(FB_URL_BASE)
.get()
.call()
- call.execute().body()?.charStream()?.useLines {
- it.forEach {
+ call.execute().body()?.charStream()?.useLines { lines ->
+ lines.forEach {
val text = StringEscapeUtils.unescapeEcmaScript(it)
val fb_dtsg = FB_DTSG_MATCHER.find(text)[1]
if (fb_dtsg != null) {
@@ -153,8 +153,8 @@ inline fun <T, reified R : Any, O> Array<T>.zip(crossinline mapper: (List<R>) ->
fun executeForNoError(call: Call): Boolean {
val body = call.execute().body() ?: return false
var empty = true
- body.charStream().useLines {
- it.forEach {
+ body.charStream().useLines { lines ->
+ lines.forEach {
if (it.contains("error")) return false
if (empty && it.isNotEmpty()) empty = false
}
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Notifications.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Notifications.kt
index 82a9364b..0d3926dc 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Notifications.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Notifications.kt
@@ -23,5 +23,5 @@ fun RequestAuth.markNotificationRead(notifId: Long): FrostRequest<Boolean> {
fun RequestAuth.markNotificationsRead(vararg notifId: Long) =
notifId.toTypedArray().zip<Long, Boolean, Boolean>(
- { it.all { it } },
+ { it.all { self -> self } },
{ markNotificationRead(it).invoke() }) \ No newline at end of file