Skip to content

Commit

Permalink
pr feedback and more data modeling
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalbuddha committed Dec 21, 2022
1 parent 474ca2c commit 8744191
Show file tree
Hide file tree
Showing 24 changed files with 327 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ interface MastodonApi {

/**
* Fetch home feed for a particular user
* @see https://docs.joinmastodon.org/methods/timelines/#home
* @param accessToken representing the user
* @return a list of [Status]
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ val networkModule: Module = module {
}
)
}
// install(Auth) {
// bearer {
// loadTokens {
// // Load tokens from a local storage and return them as the 'BearerTokens' instance
// BearerTokens("abc123", "xyz111")
// }
// }
// }
defaultRequest {
url {
protocol = URLProtocol.HTTPS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import kotlinx.serialization.Serializable
*/
@Serializable
data class Application(
val id: String?=null,
val name: String,
@SerialName("vapid_key") val vapidKey: String?=null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ data class Status(
@SerialName("id") val id: String,
@SerialName("uri") val uri: String,
@SerialName("created_at") val createdAt: String,
@SerialName("account") val account: Account,
@SerialName("account") val account: Account? = null,
@SerialName("content") val content: String,
@SerialName("visibility") val visibility: Privacy,
@SerialName("sensitive") val sensitive: Boolean,
@SerialName("spoiler_text") val spoilerText: String,
@SerialName("media_attachments") val mediaAttachments: List<Attachment>,
@SerialName("media_attachments") val mediaAttachments: List<Attachment>?,
@SerialName("application") val application: Application?=null,

// rendering attributes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
CREATE TABLE TimelineItem (
statusId Text NOT NULL PRIMARY KEY,
type TEXT NOT NULL,
createdAt TEXT NOT NULL
remoteId Text NOT NULL PRIMARY KEY,
uri Text NOT NULL,
createdAt Text NOT NULL,
content Text NOT NULL,
accountId Text,
visibility Text NOT NULL,
sensitive INTEGER AS Boolean DEFAULT 0,
spoilerText Text NOT NULL,
avatarUrl Text NOT NULL,
accountAddress Text NOT NULL,
applicationName Text NOT NULL,
userName Text NOT NULL,
repliesCount INTEGER,
favouritesCount INTEGER,
reblogsCount INTEGER
);

insertFeedItem:
INSERT OR REPLACE INTO TimelineItem
VALUES ?;
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);

selectHomeItems:
SELECT * FROM TimelineItem
Expand Down
30 changes: 28 additions & 2 deletions data/repository/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,44 @@ kotlin {
implementation(projects.data.network)
implementation(projects.data.persistence)
implementation(projects.domain.authentication)
implementation(projects.domain.timeline)
implementation(libs.io.insert.koin.core)
implementation(libs.kotlinx.coroutines.core)
//temp until we map to UI models
api(libs.store)
implementation ("com.squareup.sqldelight:coroutines-extensions:1.5.4")
implementation(libs.com.squareup.sqldelight.coroutines.extensions)
}
}

// testing
val androidTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.org.jetbrains.kotlin.test.junit)
}
}
val desktopTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.org.jetbrains.kotlin.test.junit)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.org.jetbrains.kotlin.test.common)
implementation(libs.org.jetbrains.kotlin.test.annotations.common)
implementation(libs.org.jetbrains.kotlinx.coroutines.test)
}
}



// android
val androidMain by getting {
dependsOn(commonMain)
dependencies {
api ("org.jetbrains.kotlinx:atomicfu:0.18.5")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,10 @@
*/
package social.androiddev.common.repository.di

import com.squareup.sqldelight.runtime.coroutines.asFlow
import com.squareup.sqldelight.runtime.coroutines.mapToList
import kotlinx.coroutines.Dispatchers
import org.koin.core.module.Module
import org.koin.dsl.module
import org.mobilenativefoundation.store.store5.Bookkeeper
import org.mobilenativefoundation.store.store5.Market
import org.mobilenativefoundation.store.store5.NetworkFetcher
import org.mobilenativefoundation.store.store5.NetworkUpdater
import org.mobilenativefoundation.store.store5.OnNetworkCompletion
import org.mobilenativefoundation.store.store5.Store
import social.androiddev.common.network.MastodonApi
import social.androiddev.common.network.model.Status
import social.androiddev.common.persistence.localstorage.DodoAuthStorage
import social.androiddev.common.repository.AuthenticationRepositoryImpl
import social.androiddev.common.timeline.TimelineDatabase
import social.androiddev.common.timeline.TimelineItem
import social.androiddev.domain.authentication.repository.AuthenticationRepository

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@ package social.androiddev.common.repository.timeline

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import org.mobilenativefoundation.store.store5.Market
import org.mobilenativefoundation.store.store5.MarketResponse
import org.mobilenativefoundation.store.store5.ReadRequest
import social.androiddev.common.timeline.TimelineItem
import org.mobilenativefoundation.store.store5.Store
import org.mobilenativefoundation.store.store5.StoreRequest
import org.mobilenativefoundation.store.store5.StoreResponse
import social.androiddev.domain.timeline.FeedType
import social.androiddev.domain.timeline.HomeTimelineRepository
import social.androiddev.domain.timeline.model.StatusUI

interface HomeTimelineRepository {
suspend fun read(): Flow<MarketResponse<List<TimelineItem>>>
}

class RealHomeTimelineRepository(
private val market: Market<FeedType, List<TimelineItem>, List<TimelineItem>>
private val store: Store<FeedType, List<StatusUI>>
) : HomeTimelineRepository {
/**
* returns a flow of home feed items from a database
* anytime table rows are created/updated will return a new list of timeline items
* on first return will also call network fetcher to get
* latest from network and update local storage with it]
*/


override suspend fun read(): Flow<MarketResponse<List<TimelineItem>>> {
return market.read(ReadRequest.of(
FeedType.Home,
emptyList(),
null,
true))
.distinctUntilChanged()
}
override suspend fun read(
feedType: FeedType,
refresh: Boolean
): Flow<StoreResponse<List<StatusUI>>> {
return store.stream(StoreRequest.cached(key = feedType, refresh = true))
.distinctUntilChanged() }


}
Expand Down
Loading

0 comments on commit 8744191

Please sign in to comment.