1
0
mirror of https://github.com/AllanWang/Frost-for-Facebook.git synced 2024-09-20 07:31:40 +02:00

Rename some methods

This commit is contained in:
Allan Wang 2019-03-07 17:28:32 -05:00
parent 9e201159fd
commit e617c95e2b
No known key found for this signature in database
GPG Key ID: C93E3F9C679D7A56
11 changed files with 32 additions and 250 deletions

View File

@ -19,7 +19,7 @@ class CacheDbTest : BaseDbTest() {
val type = "test"
val content = "long test".repeat(10000)
runBlocking {
cookieDao.insertCookie(cookie)
cookieDao.save(cookie)
dao.save(cookie.id, type, content)
val cache = dao.select(cookie.id, type) ?: fail("Cache not found")
assertEquals(content, cache.contents, "Content mismatch")

View File

@ -13,7 +13,7 @@ class CookieDbTest : BaseDbTest() {
fun basicCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
dao.insertCookie(cookie)
dao.save(cookie)
val cookies = dao.selectAll()
assertEquals(listOf(cookie), cookies, "Cookie mismatch")
}
@ -24,7 +24,7 @@ class CookieDbTest : BaseDbTest() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
dao.insertCookie(cookie)
dao.save(cookie)
dao.deleteById(cookie.id + 1)
assertEquals(
listOf(cookie),
@ -40,15 +40,15 @@ class CookieDbTest : BaseDbTest() {
fun insertReplaceCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
dao.insertCookie(cookie)
dao.save(cookie)
assertEquals(listOf(cookie), dao.selectAll(), "Cookie insertion failed")
dao.insertCookie(cookie.copy(name = "testName2"))
dao.save(cookie.copy(name = "testName2"))
assertEquals(
listOf(cookie.copy(name = "testName2")),
dao.selectAll(),
"Cookie replacement failed"
)
dao.insertCookie(cookie.copy(id = 123L))
dao.save(cookie.copy(id = 123L))
assertEquals(
setOf(cookie.copy(id = 123L), cookie.copy(name = "testName2")),
dao.selectAll().toSet(),
@ -61,7 +61,7 @@ class CookieDbTest : BaseDbTest() {
fun selectCookie() {
val cookie = CookieEntity(id = 1234L, name = "testName", cookie = "testCookie")
runBlocking {
dao.insertCookie(cookie)
dao.save(cookie)
assertEquals(cookie, dao.selectById(cookie.id), "Cookie selection failed")
assertNull(dao.selectById(cookie.id + 1), "Inexistent cookie selection failed")
}

View File

@ -31,7 +31,7 @@ class NotificationDbTest : BaseDbTest() {
// Unique unsorted ids
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking {
db.cookieDao().insertCookie(cookie)
db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL)
assertEquals(notifs.sortedByDescending { it.timestamp }, dbNotifs, "Incorrect notification list received")
@ -45,8 +45,8 @@ class NotificationDbTest : BaseDbTest() {
val cookie2 = cookie(12L)
val notifs1 = (0L..2L).map { notifContent(it, cookie1) }
val notifs2 = (5L..10L).map { notifContent(it, cookie2) }
db.cookieDao().insertCookie(cookie1)
db.cookieDao().insertCookie(cookie2)
db.cookieDao().save(cookie1)
db.cookieDao().save(cookie2)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1)
dao.saveNotifications(NOTIF_CHANNEL_MESSAGES, notifs2)
assertEquals(
@ -82,8 +82,8 @@ class NotificationDbTest : BaseDbTest() {
val cookie2 = cookie(12L)
val notifs1 = (0L..2L).map { notifContent(it, cookie1) }
val notifs2 = notifs1.map { it.copy(data = cookie2) }
db.cookieDao().insertCookie(cookie1)
db.cookieDao().insertCookie(cookie2)
db.cookieDao().save(cookie1)
db.cookieDao().save(cookie2)
assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs1), "Notif1 save failed")
assertTrue(dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs2), "Notif2 save failed")
}
@ -95,7 +95,7 @@ class NotificationDbTest : BaseDbTest() {
// Unique unsorted ids
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking {
db.cookieDao().insertCookie(cookie)
db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
db.cookieDao().deleteById(cookie.id)
val dbNotifs = dao.selectNotifications(cookie.id, NOTIF_CHANNEL_GENERAL)
@ -110,7 +110,7 @@ class NotificationDbTest : BaseDbTest() {
val notifs = listOf(0L, 4L, 2L, 6L, 99L, 3L).map { notifContent(it, cookie) }
runBlocking {
assertEquals(-1L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Default epoch failed")
db.cookieDao().insertCookie(cookie)
db.cookieDao().save(cookie)
dao.saveNotifications(NOTIF_CHANNEL_GENERAL, notifs)
assertEquals(99L, dao.latestEpoch(cookie.id, NOTIF_CHANNEL_GENERAL), "Latest epoch failed")
}

View File

@ -38,6 +38,7 @@ import com.pitchedapps.frost.db.CookieModel
import com.pitchedapps.frost.db.FbTabDao
import com.pitchedapps.frost.db.FbTabModel
import com.pitchedapps.frost.db.save
import com.pitchedapps.frost.db.selectAll
import com.pitchedapps.frost.facebook.FbCookie
import com.pitchedapps.frost.utils.EXTRA_COOKIES
import com.pitchedapps.frost.utils.L
@ -94,6 +95,7 @@ class StartActivity : KauBaseActivity() {
})
}
} catch (e: Exception) {
L._e(e) { "Load start failed" }
showInvalidWebView()
}
}
@ -106,9 +108,11 @@ class StartActivity : KauBaseActivity() {
private suspend fun migrate() = withContext(Dispatchers.IO) {
if (cookieDao.selectAll().isNotEmpty()) return@withContext
val cookies = (select from CookieModel::class).queryList().map { CookieEntity(it.id, it.name, it.cookie) }
cookieDao.insertCookies(cookies)
cookieDao.save(cookies)
val tabs = (select from FbTabModel::class).queryList().map(FbTabModel::tab)
tabDao.save(tabs)
L._d { "Migrated cookies ${cookieDao.selectAll()}" }
L._d { "Migrated tabs ${tabDao.selectAll()}" }
}
private fun showInvalidWebView() =

View File

@ -184,7 +184,7 @@ class LoginActivity : BaseActivity() {
}
if (cookie.name?.isNotBlank() == false && result != cookie.name) {
cookieDao.insertCookie(cookie.copy(name = result))
cookieDao.save(cookie.copy(name = result))
}
cookie.name ?: ""

View File

@ -59,10 +59,10 @@ interface CookieDao {
suspend fun selectById(id: Long): CookieEntity?
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCookie(cookie: CookieEntity)
suspend fun save(cookie: CookieEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertCookies(cookies: List<CookieEntity>)
suspend fun save(cookies: List<CookieEntity>)
@Query("DELETE FROM cookies WHERE cookie_id = :id")
suspend fun deleteById(id: Long)

View File

@ -5,6 +5,7 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import org.koin.core.Koin
import org.koin.dsl.module.module
import org.koin.standalone.StandAloneContext
@ -59,11 +60,11 @@ class FrostDatabase(private val privateDb: FrostPrivateDatabase, private val pub
val privateDb = Room.databaseBuilder(
context, FrostPrivateDatabase::class.java,
FrostPrivateDatabase.DATABASE_NAME
).build()
).fallbackToDestructiveMigration().build()
val publicDb = Room.databaseBuilder(
context, FrostPublicDatabase::class.java,
FrostPublicDatabase.DATABASE_NAME
).build()
).fallbackToDestructiveMigration().build()
return FrostDatabase(privateDb, publicDb)
}

View File

@ -85,7 +85,7 @@ object FbCookie {
Prefs.userId = id
CookieManager.getInstance().flush()
val cookie = CookieEntity(Prefs.userId, null, webCookie)
cookieDao.insertCookie(cookie)
cookieDao.save(cookie)
}
suspend fun reset() {

View File

@ -20,6 +20,7 @@ import android.util.Log
import ca.allanwang.kau.logging.KauLogger
import com.bugsnag.android.Bugsnag
import com.pitchedapps.frost.BuildConfig
import java.lang.Exception
/**
* Created by Allan Wang on 2017-05-28.
@ -50,6 +51,11 @@ object L : KauLogger("Frost", {
d(message)
}
inline fun _e(e: Throwable?, message: () -> Any?) {
if (BuildConfig.DEBUG)
e(e, message)
}
override fun logImpl(priority: Int, message: String?, t: Throwable?) {
if (BuildConfig.DEBUG)
super.logImpl(priority, message, t)

View File

@ -1,189 +0,0 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "0a9d994786b7e07fea95c11d9210ce0e",
"entities": [
{
"tableName": "cookies",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cookie_id` INTEGER NOT NULL, `name` TEXT, `cookie` TEXT, PRIMARY KEY(`cookie_id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "cookie_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "cookie",
"columnName": "cookie",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"cookie_id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "notifications",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`notif_id` INTEGER NOT NULL, `userId` INTEGER NOT NULL, `href` TEXT NOT NULL, `title` TEXT, `text` TEXT NOT NULL, `timestamp` INTEGER NOT NULL, `profileUrl` TEXT, `type` TEXT NOT NULL, PRIMARY KEY(`notif_id`, `userId`), FOREIGN KEY(`userId`) REFERENCES `cookies`(`cookie_id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "notif_id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "userId",
"columnName": "userId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "href",
"columnName": "href",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "text",
"columnName": "text",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "timestamp",
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "profileUrl",
"columnName": "profileUrl",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"notif_id",
"userId"
],
"autoGenerate": false
},
"indices": [
{
"name": "index_notifications_notif_id",
"unique": false,
"columnNames": [
"notif_id"
],
"createSql": "CREATE INDEX `index_notifications_notif_id` ON `${TABLE_NAME}` (`notif_id`)"
},
{
"name": "index_notifications_userId",
"unique": false,
"columnNames": [
"userId"
],
"createSql": "CREATE INDEX `index_notifications_userId` ON `${TABLE_NAME}` (`userId`)"
}
],
"foreignKeys": [
{
"table": "cookies",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"userId"
],
"referencedColumns": [
"cookie_id"
]
}
]
},
{
"tableName": "frost_cache",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `type` TEXT NOT NULL, `lastUpdated` INTEGER NOT NULL, `contents` TEXT NOT NULL, PRIMARY KEY(`id`, `type`), FOREIGN KEY(`id`) REFERENCES `cookies`(`cookie_id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "type",
"columnName": "type",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastUpdated",
"columnName": "lastUpdated",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "contents",
"columnName": "contents",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id",
"type"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": [
{
"table": "cookies",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"id"
],
"referencedColumns": [
"cookie_id"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"0a9d994786b7e07fea95c11d9210ce0e\")"
]
}
}

View File

@ -1,40 +0,0 @@
{
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "fde868470836ff9230f1d406922d7563",
"entities": [
{
"tableName": "tabs",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`position` INTEGER NOT NULL, `tab` TEXT NOT NULL, PRIMARY KEY(`position`))",
"fields": [
{
"fieldPath": "position",
"columnName": "position",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "tab",
"columnName": "tab",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"position"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"fde868470836ff9230f1d406922d7563\")"
]
}
}