mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 03:05:26 +00:00
Update My Stories logic when user has not sent to a distribution list.
This commit is contained in:
committed by
Cody Henthorne
parent
19861ef0d1
commit
d9ffd67f36
@@ -20,8 +20,7 @@ object MyStoriesItem {
|
||||
}
|
||||
|
||||
class Model(
|
||||
val hasOutgoingStories: Boolean,
|
||||
val onClick: (Boolean) -> Unit,
|
||||
val onClick: () -> Unit,
|
||||
val onClickThumbnail: () -> Unit
|
||||
) : PreferenceModel<Model>() {
|
||||
override fun areItemsTheSame(newItem: Model): Boolean = true
|
||||
@@ -34,7 +33,7 @@ object MyStoriesItem {
|
||||
private val badgeView: BadgeImageView = itemView.findViewById(R.id.badge)
|
||||
|
||||
override fun bind(model: Model) {
|
||||
itemView.setOnClickListener { model.onClick(model.hasOutgoingStories) }
|
||||
itemView.setOnClickListener { model.onClick() }
|
||||
thumbnail.setOnClickListener { model.onClickThumbnail() }
|
||||
|
||||
avatarView.displayProfileAvatar(Recipient.self())
|
||||
|
||||
@@ -110,13 +110,8 @@ class StoriesLandingFragment : DSLSettingsFragment(layoutId = R.layout.stories_l
|
||||
if (state.displayMyStoryItem) {
|
||||
customPref(
|
||||
MyStoriesItem.Model(
|
||||
state.hasOutgoingStories,
|
||||
onClick = {
|
||||
if (it) {
|
||||
startActivity(Intent(requireContext(), MyStoriesActivity::class.java))
|
||||
} else {
|
||||
cameraFab.performClick()
|
||||
}
|
||||
startActivity(Intent(requireContext(), MyStoriesActivity::class.java))
|
||||
},
|
||||
onClickThumbnail = {
|
||||
cameraFab.performClick()
|
||||
|
||||
@@ -27,7 +27,7 @@ class StoriesLandingRepository(context: Context) {
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
fun getStories(): Observable<StoriesResult> {
|
||||
fun getStories(): Observable<List<StoriesLandingItemData>> {
|
||||
val storyRecipients: Observable<Map<Recipient, List<StoryResult>>> = Observable.create { emitter ->
|
||||
fun refresh() {
|
||||
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
|
||||
@@ -57,7 +57,7 @@ class StoriesLandingRepository(context: Context) {
|
||||
refresh()
|
||||
}
|
||||
|
||||
val storiesLandingItemData = storyRecipients.switchMap { map ->
|
||||
return storyRecipients.switchMap { map ->
|
||||
val observables = map.map { (recipient, results) ->
|
||||
val messages = results
|
||||
.sortedBy { it.messageSentTimestamp }
|
||||
@@ -74,21 +74,6 @@ class StoriesLandingRepository(context: Context) {
|
||||
it.toList() as List<StoriesLandingItemData>
|
||||
}
|
||||
}
|
||||
|
||||
val hasOutgoingStories: Observable<Boolean> = storyRecipients.concatMap {
|
||||
Observable.fromCallable {
|
||||
SignalDatabase.mms.getAllOutgoingStories(false).use {
|
||||
it.next != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Observable.combineLatest(
|
||||
storiesLandingItemData,
|
||||
hasOutgoingStories
|
||||
) { data, outgoingStories ->
|
||||
StoriesResult(data, outgoingStories)
|
||||
}.observeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
private fun createStoriesLandingItemData(sender: Recipient, messageRecords: List<MessageRecord>): Observable<StoriesLandingItemData> {
|
||||
@@ -142,9 +127,4 @@ class StoriesLandingRepository(context: Context) {
|
||||
SignalDatabase.recipients.setHideStory(recipientId, hideStory)
|
||||
}.subscribeOn(Schedulers.io())
|
||||
}
|
||||
|
||||
data class StoriesResult(
|
||||
val data: List<StoriesLandingItemData>,
|
||||
val hasOutgoingStories: Boolean
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ data class StoriesLandingState(
|
||||
val storiesLandingItems: List<StoriesLandingItemData> = emptyList(),
|
||||
val displayMyStoryItem: Boolean = false,
|
||||
val isHiddenContentVisible: Boolean = false,
|
||||
val hasOutgoingStories: Boolean = false,
|
||||
val loadingState: LoadingState = LoadingState.INIT
|
||||
) {
|
||||
enum class LoadingState {
|
||||
|
||||
@@ -17,13 +17,12 @@ class StoriesLandingViewModel(private val storiesLandingRepository: StoriesLandi
|
||||
val state: LiveData<StoriesLandingState> = store.stateLiveData
|
||||
|
||||
init {
|
||||
disposables += storiesLandingRepository.getStories().subscribe { (stories, hasOutgoingGroupStories) ->
|
||||
disposables += storiesLandingRepository.getStories().subscribe { stories ->
|
||||
store.update { state ->
|
||||
state.copy(
|
||||
loadingState = StoriesLandingState.LoadingState.LOADED,
|
||||
storiesLandingItems = stories.sorted(),
|
||||
displayMyStoryItem = stories.isEmpty() || stories.none { it.storyRecipient.isMyStory },
|
||||
hasOutgoingStories = hasOutgoingGroupStories
|
||||
displayMyStoryItem = stories.isEmpty() || stories.none { it.storyRecipient.isMyStory }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.thoughtcrime.securesms.stories.my
|
||||
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.core.app.ActivityOptionsCompat
|
||||
@@ -19,8 +20,10 @@ import org.thoughtcrime.securesms.stories.dialogs.StoryContextMenu
|
||||
import org.thoughtcrime.securesms.stories.viewer.StoryViewerActivity
|
||||
import org.thoughtcrime.securesms.util.LifecycleDisposable
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.thoughtcrime.securesms.util.visible
|
||||
|
||||
class MyStoriesFragment : DSLSettingsFragment(
|
||||
layoutId = R.layout.stories_my_stories_fragment,
|
||||
titleId = R.string.StoriesLandingFragment__my_stories
|
||||
) {
|
||||
|
||||
@@ -44,12 +47,11 @@ class MyStoriesFragment : DSLSettingsFragment(
|
||||
}
|
||||
)
|
||||
|
||||
val emptyNotice = requireView().findViewById<View>(R.id.empty_notice)
|
||||
lifecycleDisposable.bindTo(viewLifecycleOwner)
|
||||
viewModel.state.observe(viewLifecycleOwner) {
|
||||
adapter.submitList(getConfiguration(it).toMappingModelList())
|
||||
if (it.distributionSets.isEmpty()) {
|
||||
requireActivity().finish()
|
||||
}
|
||||
emptyNotice.visible = it.distributionSets.isEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user