Only display outgoing messages when entering viewer through my stories.

fork-5.53.8
Alex Hart 2022-07-25 15:33:34 -03:00 zatwierdzone przez Cody Henthorne
rodzic d40be0abf8
commit cb7b2d90d5
15 zmienionych plików z 52 dodań i 38 usunięć

Wyświetl plik

@ -191,7 +191,7 @@ public abstract class MessageDatabase extends Database implements MmsSmsColumns
public abstract @NonNull Reader getOutgoingStoriesTo(@NonNull RecipientId recipientId);
public abstract @NonNull Reader getAllOutgoingStories(boolean reverse, int limit);
public abstract @NonNull Reader getAllOutgoingStoriesAt(long sentTimestamp);
public abstract @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds();
public abstract @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds(boolean isOutgoingOnly);
public abstract @NonNull Reader getAllStoriesFor(@NonNull RecipientId recipientId, int limit);
public abstract @NonNull MessageId getStoryId(@NonNull RecipientId authorId, long sentTimestamp) throws NoSuchMessageException;
public abstract int getNumberOfStoryReplies(long parentStoryId);

Wyświetl plik

@ -613,7 +613,7 @@ public class MmsDatabase extends MessageDatabase {
whereArgs = SqlUtil.buildArgs(recipientId);
} else {
where += " AND " + THREAD_ID_WHERE;
whereArgs = SqlUtil.buildArgs(1, 0, threadId);
whereArgs = SqlUtil.buildArgs(threadId);
}
return new Reader(rawQuery(where, whereArgs));
@ -798,7 +798,8 @@ public class MmsDatabase extends MessageDatabase {
}
@Override
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds() {
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds(boolean isOutgoingOnly) {
String where = "WHERE is_story > 0 AND remote_deleted = 0" + (isOutgoingOnly ? " AND is_outgoing != 0" : "") + "\n";
SQLiteDatabase db = getReadableDatabase();
String query = "SELECT\n"
+ " mms.date AS sent_timestamp,\n"
@ -812,7 +813,7 @@ public class MmsDatabase extends MessageDatabase {
+ "FROM mms\n"
+ "JOIN thread\n"
+ "ON mms.thread_id = thread._id\n"
+ "WHERE is_story > 0 AND remote_deleted = 0\n"
+ where
+ "ORDER BY\n"
+ "is_unread DESC,\n"
+ "CASE\n"

Wyświetl plik

@ -1413,7 +1413,7 @@ public class SmsDatabase extends MessageDatabase {
}
@Override
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds() {
public @NonNull List<StoryResult> getOrderedStoryRecipientsAndIds(boolean isOutgoingOnly) {
throw new UnsupportedOperationException();
}

Wyświetl plik

@ -22,7 +22,8 @@ data class StoryViewerArgs(
val groupReplyStartPosition: Int = -1,
val isUnviewedOnly: Boolean = false,
val isFromInfoContextMenuAction: Boolean = false,
val isFromQuote: Boolean = false
val isFromQuote: Boolean = false,
val isFromMyStories: Boolean = false
) : Parcelable {
class Builder(private val recipientId: RecipientId, private val isInHiddenStoryMode: Boolean) {

Wyświetl plik

@ -34,7 +34,7 @@ class StoriesLandingRepository(context: Context) {
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
val myStories = Recipient.resolved(myStoriesId)
val stories = SignalDatabase.mms.orderedStoryRecipientsAndIds
val stories = SignalDatabase.mms.getOrderedStoryRecipientsAndIds(false)
val mapping: MutableMap<Recipient, List<StoryResult>> = mutableMapOf()
stories.forEach {

Wyświetl plik

@ -151,7 +151,8 @@ class MyStoriesFragment : DSLSettingsFragment(
storyThumbTextModel = text,
storyThumbUri = image,
storyThumbBlur = blur,
isFromInfoContextMenuAction = isFromInfoContextMenuAction
isFromInfoContextMenuAction = isFromInfoContextMenuAction,
isFromMyStories = true
)
),
options.toBundle()

Wyświetl plik

@ -51,6 +51,7 @@ class StoryViewerFragment :
storyViewerArgs.isFromNotification,
storyViewerArgs.groupReplyStartPosition,
storyViewerArgs.isUnviewedOnly,
storyViewerArgs.isFromMyStories,
storyViewerArgs.isFromInfoContextMenuAction
)

Wyświetl plik

@ -13,6 +13,7 @@ class StoryViewerPagerAdapter(
private val isFromNotification: Boolean,
private val groupReplyStartPosition: Int,
private val isUnviewedOnly: Boolean,
private val isOutgoingOnly: Boolean,
private val isFromInfoContextMenuAction: Boolean
) : FragmentStateAdapter(fragment) {
@ -34,7 +35,7 @@ class StoryViewerPagerAdapter(
override fun getItemCount(): Int = pages.size
override fun createFragment(position: Int): Fragment {
return StoryViewerPageFragment.create(pages[position], initialStoryId, isFromNotification, groupReplyStartPosition, isUnviewedOnly, isFromInfoContextMenuAction)
return StoryViewerPageFragment.create(pages[position], initialStoryId, isFromNotification, groupReplyStartPosition, isUnviewedOnly, isOutgoingOnly, isFromInfoContextMenuAction)
}
private class Callback(

Wyświetl plik

@ -36,12 +36,12 @@ open class StoryViewerRepository {
}
}
fun getStories(hiddenStories: Boolean, unviewedOnly: Boolean): Single<List<RecipientId>> {
fun getStories(hiddenStories: Boolean, unviewedOnly: Boolean, isOutgoingOnly: Boolean): Single<List<RecipientId>> {
return Single.create<List<RecipientId>> { emitter ->
val myStoriesId = SignalDatabase.recipients.getOrInsertFromDistributionListId(DistributionListId.MY_STORY)
val myStories = Recipient.resolved(myStoriesId)
val releaseChannelId = SignalStore.releaseChannelValues().releaseChannelRecipientId
val recipientIds = SignalDatabase.mms.orderedStoryRecipientsAndIds.groupBy {
val recipientIds = SignalDatabase.mms.getOrderedStoryRecipientsAndIds(isOutgoingOnly).groupBy {
val recipient = Recipient.resolved(it.recipientId)
if (recipient.isDistributionList) {
myStories

Wyświetl plik

@ -89,7 +89,8 @@ class StoryViewerViewModel(
} else {
repository.getStories(
hiddenStories = storyViewerArgs.isInHiddenStoryMode,
unviewedOnly = storyViewerArgs.isUnviewedOnly
unviewedOnly = storyViewerArgs.isUnviewedOnly,
isOutgoingOnly = storyViewerArgs.isFromMyStories
)
}
}

Wyświetl plik

@ -115,6 +115,7 @@ class StoryViewerPageFragment :
storyRecipientId,
initialStoryId,
isUnviewedOnly,
isOutgoingOnly,
StoryViewerPageRepository(
requireContext()
),
@ -150,6 +151,9 @@ class StoryViewerPageFragment :
private val isUnviewedOnly: Boolean
get() = requireArguments().getBoolean(ARG_IS_UNVIEWED_ONLY, false)
private val isOutgoingOnly: Boolean
get() = requireArguments().getBoolean(ARG_IS_OUTGOING_ONLY, false)
private val isFromInfoContextMenuAction: Boolean
get() = requireArguments().getBoolean(ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION, false)
@ -985,6 +989,7 @@ class StoryViewerPageFragment :
private const val ARG_IS_FROM_NOTIFICATION = "is_from_notification"
private const val ARG_GROUP_REPLY_START_POSITION = "group_reply_start_position"
private const val ARG_IS_UNVIEWED_ONLY = "is_unviewed_only"
private const val ARG_IS_OUTGOING_ONLY = "is_outgoing_only"
private const val ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION = "is_from_info_context_menu_action"
fun create(
@ -993,6 +998,7 @@ class StoryViewerPageFragment :
isFromNotification: Boolean,
groupReplyStartPosition: Int,
isUnviewedOnly: Boolean,
isOutgoingOnly: Boolean,
isFromInfoContextMenuAction: Boolean
): Fragment {
return StoryViewerPageFragment().apply {
@ -1002,7 +1008,8 @@ class StoryViewerPageFragment :
ARG_IS_FROM_NOTIFICATION to isFromNotification,
ARG_GROUP_REPLY_START_POSITION to groupReplyStartPosition,
ARG_IS_UNVIEWED_ONLY to isUnviewedOnly,
ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION to isFromInfoContextMenuAction
ARG_IS_OUTGOING_ONLY to isOutgoingOnly,
ARG_IS_FROM_INFO_CONTEXT_MENU_ACTION to isFromInfoContextMenuAction,
)
}
}

Wyświetl plik

@ -39,7 +39,7 @@ open class StoryViewerPageRepository(context: Context) {
fun isReadReceiptsEnabled(): Boolean = TextSecurePreferences.isReadReceiptsEnabled(context)
private fun getStoryRecords(recipientId: RecipientId, isUnviewedOnly: Boolean): Observable<List<MessageRecord>> {
private fun getStoryRecords(recipientId: RecipientId, isUnviewedOnly: Boolean, isOutgoingOnly: Boolean): Observable<List<MessageRecord>> {
return Observable.create { emitter ->
val recipient = Recipient.resolved(recipientId)
@ -48,16 +48,14 @@ open class StoryViewerPageRepository(context: Context) {
SignalDatabase.mms.getAllOutgoingStories(false, 100)
} else if (isUnviewedOnly) {
SignalDatabase.mms.getUnreadStories(recipientId, 100)
} else if (isOutgoingOnly) {
SignalDatabase.mms.getOutgoingStoriesTo(recipientId)
} else {
SignalDatabase.mms.getAllStoriesFor(recipientId, 100)
}
val results = mutableListOf<MessageRecord>()
while (stories.next != null) {
if (!(recipient.isMyStory && stories.current.recipient.isGroup)) {
results.add(stories.current)
}
val results = stories.filterNot {
recipient.isMyStory && it.recipient.isGroup
}
emitter.onNext(results)
@ -150,8 +148,8 @@ open class StoryViewerPageRepository(context: Context) {
return Stories.enqueueAttachmentsFromStoryForDownload(post.conversationMessage.messageRecord as MmsMessageRecord, true)
}
fun getStoryPostsFor(recipientId: RecipientId, isUnviewedOnly: Boolean): Observable<List<StoryPost>> {
return getStoryRecords(recipientId, isUnviewedOnly)
fun getStoryPostsFor(recipientId: RecipientId, isUnviewedOnly: Boolean, isOutgoingOnly: Boolean): Observable<List<StoryPost>> {
return getStoryRecords(recipientId, isUnviewedOnly, isOutgoingOnly)
.switchMap { records ->
val posts = records.map { getStoryPostFromRecord(recipientId, it) }
if (posts.isEmpty()) {

Wyświetl plik

@ -26,6 +26,7 @@ class StoryViewerPageViewModel(
private val recipientId: RecipientId,
private val initialStoryId: Long,
private val isUnviewedOnly: Boolean,
private val isOutgoingOnly: Boolean,
private val repository: StoryViewerPageRepository,
val storyCache: StoryCache
) : ViewModel() {
@ -61,7 +62,7 @@ class StoryViewerPageViewModel(
fun refresh() {
disposables.clear()
disposables += repository.getStoryPostsFor(recipientId, isUnviewedOnly).subscribe { posts ->
disposables += repository.getStoryPostsFor(recipientId, isUnviewedOnly, isOutgoingOnly).subscribe { posts ->
store.update { state ->
val isDisplayingInitialState = state.posts.isEmpty() && posts.isNotEmpty()
val startIndex = if (state.posts.isEmpty() && initialStoryId > 0) {
@ -286,11 +287,12 @@ class StoryViewerPageViewModel(
private val recipientId: RecipientId,
private val initialStoryId: Long,
private val isUnviewedOnly: Boolean,
private val isOutgoingOnly: Boolean,
private val repository: StoryViewerPageRepository,
private val storyCache: StoryCache
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return modelClass.cast(StoryViewerPageViewModel(recipientId, initialStoryId, isUnviewedOnly, repository, storyCache)) as T
return modelClass.cast(StoryViewerPageViewModel(recipientId, initialStoryId, isUnviewedOnly, isOutgoingOnly, repository, storyCache)) as T
}
}
}

Wyświetl plik

@ -66,7 +66,7 @@ class StoryViewerViewModelTest {
testScheduler.triggerActions()
// THEN
verify(repository, never()).getStories(any(), any())
verify(repository, never()).getStories(any(), any(), any())
assertEquals(injectedStories, testSubject.stateSnapshot.pages)
}
@ -75,7 +75,7 @@ class StoryViewerViewModelTest {
// GIVEN
val stories: List<RecipientId> = (1L..5L).map(RecipientId::from)
val startStory = RecipientId.from(2L)
whenever(repository.getStories(any(), any())).doReturn(Single.just(stories))
whenever(repository.getStories(any(), any(), any())).doReturn(Single.just(stories))
// WHEN
val testSubject = StoryViewerViewModel(
@ -99,7 +99,7 @@ class StoryViewerViewModelTest {
// GIVEN
val stories: List<RecipientId> = (1L..5L).map(RecipientId::from)
val startStory = RecipientId.from(1L)
whenever(repository.getStories(any(), any())).doReturn(Single.just(stories))
whenever(repository.getStories(any(), any(), any())).doReturn(Single.just(stories))
val testSubject = StoryViewerViewModel(
StoryViewerArgs(
recipientId = startStory,
@ -125,7 +125,7 @@ class StoryViewerViewModelTest {
// GIVEN
val stories: List<RecipientId> = (1L..5L).map(RecipientId::from)
val startStory = stories.last()
whenever(repository.getStories(any(), any())).doReturn(Single.just(stories))
whenever(repository.getStories(any(), any(), any())).doReturn(Single.just(stories))
val testSubject = StoryViewerViewModel(
StoryViewerArgs(
recipientId = startStory,
@ -151,7 +151,7 @@ class StoryViewerViewModelTest {
// GIVEN
val stories: List<RecipientId> = (1L..5L).map(RecipientId::from)
val startStory = stories.last()
whenever(repository.getStories(any(), any())).doReturn(Single.just(stories))
whenever(repository.getStories(any(), any(), any())).doReturn(Single.just(stories))
val testSubject = StoryViewerViewModel(
StoryViewerArgs(
recipientId = startStory,
@ -177,7 +177,7 @@ class StoryViewerViewModelTest {
// GIVEN
val stories: List<RecipientId> = (1L..5L).map(RecipientId::from)
val startStory = stories.first()
whenever(repository.getStories(any(), any())).doReturn(Single.just(stories))
whenever(repository.getStories(any(), any(), any())).doReturn(Single.just(stories))
val testSubject = StoryViewerViewModel(
StoryViewerArgs(
recipientId = startStory,
@ -203,7 +203,7 @@ class StoryViewerViewModelTest {
// GIVEN
val stories: List<RecipientId> = (1L..5L).map(RecipientId::from)
val startStory = stories.first()
whenever(repository.getStories(any(), any())).doReturn(Single.just(stories))
whenever(repository.getStories(any(), any(), any())).doReturn(Single.just(stories))
val testSubject = StoryViewerViewModel(
StoryViewerArgs(
recipientId = startStory,

Wyświetl plik

@ -42,7 +42,7 @@ class StoryViewerPageViewModelTest {
fun `Given first page and first post, when I goToPreviousPost, then I expect storyIndex to be 0`() {
// GIVEN
val storyPosts = createStoryPosts(3) { true }
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
val testSubject = createTestSubject()
testSubject.setIsFirstPage(true)
testScheduler.triggerActions()
@ -61,7 +61,7 @@ class StoryViewerPageViewModelTest {
fun `Given first page and second post, when I goToPreviousPost, then I expect storyIndex to be 0`() {
// GIVEN
val storyPosts = createStoryPosts(3) { true }
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
val testSubject = createTestSubject()
testSubject.setIsFirstPage(true)
testScheduler.triggerActions()
@ -82,7 +82,7 @@ class StoryViewerPageViewModelTest {
fun `Given no initial story and 3 records all viewed, when I initialize, then I expect storyIndex to be 0`() {
// GIVEN
val storyPosts = createStoryPosts(3) { true }
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
// WHEN
val testSubject = createTestSubject()
@ -98,7 +98,7 @@ class StoryViewerPageViewModelTest {
fun `Given no initial story and 3 records all not viewed, when I initialize, then I expect storyIndex to be 0`() {
// GIVEN
val storyPosts = createStoryPosts(3) { false }
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
// WHEN
val testSubject = createTestSubject()
@ -114,7 +114,7 @@ class StoryViewerPageViewModelTest {
fun `Given no initial story and 3 records with 2nd is not viewed, when I initialize, then I expect storyIndex to be 1`() {
// GIVEN
val storyPosts = createStoryPosts(3) { it % 2 != 0 }
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
// WHEN
val testSubject = createTestSubject()
@ -130,7 +130,7 @@ class StoryViewerPageViewModelTest {
fun `Given no initial story and 3 records with 1st and 3rd not viewed, when I goToNext, then I expect storyIndex to be 2`() {
// GIVEN
val storyPosts = createStoryPosts(3) { it % 2 == 0 }
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
// WHEN
val testSubject = createTestSubject()
@ -148,7 +148,7 @@ class StoryViewerPageViewModelTest {
fun `Given a single story, when I goToPrevious, then I expect storyIndex to be -1`() {
// GIVEN
val storyPosts = createStoryPosts(1)
whenever(repository.getStoryPostsFor(any(), any())).thenReturn(Observable.just(storyPosts))
whenever(repository.getStoryPostsFor(any(), any(), any())).thenReturn(Observable.just(storyPosts))
// WHEN
val testSubject = createTestSubject()
@ -167,6 +167,7 @@ class StoryViewerPageViewModelTest {
RecipientId.from(1),
-1L,
false,
false,
repository,
mock()
)