Skip to content

Commit

Permalink
Merge pull request #365 from stakwork/tt/fix/feed-repository
Browse files Browse the repository at this point in the history
Feed Repository refactor
  • Loading branch information
tomastiminskas authored Dec 10, 2021
2 parents dba3da1 + 2dd5877 commit 3657d8e
Show file tree
Hide file tree
Showing 23 changed files with 79 additions and 61 deletions.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ include ':sphinx:application:data:concepts:repositories:concept-repository-light
include ':sphinx:application:data:concepts:repositories:concept-repository-media'
include ':sphinx:application:data:concepts:repositories:concept-repository-message'
include ':sphinx:application:data:concepts:repositories:concept-repository-subscription'
include ':sphinx:application:data:concepts:repositories:concept-repository-podcast'
include ':sphinx:application:data:concepts:repositories:concept-repository-feed'
include ':sphinx:application:data:features:feature-repository'
include ':sphinx:application:data:features:feature-repository-android'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@ interface ChatRepository {
tribeDto: TribeDto,
): Flow<LoadResponse<ChatDto, ResponseError>>

suspend fun updateFeedContent(
chatId: ChatId,
host: ChatHost,
feedUrl: FeedUrl,
chatUUID: ChatUUID?,
subscribed: Subscribed,
currentEpisodeId: FeedId?
)

fun getFeedByChatId(chatId: ChatId): Flow<Feed?>
fun getFeedById(feedId: FeedId): Flow<Feed?>

suspend fun toggleFeedSubscribeState(feedId: FeedId, currentSubscribeState: Subscribed)

suspend fun updateTribeInfo(chat: Chat): TribeData?
suspend fun createTribe(createTribe: CreateTribe): Response<Any, ResponseError>
suspend fun updateTribe(chatId: ChatId, createTribe: CreateTribe): Response<Any, ResponseError>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package chat.sphinx.concept_repository_feed

import chat.sphinx.wrapper_chat.ChatHost
import chat.sphinx.wrapper_common.chat.ChatUUID
import chat.sphinx.wrapper_common.dashboard.ChatId
import chat.sphinx.wrapper_common.feed.FeedId
import chat.sphinx.wrapper_common.feed.FeedUrl
import chat.sphinx.wrapper_common.feed.Subscribed
import chat.sphinx.wrapper_feed.Feed
import chat.sphinx.wrapper_podcast.Podcast
import chat.sphinx.wrapper_podcast.PodcastSearchResultRow
import kotlinx.coroutines.flow.Flow

interface FeedRepository {
fun getPodcastByChatId(chatId: ChatId): Flow<Podcast?>
fun getPodcastById(feedId: FeedId): Flow<Podcast?>
fun searchPodcastBy(searchTerm: String): Flow<List<PodcastSearchResultRow>>

suspend fun updateFeedContent(
chatId: ChatId,
host: ChatHost,
feedUrl: FeedUrl,
chatUUID: ChatUUID?,
subscribed: Subscribed,
currentEpisodeId: FeedId?
)

fun getFeedByChatId(chatId: ChatId): Flow<Feed?>
fun getFeedById(feedId: FeedId): Flow<Feed?>

suspend fun toggleFeedSubscribeState(feedId: FeedId, currentSubscribeState: Subscribed)
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-media')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-message')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-subscription')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-podcast')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-feed')

api project(path: ':sphinx:application:network:concepts:concept-meme-input-stream')
api project(path: ':sphinx:application:network:concepts:queries:concept-network-query-meme-server')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import chat.sphinx.concept_repository_message.model.AttachmentInfo
import chat.sphinx.concept_repository_message.model.SendMessage
import chat.sphinx.concept_repository_message.model.SendPayment
import chat.sphinx.concept_repository_message.model.SendPaymentRequest
import chat.sphinx.concept_repository_podcast.PodcastRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.concept_repository_subscription.SubscriptionRepository
import chat.sphinx.concept_socket_io.SocketIOManager
import chat.sphinx.concept_socket_io.SphinxSocketIOMessage
Expand Down Expand Up @@ -159,7 +159,7 @@ abstract class SphinxRepository(
SubscriptionRepository,
RepositoryDashboard,
RepositoryMedia,
PodcastRepository,
FeedRepository,
CoroutineDispatchers by dispatchers,
SphinxSocketIOMessageListener {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import chat.sphinx.concept_repository_dashboard_android.RepositoryDashboardAndro
import chat.sphinx.concept_repository_lightning.LightningRepository
import chat.sphinx.concept_repository_media.RepositoryMedia
import chat.sphinx.concept_repository_message.MessageRepository
import chat.sphinx.concept_repository_podcast.PodcastRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.concept_repository_subscription.SubscriptionRepository
import chat.sphinx.concept_socket_io.SocketIOManager
import chat.sphinx.database.SphinxCoreDBImpl
Expand Down Expand Up @@ -198,9 +198,9 @@ object RepositoryModule {
sphinxRepositoryAndroid

@Provides
fun providePodcastRepository(
fun provideFeedRepository(
sphinxRepositoryAndroid: SphinxRepositoryAndroid
): PodcastRepository =
): FeedRepository =
sphinxRepositoryAndroid

@Provides
Expand Down
1 change: 1 addition & 0 deletions sphinx/screens-detail/join-tribe/join-tribe/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
implementation project(path: ':sphinx:application:data:concepts:concept-media-cache')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-contact')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-chat')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-feed')
implementation project(path: ':sphinx:application:network:concepts:queries:concept-network-query-chat')
implementation project(path: ':sphinx:application:common:menus:menu-bottom-picture')
implementation project(path: ':sphinx:screens-detail:common:detail-resources')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import chat.sphinx.concept_network_query_chat.NetworkQueryChat
import chat.sphinx.concept_network_query_chat.model.TribeDto
import chat.sphinx.concept_repository_chat.ChatRepository
import chat.sphinx.concept_repository_contact.ContactRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.concept_view_model_coordinator.ViewModelCoordinator
import chat.sphinx.join_tribe.R
import chat.sphinx.join_tribe.navigation.JoinTribeNavigator
Expand Down Expand Up @@ -53,6 +54,7 @@ internal class JoinTribeViewModel @Inject constructor(
private val app: Application,
private val contactRepository: ContactRepository,
private val chatRepository: ChatRepository,
private val feedRepository: FeedRepository,
private val networkQueryChat: NetworkQueryChat,
private val cameraCoordinator: ViewModelCoordinator<CameraRequest, CameraResponse>,
private val mediaCacheHandler: MediaCacheHandler,
Expand Down Expand Up @@ -205,7 +207,7 @@ internal class JoinTribeViewModel @Inject constructor(
nnTribeInfo.feed_url?.toFeedUrl()?.let { feedUrl ->
nnTribeInfo.uuid?.toChatUUID()?.let { chatUUID ->
nnTribeInfo.host?.toChatHost()?.let { chatHost ->
chatRepository.updateFeedContent(
feedRepository.updateFeedContent(
chatId,
chatHost,
feedUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {

implementation project(path: ':sphinx:application:data:concepts:concept-image-loader')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-chat')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-feed')
implementation project(path: ':sphinx:screens-detail:common:detail-resources')
implementation project(path: ':sphinx:application:common:logger')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Application
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import chat.sphinx.concept_repository_chat.ChatRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.newsletter_detail.R
import chat.sphinx.newsletter_detail.navigation.NewsletterDetailNavigator
import chat.sphinx.wrapper_common.dashboard.ChatId
Expand All @@ -29,13 +30,14 @@ internal class NewsletterDetailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val app: Application,
private val chatRepository: ChatRepository,
private val feedRepository: FeedRepository,
val navigator: NewsletterDetailNavigator
): BaseViewModel<NewsletterDetailViewState>(dispatchers, NewsletterDetailViewState.Idle)
{
private val args: NewsletterDetailFragmentArgs by savedStateHandle.navArgs()

private val newsletterSharedFlow: SharedFlow<Feed?> = flow {
emitAll(chatRepository.getFeedByChatId(args.chatId))
emitAll(feedRepository.getFeedByChatId(args.chatId))
}.distinctUntilChanged().shareIn(
viewModelScope,
SharingStarted.WhileSubscribed(2_000),
Expand Down Expand Up @@ -66,7 +68,7 @@ internal class NewsletterDetailViewModel @Inject constructor(
chatRepository.getChatById(args.chatId).firstOrNull()?.let { chat ->
chat.host?.let { chatHost ->
args.argFeedUrl.toFeedUrl()?.let { feedUrl ->
chatRepository.updateFeedContent(
feedRepository.updateFeedContent(
chatId = chat.id,
host = chatHost,
feedUrl = feedUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies {
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-chat')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-message')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-contact')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-podcast')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-feed')
implementation project(path: ':sphinx:application:network:concepts:queries:concept-network-query-chat')

api project(path: ':sphinx:service:concepts:concept-service-media-player')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import app.cash.exhaustive.Exhaustive
import chat.sphinx.concept_repository_chat.ChatRepository
import chat.sphinx.concept_repository_contact.ContactRepository
import chat.sphinx.concept_repository_message.MessageRepository
import chat.sphinx.concept_repository_podcast.PodcastRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.concept_service_media.MediaPlayerServiceController
import chat.sphinx.concept_service_media.MediaPlayerServiceState
import chat.sphinx.concept_service_media.UserAction
Expand All @@ -25,7 +25,6 @@ import chat.sphinx.wrapper_podcast.PodcastEpisode
import dagger.hilt.android.lifecycle.HiltViewModel
import io.matthewnelson.android_feature_navigation.util.navArgs
import io.matthewnelson.android_feature_viewmodel.BaseViewModel
import io.matthewnelson.android_feature_viewmodel.updateViewState
import io.matthewnelson.concept_coroutines.CoroutineDispatchers
import io.matthewnelson.concept_views.viewstate.ViewStateContainer
import kotlinx.coroutines.delay
Expand All @@ -47,7 +46,7 @@ internal class PodcastPlayerViewModel @Inject constructor(
private val chatRepository: ChatRepository,
private val messageRepository: MessageRepository,
private val contactRepository: ContactRepository,
private val podcastRepository: PodcastRepository,
private val feedRepository: FeedRepository,
savedStateHandle: SavedStateHandle,
private val mediaPlayerServiceController: MediaPlayerServiceController
) : BaseViewModel<PodcastPlayerViewState>(
Expand All @@ -60,9 +59,9 @@ internal class PodcastPlayerViewModel @Inject constructor(

private val podcastSharedFlow: SharedFlow<Podcast?> = flow {
if (args.argChatId != ChatId.NULL_CHAT_ID.toLong()) {
emitAll(podcastRepository.getPodcastByChatId(args.chatId))
emitAll(feedRepository.getPodcastByChatId(args.chatId))
} else {
emitAll(podcastRepository.getPodcastById(args.feedId))
emitAll(feedRepository.getPodcastById(args.feedId))
}
}.distinctUntilChanged().shareIn(
viewModelScope,
Expand Down Expand Up @@ -190,7 +189,7 @@ internal class PodcastPlayerViewModel @Inject constructor(
val subscribed = (chat != null || (podcast?.subscribed?.isTrue() == true))

args.argFeedUrl.toFeedUrl()?.let { feedUrl ->
chatRepository.updateFeedContent(
feedRepository.updateFeedContent(
chatId = chat?.id ?: ChatId(ChatId.NULL_CHAT_ID.toLong()),
host = chatHost,
feedUrl = feedUrl,
Expand Down Expand Up @@ -227,7 +226,7 @@ internal class PodcastPlayerViewModel @Inject constructor(

fun toggleSubscribeState(podcast: Podcast) {
viewModelScope.launch(mainImmediate) {
chatRepository.toggleFeedSubscribeState(
feedRepository.toggleFeedSubscribeState(
podcast.id,
podcast.subscribed
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation project(path: ':sphinx:application:data:concepts:concept-image-loader')
implementation project(path: ':sphinx:application:data:concepts:concept-relay')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-chat')
implementation project(path: ':sphinx:application:data:concepts:repositories:concept-repository-feed')

implementation deps.androidx.lifecycle.hilt
implementation deps.google.hilt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chat.sphinx.video_screen.ui

import androidx.lifecycle.viewModelScope
import chat.sphinx.concept_repository_chat.ChatRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.video_screen.ui.viewstate.SelectedVideoViewState
import chat.sphinx.video_screen.ui.viewstate.VideoFeedScreenViewState
import chat.sphinx.wrapper_common.dashboard.ChatId
Expand All @@ -20,10 +21,11 @@ import kotlinx.coroutines.launch
internal open class VideoFeedScreenViewModel(
dispatchers: CoroutineDispatchers,
private val chatRepository: ChatRepository,
private val feedRepository: FeedRepository,
): BaseViewModel<VideoFeedScreenViewState>(dispatchers, VideoFeedScreenViewState.Idle)
{
private val videoFeedSharedFlow: SharedFlow<Feed?> = flow {
emitAll(chatRepository.getFeedByChatId(getArgChatId()))
emitAll(feedRepository.getFeedByChatId(getArgChatId()))
}.distinctUntilChanged().shareIn(
viewModelScope,
SharingStarted.WhileSubscribed(2_000),
Expand Down Expand Up @@ -72,7 +74,7 @@ internal open class VideoFeedScreenViewModel(
chatRepository.getChatById(getArgChatId()).firstOrNull()?.let { chat ->
chat.host?.let { chatHost ->
getArgFeedUrl()?.let { feedUrl ->
chatRepository.updateFeedContent(
feedRepository.updateFeedContent(
chatId = chat.id,
host = chatHost,
feedUrl = feedUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chat.sphinx.video_screen.ui.detail

import androidx.lifecycle.SavedStateHandle
import chat.sphinx.concept_repository_chat.ChatRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.video_screen.ui.VideoFeedScreenViewModel
import chat.sphinx.video_screen.ui.watch.chatId
import chat.sphinx.video_screen.ui.watch.feedUrl
Expand All @@ -23,9 +24,11 @@ internal class VideoFeedDetailScreenViewModel @Inject constructor(
dispatchers: CoroutineDispatchers,
savedStateHandle: SavedStateHandle,
chatRepository: ChatRepository,
feedRepository: FeedRepository,
): VideoFeedScreenViewModel(
dispatchers,
chatRepository
chatRepository,
feedRepository
)
{
private val args: VideoFeedDetailScreenFragmentArgs by savedStateHandle.navArgs()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.widget.VideoView
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import chat.sphinx.concept_repository_chat.ChatRepository
import chat.sphinx.concept_repository_feed.FeedRepository
import chat.sphinx.video_player_controller.VideoPlayerController
import chat.sphinx.video_screen.ui.VideoFeedScreenViewModel
import chat.sphinx.video_screen.ui.viewstate.PlayingVideoViewState
Expand All @@ -28,9 +29,11 @@ internal class VideoFeedWatchScreenViewModel @Inject constructor(
dispatchers: CoroutineDispatchers,
savedStateHandle: SavedStateHandle,
private val chatRepository: ChatRepository,
feedRepository: FeedRepository,
): VideoFeedScreenViewModel(
dispatchers,
chatRepository
chatRepository,
feedRepository
)
{
private val args: VideoFeedWatchScreenFragmentArgs by savedStateHandle.navArgs()
Expand Down
2 changes: 1 addition & 1 deletion sphinx/screens/chats/chat-common/chat-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-contact')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-message')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-media')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-podcast')
api project(path: ':sphinx:application:data:concepts:repositories:concept-repository-feed')

implementation project(path: ':sphinx:application:network:concepts:clients:concept-network-client-crypto')

Expand Down
Loading

0 comments on commit 3657d8e

Please sign in to comment.