Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalbuddha committed Dec 21, 2022
1 parent cd047c0 commit ecae908
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ internal class MastodonApiKtor(

override suspend fun getHomeFeed(domain: String, accessToken: String): Result<List<Status>> {
return runCatchingIgnoreCancelled {
httpClient.get{
httpClient.get {
url {
host = domain
path("/api/v1/timelines/home")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class Application(
val name: String,
@SerialName("vapid_key") val vapidKey: String?=null,
@SerialName("vapid_key") val vapidKey: String? = null,

// optional attributes
val website: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data class Status(
@SerialName("sensitive") val sensitive: Boolean,
@SerialName("spoiler_text") val spoilerText: String,
@SerialName("media_attachments") val mediaAttachments: List<Attachment>? = emptyList(),
@SerialName("application") val application: Application?=null,
@SerialName("application") val application: Application? = null,

// rendering attributes
@SerialName("mentions") val mentions: List<Mention>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ data class Tag(
@SerialName("url") val url: String,

// optional attributes
@SerialName("history") val history: List<History>?= emptyList(),
@SerialName("history") val history: List<History>? = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import kotlin.test.assertNull
import kotlin.test.assertTrue

@OptIn(ExperimentalCoroutinesApi::class)
class MastodonApiTests {
class MastodonApiTests {

@Test
fun `instance list should be parsed correctly`() = runTest {
Expand Down Expand Up @@ -215,7 +215,7 @@ import kotlin.test.assertTrue
// then
assertTrue(actual = result.isSuccess)
}
//TODO MIKE: Harden tests to validate inputs
// TODO MIKE: Harden tests to validate inputs
@Test
fun `view home feed should succeed`() = runTest {
val mastodonApi = MastodonApiKtor(
Expand All @@ -225,7 +225,7 @@ import kotlin.test.assertTrue
)

// when
val result = mastodonApi.getHomeFeed("","")
val result = mastodonApi.getHomeFeed("", "")

// then
assertTrue(actual = result.isSuccess)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.network.fixtures

val homeFeed = """
val homeFeed = """
[
{
"id": "109518540195637455",
Expand Down Expand Up @@ -2400,4 +2409,4 @@ package social.androiddev.common.network.fixtures
"poll": null
}
]
""".trimIndent()
""".trimIndent()
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ val repositoryModule: Module = module {
)
}
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.repository.timeline

import social.androiddev.common.network.model.Status
Expand All @@ -11,9 +20,9 @@ fun StatusDB.toLocal(
remoteId = remoteId,
feedType = key,
createdAt = createdAt,
repliesCount = repliesCount?:0,
reblogsCount = favouritesCount?:0,
favoritesCount = favouritesCount?:0,
repliesCount = repliesCount ?: 0,
reblogsCount = favouritesCount ?: 0,
favoritesCount = favouritesCount ?: 0,
content = content,
sensitive = sensitive ?: false,
spoilerText = spoilerText,
Expand All @@ -23,7 +32,6 @@ fun StatusDB.toLocal(
userName = userName
)


fun Status.statusDB() =
StatusDB(
type = FeedType.Home.type,
Expand All @@ -39,7 +47,7 @@ fun Status.statusDB() =
repliesCount = repliesCount?.toLong(),
reblogsCount = reblogsCount?.toLong(),
favouritesCount = favouritesCount?.toLong(),
avatarUrl = account?.avatar?:"",
accountAddress = account?.acct?:"",
userName = account?.username?:" "
)
avatarUrl = account?.avatar ?: "",
accountAddress = account?.acct ?: "",
userName = account?.username ?: " "
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.repository.timeline

import kotlinx.coroutines.flow.Flow
Expand All @@ -9,7 +18,6 @@ import social.androiddev.domain.timeline.FeedType
import social.androiddev.domain.timeline.HomeTimelineRepository
import social.androiddev.domain.timeline.model.StatusLocal


class RealHomeTimelineRepository(
private val store: Store<FeedType, List<StatusLocal>>
) : HomeTimelineRepository {
Expand All @@ -24,8 +32,6 @@ class RealHomeTimelineRepository(
refresh: Boolean
): Flow<StoreResponse<List<StatusLocal>>> {
return store.stream(StoreRequest.cached(key = feedType, refresh = true))
.distinctUntilChanged() }


}

.distinctUntilChanged()
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.repository.timeline

import org.mobilenativefoundation.store.store5.Fetcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ val timelineRepoModule: Module = module {

factory { get<MastodonApi>().timelineFetcher(authStorage = get()) }


factory {
val fetcher = get<Fetcher<FeedType, List<StatusDB>>>()
val sourceOfTruth = get<SourceOfTruth<FeedType, List<StatusDB>, List<StatusLocal>>>()
StoreBuilder.from(
fetcher = fetcher,
sourceOfTruth = sourceOfTruth
)
fetcher = fetcher,
sourceOfTruth = sourceOfTruth
)
.build()
}
}



Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.repository.timeline

import com.squareup.sqldelight.runtime.coroutines.asFlow
Expand Down Expand Up @@ -29,13 +38,13 @@ private fun TimelineQueries.homeItemsAsLocal(key: FeedType) = selectHomeItems()
.asFlow()
.mapToList()
.map {
it.ifEmpty { return@map null } //treat empty list as no result otherwise
it.ifEmpty { return@map null } // treat empty list as no result otherwise
it.map { item -> item.toLocal(key) }
}

fun TimelineDatabase.tryWriteItem(it: StatusDB, type: FeedType): Boolean = try {
timelineQueries.insertFeedItem(
it.copy(type = type.type)
it.copy(type = type.type)
)
true
} catch (t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.repository.timeline

import kotlinx.coroutines.flow.first
Expand All @@ -12,7 +21,6 @@ import social.androiddev.domain.timeline.FeedType
import kotlin.test.Test
import kotlin.test.assertTrue


class TimelineFetcherKtTest {
@Test
fun timelineFetcher() = runTest {
Expand All @@ -37,5 +45,3 @@ class TimelineFetcherKtTest {
assertTrue { list[0] == expected.statusDB() }
}
}


Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.common.repository.timeline.fixtures

import social.androiddev.common.network.MastodonApi
Expand All @@ -10,7 +19,6 @@ import social.androiddev.common.network.model.Status
import social.androiddev.common.network.model.Token
import social.androiddev.common.persistence.localstorage.DodoAuthStorage


val fakeStorage = object : DodoAuthStorage {
override var currentDomain: String? = "androiddev.social"

Expand Down Expand Up @@ -78,4 +86,4 @@ val fakeApi = object : MastodonApi {
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.domain.timeline

import kotlinx.coroutines.flow.Flow

import org.mobilenativefoundation.store.store5.StoreResponse
import social.androiddev.domain.timeline.model.StatusLocal

interface HomeTimelineRepository {
suspend fun read(feedType: FeedType, refresh: Boolean = false): Flow<StoreResponse<List<StatusLocal>>>
suspend fun read(
feedType: FeedType,
refresh: Boolean = false
): Flow<StoreResponse<List<StatusLocal>>>
}

sealed class FeedType(val type: String) {
object Home : FeedType("HOME")
}
sealed class FeedType(val type:String){
object Home: FeedType("HOME")
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ package social.androiddev.domain.timeline.model
import social.androiddev.domain.timeline.FeedType

data class StatusLocal(
val remoteId:String,
val remoteId: String,
val feedType: FeedType,
val createdAt: String,
val repliesCount: Long=0,
val reblogsCount: Long=0,
val favoritesCount: Long=0,
val repliesCount: Long = 0,
val reblogsCount: Long = 0,
val favoritesCount: Long = 0,
val content: String,
val account: Account?=null,
val account: Account? = null,
val sensitive: Boolean = false,
val spoilerText: String? = null,
val visibility: String = "Public",
val avatarUrl:String="",
val accountAddress:String="",
val userName:String
val avatarUrl: String = "",
val accountAddress: String = "",
val userName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import kotlinx.coroutines.flow.StateFlow
import org.mobilenativefoundation.store.store5.StoreResponse
import social.androiddev.domain.timeline.model.StatusLocal
import social.androiddev.signedin.navigation.SignedInRootComponent
import social.androiddev.timeline.FeedItemState
import social.androiddev.timeline.TimelineContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import kotlin.coroutines.CoroutineContext
class DefaultSignedInRootComponent(
private val componentContext: ComponentContext,
private val mainContext: CoroutineContext,
) : SignedInRootComponent, ComponentContext by componentContext {
) : SignedInRootComponent, ComponentContext by componentContext {

// StackNavigation accepts navigation commands and forwards them to all subscribed observers.
private val navigation = StackNavigation<Config>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fun TimelineContent(
}

else -> {
//handle error/loading
// handle error/loading
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import social.androiddev.common.theme.DodoTheme

@Composable
Expand Down Expand Up @@ -59,8 +56,6 @@ fun TootContent(
}
}



// @Preview
@Composable
private fun PreviewTootContentLight() {
Expand Down
Loading

0 comments on commit ecae908

Please sign in to comment.