diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/parsers/NotifParser.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/parsers/NotifParser.kt | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/parsers/NotifParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/parsers/NotifParser.kt index f743a43a..451eb774 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/parsers/NotifParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/parsers/NotifParser.kt @@ -3,7 +3,6 @@ package com.pitchedapps.frost.parsers import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.* import com.pitchedapps.frost.services.NotificationContent -import com.pitchedapps.frost.utils.L import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -29,10 +28,10 @@ data class FrostNotifs( with(it) { NotificationContent( data = data, - notifId = Math.abs(id.toInt()), + id = id, href = url, title = null, - text = content ?: "", + text = content, timestamp = time, profileUrl = img ) @@ -47,13 +46,17 @@ data class FrostNotifs( * [url] link to thread * [unread] true if image is unread, false otherwise * [content] optional string for thread + * [timeString] text version of time from Facebook + * [thumbnailUrl] optional thumbnail url if existent */ data class FrostNotif(val id: Long, - val img: String, + val img: String?, val time: Long, val url: String, val unread: Boolean, - val content: String?) + val content: String, + val timeString: String, + val thumbnailUrl: String?) private class NotifParserImpl : FrostParserBase<FrostNotifs>(false) { @@ -62,7 +65,7 @@ private class NotifParserImpl : FrostParserBase<FrostNotifs>(false) { override fun parseImpl(doc: Document): FrostNotifs? { val notificationList = doc.getElementById("notifications_list") ?: return null val notifications = notificationList.getElementsByAttributeValueContaining("id", "list_notif_") - .mapNotNull { parseNotif(it) } + .mapNotNull(this::parseNotif) val seeMore = parseLink(doc.getElementsByAttributeValue("href", "/notifications.php?more").first()) return FrostNotifs(notifications, seeMore) } @@ -73,18 +76,20 @@ private class NotifParserImpl : FrostParserBase<FrostNotifs>(false) { val epoch = FB_EPOCH_MATCHER.find(abbr.attr("data-store"))[1]?.toLongOrNull() ?: -1L //fetch id val id = FB_NOTIF_ID_MATCHER.find(element.id())[1]?.toLongOrNull() - ?: System.currentTimeMillis() + ?: System.currentTimeMillis() % FALLBACK_TIME_MOD val img = element.getInnerImgStyle() val timeString = abbr.text() val content = a.text().replace("\u00a0", " ").removeSuffix(timeString).trim() //remove - L.v("url", a.attr("href")) + val thumbnail = element.selectFirst("img.thumbnail")?.attr("src") return FrostNotif( id = id, img = img, time = epoch, url = a.attr("href").formattedFbUrl, unread = !element.hasClass("acw"), - content = content + content = content, + timeString = timeString, + thumbnailUrl = if (thumbnail?.isNotEmpty() == true) thumbnail else null ) } |